Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use upgraded lunar-api schema manifest #3

Merged
merged 17 commits into from
Oct 31, 2023
166 changes: 83 additions & 83 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,85 +1,85 @@
{
"name": "dystcz/lunar-api-newsletter",
"description": "Add the possibility to sign up to newsletter lists to your Lunar backend",
"keywords": [
"dystopia",
"lunar-api-newsletter",
"lunar",
"newsletter"
],
"homepage": "https://github.com/dystcz/lunar-api-newsletter",
"license": "MIT",
"type": "library",
"authors": [
{
"name": "Jakub Theimer",
"email": "jakub@dy.st",
"role": "Developer"
}
],
"require": {
"php": "^8.2",
"dystcz/lunar-api": "^0.6.0-dev",
"illuminate/support": "^10.0",
"laravel-json-api/laravel": "^3.0",
"laravel-json-api/non-eloquent": "^3.0",
"spatie/laravel-newsletter": "^5.1"
},
"suggest": {
"spatie/mailcoach-sdk-php": "For working with Mailcoach",
"drewm/mailchimp-api": "For working with MailChimp"
},
"require-dev": {
"drewm/mailchimp-api": "^2.5",
"driftingly/rector-laravel": "^0.17.0",
"laravel-json-api/testing": "^2.1",
"laravel/pint": "^1.7",
"mockery/mockery": "^1.5",
"nunomaduro/larastan": "^2.5.1",
"orchestra/testbench": "^8.0",
"pestphp/pest": "^2.0",
"pestphp/pest-plugin-faker": "^2.0",
"pestphp/pest-plugin-laravel": "^2.0",
"rector/rector": "^0.15.23",
"spatie/laravel-ray": "^1.32",
"spatie/mailcoach-sdk-php": "^1.1"
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/lorinczdev/json-api"
}
],
"autoload": {
"psr-4": {
"Dystcz\\LunarApiNewsletter\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"Dystcz\\LunarApiNewsletter\\Tests\\": "tests"
}
},
"scripts": {
"test": "vendor/bin/pest",
"test-coverage": "vendor/bin/phpunit --coverage-html coverage"
},
"config": {
"sort-packages": true,
"allow-plugins": {
"pestphp/pest-plugin": true
}
},
"extra": {
"laravel": {
"providers": [
"Dystcz\\LunarApiNewsletter\\LunarApiNewsletterServiceProvider"
],
"aliases": {
"LunarApiNewsletter": "Dystcz\\LunarApiNewsletter\\LunarApiNewsletterFacade"
}
}
},
"minimum-stability": "dev",
"prefer-stable": true
"name": "dystcz/lunar-api-newsletter",
"description": "Add the possibility to sign up to newsletter lists to your Lunar backend",
"keywords": [
"dystopia",
"lunar-api-newsletter",
"lunar",
"newsletter"
],
"homepage": "https://github.com/dystcz/lunar-api-newsletter",
"license": "MIT",
"type": "library",
"authors": [
{
"name": "Jakub Theimer",
"email": "jakub@dy.st",
"role": "Developer"
}
],
"require": {
"php": "^8.2",
"dystcz/lunar-api": "^0.6.0-dev",
"illuminate/support": "^10.0",
"laravel-json-api/laravel": "^3.0",
"laravel-json-api/non-eloquent": "^3.0",
"spatie/laravel-newsletter": "^5.1"
},
"suggest": {
"spatie/mailcoach-sdk-php": "For working with Mailcoach",
"drewm/mailchimp-api": "For working with MailChimp"
},
"require-dev": {
"drewm/mailchimp-api": "^2.5",
"driftingly/rector-laravel": "^0.17.0",
"laravel-json-api/testing": "^2.1",
"laravel/pint": "^1.7",
"mockery/mockery": "^1.5",
"nunomaduro/larastan": "^2.5.1",
"orchestra/testbench": "^8.0",
"pestphp/pest": "^2.0",
"pestphp/pest-plugin-faker": "^2.0",
"pestphp/pest-plugin-laravel": "^2.0",
"rector/rector": "^0.15.23",
"spatie/laravel-ray": "^1.32",
"spatie/mailcoach-sdk-php": "^1.1"
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/lorinczdev/json-api"
}
],
"autoload": {
"psr-4": {
"Dystcz\\LunarApiNewsletter\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"Dystcz\\LunarApiNewsletter\\Tests\\": "tests"
}
},
"scripts": {
"test": "vendor/bin/pest",
"test-coverage": "vendor/bin/phpunit --coverage-html coverage"
},
"config": {
"sort-packages": true,
"allow-plugins": {
"pestphp/pest-plugin": true
}
},
"extra": {
"laravel": {
"providers": [
"Dystcz\\LunarApiNewsletter\\LunarApiNewsletterServiceProvider"
],
"aliases": {
"LunarApiNewsletter": "Dystcz\\LunarApiNewsletter\\LunarApiNewsletterFacade"
}
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
25 changes: 0 additions & 25 deletions config/lunar-api-newsletter.php

This file was deleted.

22 changes: 22 additions & 0 deletions config/newsletter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

/*
* Lunar API Newsletter configuration
*/
return [
// Configuration for specific domains
'domains' => [
'newsletter' => [
'model' => null,
'lunar_model' => null,
'policy' => null,
'schema' => Dystcz\LunarApiNewsletter\Domain\Newsletter\JsonApi\V1\NewsletterSchema::class,
'resource' => Dystcz\LunarApiNewsletter\Domain\Newsletter\JsonApi\V1\NewsletterResource::class,
'query' => Dystcz\LunarApiNewsletter\Domain\Newsletter\JsonApi\V1\NewsletterQuery::class,
'collection_query' => Dystcz\LunarApiNewsletter\Domain\Newsletter\JsonApi\V1\NewsletterCollectionQuery::class,
'routes' => Dystcz\LunarApiNewsletter\Domain\Newsletter\Http\Routing\NewsletterRouteGroup::class,
'route_actions' => [],
'settings' => [],
],
],
];
11 changes: 11 additions & 0 deletions lang/en/validations.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

return [

'newsletter_subscription' => [
'email' => [
'required' => 'Please enter an email address',
'email' => 'Please enter a valid email address',
],
],
];
21 changes: 4 additions & 17 deletions routes/api.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,10 @@
<?php

use Dystcz\LunarApi\Routing\RouteGroup;
use Illuminate\Routing\Router;
use Illuminate\Support\Collection;
use Dystcz\LunarApi\Support\Config\Actions\RegisterRoutesFromConfig;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Route;

Route::group([
'prefix' => Config::get('lunar-api-newsletter.route_prefix'),
'middleware' => Config::get('lunar-api-newsletter.route_middleware'),
], function (Router $router) {
$domains = Collection::make(Config::get('lunar-api-newsletter.domains'));

foreach ($domains as $domain) {
if (isset($domain['route_groups'])) {
foreach ($domain['route_groups'] as $group) {
/** @var RouteGroup $group */
$group::make($domain['schema']::type())->routes();
}
}
}
});
'prefix' => Config::get('lunar-api.general.route_prefix'),
'middleware' => Config::get('lunar-api.general.route_middleware'),
], fn () => RegisterRoutesFromConfig::run('lunar-api.newsletter.domains'));
5 changes: 3 additions & 2 deletions src/Domain/Newsletter/Actions/SubscribeToNewsletter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

