A free open source IT asset/license management system
some notes and things moved
spencerrlongg5e81c63d6ee7
diff --git a/app/Actions/Categories/DestroyCategoryAction.php b/app/Actions/Categories/DestroyCategoryAction.phpindex 82be14afcc..65cdec2b83 100644--- a/app/Actions/Categories/DestroyCategoryAction.php+++ b/app/Actions/Categories/DestroyCategoryAction.php@@ -2,12 +2,13 @@namespace App\Actions\Categories;+use App\Exceptions\ModelIsNotDeletable;use App\Helpers\Helper;use App\Models\Category;class DestroyCategoryAction{- static function run(Category $category)+ static function run(Category $category): bool{// why do we need to do this?// hm,@@ -20,11 +21,13 @@ class DestroyCategoryAction'models as models_count']);+ // this should give better errors, do we throw down in the model for this one, or move that logic up here?+ // one of those fat-model vs action things...if (!$category->isDeletable()) {- return response()->json(- Helper::formatStandardApiResponse('error', null, trans('admin/categories/message.assoc_items', ['asset_type' => $category->category_type]))- );+ throw new ModelIsNotDeletable($category);}$category->delete();++ return true;}}\ No newline at end of filediff --git a/app/Exceptions/ModelIsNotDeletable.php b/app/Exceptions/ModelIsNotDeletable.phpnew file mode 100644index 0000000000..31da7914ef--- /dev/null+++ b/app/Exceptions/ModelIsNotDeletable.php@@ -0,0 +1,10 @@+<?php++namespace App\Exceptions;++use Exception;++class ModelIsNotDeletable extends Exception+{+ //+}diff --git a/app/Http/Controllers/Api/CategoriesController.php b/app/Http/Controllers/Api/CategoriesController.phpindex 98c4f061a4..45cad70cbc 100644--- a/app/Http/Controllers/Api/CategoriesController.php+++ b/app/Http/Controllers/Api/CategoriesController.php@@ -2,6 +2,8 @@namespace App\Http\Controllers\Api;+use App\Actions\Categories\DestroyCategoryAction;+use App\Exceptions\ModelIsNotDeletable;use App\Helpers\Helper;use App\Http\Controllers\Controller;use App\Http\Transformers\CategoriesTransformer;@@ -209,10 +211,16 @@ class CategoriesController extends Controller* @param int $id* @return \Illuminate\Http\Response*/- public function destroy($id) : JsonResponse+ public function destroy(Category $category): JsonResponse{$this->authorize('delete', Category::class);-+ try {+ DestroyCategoryAction::run(category: $category);+ } catch (ModelIsNotDeletable $e) {+ return response()->json(+ Helper::formatStandardApiResponse('error', null, trans('admin/categories/message.assoc_items', ['asset_type' => $category->category_type]))+ );+ }return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/categories/message.delete.success')));}