From 10d4c4b92e338a7f93de5e23c6393d891d76ab46 Mon Sep 17 00:00:00 2001 From: spencerrlongg Date: Wed, 23 Oct 2024 12:55:47 -0500 Subject: [PATCH] just a little scaffolding --- app/Actions/Assets/StoreAssetAction.php | 12 ++++++++++++ app/Http/Controllers/Assets/AssetsController.php | 15 ++++++++++++--- app/Http/Requests/StoreAssetRequest.php | 8 ++++++++ 3 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 app/Actions/Assets/StoreAssetAction.php diff --git a/app/Actions/Assets/StoreAssetAction.php b/app/Actions/Assets/StoreAssetAction.php new file mode 100644 index 0000000000..6c9c95c269 --- /dev/null +++ b/app/Actions/Assets/StoreAssetAction.php @@ -0,0 +1,12 @@ +] * @since [v1.0] */ - public function store(ImageUploadRequest $request) : RedirectResponse + public function store(StoreAssetRequest $request): RedirectResponse { - $this->authorize(Asset::class); - + try { + StoreAssetAction::run($request->validated()); + } catch (\Exception $e) { + return back()->with('error', $e->getMessage()); + } // There are a lot more rules to add here but prevents // errors around `asset_tags` not being present below. + + // so do we want to foreach over the action, or convert the api's asset tags to an array as well + // so we can just easily add it to the action? + // (obviously then this would move up to the request) $this->validate($request, ['asset_tags' => ['required', 'array']]); // Handle asset tags - there could be one, or potentially many. diff --git a/app/Http/Requests/StoreAssetRequest.php b/app/Http/Requests/StoreAssetRequest.php index fb7469ac88..c34be2dbfa 100644 --- a/app/Http/Requests/StoreAssetRequest.php +++ b/app/Http/Requests/StoreAssetRequest.php @@ -36,6 +36,14 @@ class StoreAssetRequest extends ImageUploadRequest $this->parseLastAuditDate(); + // maybe do something like this? + if (!is_array($this->asset_tag)) { + $this->asset_tag = [$this->asset_tag]; + } + if (!is_array($this->serial)) { + $this->serial = [$this->serial]; + } + $this->merge([ 'asset_tag' => $this->asset_tag ?? Asset::autoincrement_asset(), 'company_id' => $idForCurrentUser,