just a little scaffolding

This commit is contained in:
spencerrlongg 2024-10-23 12:55:47 -05:00
parent 5da3ce3564
commit 10d4c4b92e
3 changed files with 32 additions and 3 deletions

View file

@ -0,0 +1,12 @@
<?php
namespace App\Actions\Assets;
class StoreAssetAction
{
public static function run($validatedData)
{
}
}

View file

@ -2,10 +2,12 @@
namespace App\Http\Controllers\Assets;
use App\Actions\Assets\StoreAssetAction;
use App\Events\CheckoutableCheckedIn;
use App\Helpers\Helper;
use App\Http\Controllers\Controller;
use App\Http\Requests\ImageUploadRequest;
use App\Http\Requests\StoreAssetRequest;
use App\Models\Actionlog;
use App\Http\Requests\UploadFileRequest;
use Illuminate\Support\Facades\Log;
@ -96,12 +98,19 @@ class AssetsController extends Controller
* @author [A. Gianotto] [<snipe@snipe.net>]
* @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.

View file

@ -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,