diff --git a/app/Containers/v1/Notification/Controllers/Controller.php b/app/Containers/v1/Notification/Controllers/Controller.php index ce7b0e3..7d4625c 100644 --- a/app/Containers/v1/Notification/Controllers/Controller.php +++ b/app/Containers/v1/Notification/Controllers/Controller.php @@ -73,9 +73,9 @@ public function read(string $notificationId) * * @return \Illuminate\Http\JsonResponse */ - public function multiRead(MultiReadRequest $request) + public function multiRead(Request $request) { - $notificationStoreDTO = NotificationStoreDTO::fromRequest($request); + $notificationStoreDTO = NotificationStoreDTO::from($request); Executor::run('Notification@MultiReadAction', $notificationStoreDTO); return Responder::success([], __('message.success_update')); @@ -88,9 +88,9 @@ public function multiRead(MultiReadRequest $request) * * @return \Illuminate\Http\JsonResponse */ - public function multiDelete(MultiDeleteRequest $request) + public function multiDelete(Request $request) { - $notificationStoreDTO = NotificationStoreDTO::fromRequest($request); + $notificationStoreDTO = NotificationStoreDTO::from($request); Executor::run('Notification@MultiDeleteAction', $notificationStoreDTO); return Responder::success([], __('message.success_delete')); diff --git a/app/Containers/v1/Notification/DTO/NotificationStoreDTO.php b/app/Containers/v1/Notification/DTO/NotificationStoreDTO.php index 3dcc920..6a773bb 100644 --- a/app/Containers/v1/Notification/DTO/NotificationStoreDTO.php +++ b/app/Containers/v1/Notification/DTO/NotificationStoreDTO.php @@ -2,17 +2,27 @@ namespace App\Containers\v1\Notification\DTO; -use Illuminate\Http\Request; -use Spatie\DataTransferObject\DataTransferObject; +use Spatie\LaravelData\Data; -class NotificationStoreDTO extends DataTransferObject +/** + * @reference https://github.com/spatie/data-transfer-object + */ +class NotificationStoreDTO extends Data { - public $notification_ids; + public function __construct( + public array $notification_ids + ) {} - public static function fromRequest(Request $request): self + /** + * to construct a custom rule object + * + * @reference https://laravel.com/docs/9.x/validation + */ + public static function rules(): array { - return new self([ - 'notification_ids' => $request->notification_ids - ]); + return [ + 'notification_ids' => ['required', 'array', 'bail'], + 'notification_ids.*' => ['integer', 'max:36', 'bail'] + ]; } } diff --git a/app/Containers/v1/Notification/Requests/MultiDeleteRequest.php b/app/Containers/v1/Notification/Requests/MultiDeleteRequest.php deleted file mode 100644 index 1e9fcab..0000000 --- a/app/Containers/v1/Notification/Requests/MultiDeleteRequest.php +++ /dev/null @@ -1,16 +0,0 @@ - ['nullable', 'array', 'bail'], - 'notification_ids.*' => ['string', 'max:36', 'bail'] - ]; - } -} diff --git a/app/Containers/v1/Notification/Requests/MultiReadRequest.php b/app/Containers/v1/Notification/Requests/MultiReadRequest.php deleted file mode 100644 index fe85a13..0000000 --- a/app/Containers/v1/Notification/Requests/MultiReadRequest.php +++ /dev/null @@ -1,16 +0,0 @@ - ['nullable', 'array', 'bail'], - 'notification_ids.*' => ['string', 'max:36', 'bail'] - ]; - } -}