From 5ef5e95be8bfb6b6eee40d768a3380f4fbd8ffab Mon Sep 17 00:00:00 2001 From: philipp lang Date: Thu, 24 Oct 2024 23:17:23 +0200 Subject: [PATCH] Move modules --- app/Maildispatcher/Models/Maildispatcher.php | 2 +- .../Resources/MaildispatcherResource.php | 2 +- app/Mailgateway/Actions/StoreAction.php | 27 -------- app/Mailgateway/Actions/UpdateAction.php | 28 -------- app/Mailgateway/Actions/ValidatesRequests.php | 65 ------------------- app/Mailgateway/MailgatewaySettings.php | 2 +- .../Resources/MailgatewayResource.php | 2 +- modules/Mailgateway/Components/Form.php | 2 +- .../Mailgateway/Components/SettingView.php | 2 +- modules/Mailgateway/IndexTest.php | 4 +- .../Mailgateway/Models/Mailgateway.php | 6 +- .../Mailgateway/Models/MailgatewayFactory.php | 5 +- modules/Mailgateway/StoreTest.php | 2 +- modules/Mailgateway/UpdateTest.php | 4 +- tests/EndToEnd/Maildispatcher/StoreTest.php | 2 +- tests/EndToEnd/Maildispatcher/UpdateTest.php | 2 +- 16 files changed, 19 insertions(+), 138 deletions(-) delete mode 100644 app/Mailgateway/Actions/StoreAction.php delete mode 100644 app/Mailgateway/Actions/UpdateAction.php delete mode 100644 app/Mailgateway/Actions/ValidatesRequests.php rename {app => modules}/Mailgateway/Models/Mailgateway.php (79%) rename {database/factories => modules}/Mailgateway/Models/MailgatewayFactory.php (82%) diff --git a/app/Maildispatcher/Models/Maildispatcher.php b/app/Maildispatcher/Models/Maildispatcher.php index 3cdf717f..c17e0176 100644 --- a/app/Maildispatcher/Models/Maildispatcher.php +++ b/app/Maildispatcher/Models/Maildispatcher.php @@ -2,7 +2,7 @@ namespace App\Maildispatcher\Models; -use App\Mailgateway\Models\Mailgateway; +use Modules\Mailgateway\Models\Mailgateway; use Database\Factories\Maildispatcher\Models\MaildispatcherFactory; use Illuminate\Database\Eloquent\Concerns\HasUuids; use Illuminate\Database\Eloquent\Factories\HasFactory; diff --git a/app/Maildispatcher/Resources/MaildispatcherResource.php b/app/Maildispatcher/Resources/MaildispatcherResource.php index 7250d916..9928209e 100644 --- a/app/Maildispatcher/Resources/MaildispatcherResource.php +++ b/app/Maildispatcher/Resources/MaildispatcherResource.php @@ -4,7 +4,7 @@ namespace App\Maildispatcher\Resources; use App\Lib\HasMeta; use App\Maildispatcher\Models\Maildispatcher; -use App\Mailgateway\Models\Mailgateway; +use Modules\Mailgateway\Models\Mailgateway; use App\Mailgateway\Resources\MailgatewayResource; use App\Member\FilterScope; use App\Member\Member; diff --git a/app/Mailgateway/Actions/StoreAction.php b/app/Mailgateway/Actions/StoreAction.php deleted file mode 100644 index 41194c6a..00000000 --- a/app/Mailgateway/Actions/StoreAction.php +++ /dev/null @@ -1,27 +0,0 @@ - $input - */ - public function handle(array $input): void - { - $this->checkIfWorks($input); - Mailgateway::create($input); - } - - public function asController(ActionRequest $request): void - { - $this->handle($request->validated()); - } -} diff --git a/app/Mailgateway/Actions/UpdateAction.php b/app/Mailgateway/Actions/UpdateAction.php deleted file mode 100644 index 4b794520..00000000 --- a/app/Mailgateway/Actions/UpdateAction.php +++ /dev/null @@ -1,28 +0,0 @@ - $input - */ - public function handle(Mailgateway $mailgateway, array $input): void - { - $this->checkIfWorks($input); - - $mailgateway->update($input); - } - - public function asController(Mailgateway $mailgateway, ActionRequest $request): void - { - $this->handle($mailgateway, $request->validated()); - } -} diff --git a/app/Mailgateway/Actions/ValidatesRequests.php b/app/Mailgateway/Actions/ValidatesRequests.php deleted file mode 100644 index 50df8bf0..00000000 --- a/app/Mailgateway/Actions/ValidatesRequests.php +++ /dev/null @@ -1,65 +0,0 @@ - $input - */ - public function checkIfWorks(array $input): void - { - if (!app(data_get($input, 'type.cls'))->setParams($input['type']['params'])->works()) { - throw ValidationException::withMessages(['connection' => 'Verbindung fehlgeschlagen.']); - } - } - - /** - * @return array - */ - public function rules(): array - { - return [ - 'name' => 'required|string|max:255', - 'domain' => 'required|string|max:255', - ...$this->typeValidation(), - 'type.params' => 'present|array', - ...collect(request()->input('type.cls')::rules('storeValidator'))->mapWithKeys(fn ($rules, $key) => ["type.params.{$key}" => $rules]), - ]; - } - - /** - * @return array - */ - public function getValidationAttributes(): array - { - return [ - 'type.cls' => 'Typ', - 'name' => 'Beschreibung', - 'domain' => 'Domain', - ...collect(request()->input('type.cls')::fieldNames())->mapWithKeys(fn ($attribute, $key) => ["type.params.{$key}" => $attribute]), - ]; - } - - /** - * @return array - */ - private function typeValidation(): array - { - return [ - 'type.cls' => ['required', 'string', 'max:255', Rule::in(app('mail-gateways'))], - ]; - } - - public function prepareForValidation(ActionRequest $request): void - { - if (!is_subclass_of(request()->input('type.cls'), Type::class)) { - throw ValidationException::withMessages(['type.cls' => 'Typ ist nicht valide.']); - } - } -} diff --git a/app/Mailgateway/MailgatewaySettings.php b/app/Mailgateway/MailgatewaySettings.php index 5a84f267..31c38d57 100644 --- a/app/Mailgateway/MailgatewaySettings.php +++ b/app/Mailgateway/MailgatewaySettings.php @@ -2,7 +2,7 @@ namespace App\Mailgateway; -use App\Mailgateway\Models\Mailgateway; +use Modules\Mailgateway\Models\Mailgateway; use App\Mailgateway\Resources\MailgatewayResource; use App\Setting\LocalSettings; diff --git a/app/Mailgateway/Resources/MailgatewayResource.php b/app/Mailgateway/Resources/MailgatewayResource.php index d27a838f..3386d35a 100644 --- a/app/Mailgateway/Resources/MailgatewayResource.php +++ b/app/Mailgateway/Resources/MailgatewayResource.php @@ -3,7 +3,7 @@ namespace App\Mailgateway\Resources; use App\Lib\HasMeta; -use App\Mailgateway\Models\Mailgateway; +use Modules\Mailgateway\Models\Mailgateway; use Illuminate\Http\Resources\Json\JsonResource; /** diff --git a/modules/Mailgateway/Components/Form.php b/modules/Mailgateway/Components/Form.php index b9adde5f..ce1f4390 100644 --- a/modules/Mailgateway/Components/Form.php +++ b/modules/Mailgateway/Components/Form.php @@ -2,7 +2,7 @@ namespace Modules\Mailgateway\Components; -use App\Mailgateway\Models\Mailgateway; +use Modules\Mailgateway\Models\Mailgateway; use App\Mailgateway\Types\Type; use Illuminate\Support\Collection; use Illuminate\Validation\ValidationException; diff --git a/modules/Mailgateway/Components/SettingView.php b/modules/Mailgateway/Components/SettingView.php index b6d892ea..977383ba 100644 --- a/modules/Mailgateway/Components/SettingView.php +++ b/modules/Mailgateway/Components/SettingView.php @@ -2,7 +2,7 @@ namespace Modules\Mailgateway\Components; -use App\Mailgateway\Models\Mailgateway; +use Modules\Mailgateway\Models\Mailgateway; use Livewire\Component; use Modules\Mailgateway\MailgatewaySettings; diff --git a/modules/Mailgateway/IndexTest.php b/modules/Mailgateway/IndexTest.php index d806616a..b0e018e7 100644 --- a/modules/Mailgateway/IndexTest.php +++ b/modules/Mailgateway/IndexTest.php @@ -1,8 +1,8 @@ */ use HasFactory; use HasUuids; diff --git a/database/factories/Mailgateway/Models/MailgatewayFactory.php b/modules/Mailgateway/Models/MailgatewayFactory.php similarity index 82% rename from database/factories/Mailgateway/Models/MailgatewayFactory.php rename to modules/Mailgateway/Models/MailgatewayFactory.php index 968599a4..3f97c29c 100644 --- a/database/factories/Mailgateway/Models/MailgatewayFactory.php +++ b/modules/Mailgateway/Models/MailgatewayFactory.php @@ -1,14 +1,13 @@ + * @extends Factory */ class MailgatewayFactory extends Factory { diff --git a/modules/Mailgateway/StoreTest.php b/modules/Mailgateway/StoreTest.php index 69c8445b..debb6dfb 100644 --- a/modules/Mailgateway/StoreTest.php +++ b/modules/Mailgateway/StoreTest.php @@ -1,6 +1,6 @@