namespace Dystcz\LunarApiNewsletter\Domain\Newsletter\Actions;

use Dystcz\LunarApi\Support\Actions\Action;
use Spatie\Newsletter\Facades\Newsletter;

class SubscribeToNewsletter
class SubscribeToNewsletter extends Action
{
/**
* Subscribe to newsletter.
*/
public function __invoke(string $email): void
public function handle(string $email): void
{
Newsletter::subscribe($email);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Domain/Newsletter/Entities/NewsletterSubscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class NewsletterSubscription implements Arrayable
/**
* {@inheritDoc}
*/
public function toArray()
public function toArray(): array
{
return [
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Dystcz\LunarApiNewsletter\Domain\Newsletter\Http\Controllers;

use Dystcz\LunarApi\Controller;
use Dystcz\LunarApi\Base\Controller;
use Dystcz\LunarApiNewsletter\Domain\Newsletter\Actions\SubscribeToNewsletter;
use Dystcz\LunarApiNewsletter\Domain\Newsletter\JsonApi\V1\NewsletterSubscriptionRequest;
use Illuminate\Http\Response;
Expand Down
32 changes: 32 additions & 0 deletions src/Domain/Newsletter/JsonApi/V1/NewsletterCollectionQuery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Dystcz\LunarApiNewsletter\Domain\Newsletter\JsonApi\V1;

use Dystcz\LunarApi\Domain\Collections\JsonApi\V1\CollectionQuery;

class NewsletterCollectionQuery extends CollectionQuery
{
/**
* Get the validation rules that apply to the request query parameters.
*
* @return array<string,array<int,mixed>>
*/
public function rules(): array
{
return [
...parent::rules(),
];
}

/**
* Get custom messages for validator errors.
*
* @return array<string,string>
*/
public function messages(): array
{
return [
...parent::messages(),
];
}
}
32 changes: 32 additions & 0 deletions src/Domain/Newsletter/JsonApi/V1/NewsletterQuery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Dystcz\LunarApiNewsletter\Domain\Newsletter\JsonApi\V1;

use Dystcz\LunarApi\Domain\JsonApi\Queries\Query;

class NewsletterQuery extends Query
{
/**
* Get the validation rules that apply to the request query parameters.
*
* @return array<string,array<int,mixed>>
*/
public function rules(): array
{
return [
...parent::rules(),
];
}

/**
* Get custom messages for validator errors.
*
* @return array<string,string>
*/
public function messages(): array
{
return [
...parent::messages(),
];
}
}
19 changes: 19 additions & 0 deletions src/Domain/Newsletter/JsonApi/V1/NewsletterResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Dystcz\LunarApiNewsletter\Domain\Newsletter\JsonApi\V1;

use Dystcz\LunarApi\Domain\JsonApi\Resources\JsonApiResource;
use Illuminate\Http\Request;

class NewsletterResource extends JsonApiResource
{
/**
* Get the resource's attributes.
*
* @param Request|null $request
*/
public function attributes($request): iterable
{
return parent::attributes($request);
}
}
Loading
Loading