From f75201dfaa01885018475fb58d5c41e55363be17 Mon Sep 17 00:00:00 2001 From: Philipp Lang Date: Thu, 1 Jun 2023 15:45:02 +0200 Subject: [PATCH] Add: Store new mailgateway --- app/Mailgateway/Actions/StoreAction.php | 33 ++++++++++++++ .../Resources/MailgatewayResource.php | 12 +++++ resources/js/views/mailgateway/Index.vue | 44 ++++++++++++------- routes/web.php | 3 +- tests/Feature/Mailgateway/IndexTest.php | 4 ++ tests/Feature/Mailgateway/StoreTest.php | 32 ++++++++++++++ .../MailgatewayRequestFactory.php | 42 ++++++++++++++++++ 7 files changed, 153 insertions(+), 17 deletions(-) create mode 100644 app/Mailgateway/Actions/StoreAction.php create mode 100644 tests/Feature/Mailgateway/StoreTest.php create mode 100644 tests/RequestFactories/MailgatewayRequestFactory.php diff --git a/app/Mailgateway/Actions/StoreAction.php b/app/Mailgateway/Actions/StoreAction.php new file mode 100644 index 00000000..d427ba0a --- /dev/null +++ b/app/Mailgateway/Actions/StoreAction.php @@ -0,0 +1,33 @@ + 'required|string|max:255', + 'domain' => 'required|string|max:255', + 'type.class' => ['required', 'string', 'max:255', Rule::in(app('mail-gateways'))], + 'type.params' => 'present', + ]; + } + + public function asController(ActionRequest $request): void + { + $this->handle($request->validated()); + } +} diff --git a/app/Mailgateway/Resources/MailgatewayResource.php b/app/Mailgateway/Resources/MailgatewayResource.php index 846ad1d0..d919506c 100644 --- a/app/Mailgateway/Resources/MailgatewayResource.php +++ b/app/Mailgateway/Resources/MailgatewayResource.php @@ -36,6 +36,18 @@ class MailgatewayResource extends JsonResource 'links' => [ 'store' => route('api.mailgateway.store'), ], + 'types' => app('mail-gateways')->map(fn ($gateway) => [ + 'id' => $gateway, + 'name' => $gateway::name(), + ]), + 'default' => [ + 'domain' => '', + 'name' => '', + 'type' => [ + 'params' => [], + 'class' => null, + ], + ], ]; } } diff --git a/resources/js/views/mailgateway/Index.vue b/resources/js/views/mailgateway/Index.vue index 065dcc74..8eed8e08 100644 --- a/resources/js/views/mailgateway/Index.vue +++ b/resources/js/views/mailgateway/Index.vue @@ -1,21 +1,18 @@