From ad2d54cf0efaf022e0e37765bbca1725b1b0ceea Mon Sep 17 00:00:00 2001 From: glovetleong Date: Mon, 20 Sep 2021 15:34:28 +0800 Subject: [PATCH] package switch packing list --- .../SwitchPackagePackingListLogic.php | 68 +++++++++++++++++++ .../Packages/SwitchesPackagePackingList.php | 25 +++++++ .../SwitchPackagePackingListController.php | 20 ++++++ routes/packing_list.php | 1 + 4 files changed, 114 insertions(+) create mode 100644 app/Classes/Modules/PackingLists/ControllersLogic/Packages/SwitchPackagePackingListLogic.php create mode 100644 app/Classes/Modules/PackingLists/Services/Packages/SwitchesPackagePackingList.php create mode 100644 app/Http/Controllers/PackingLists/Packages/SwitchPackagePackingListController.php diff --git a/app/Classes/Modules/PackingLists/ControllersLogic/Packages/SwitchPackagePackingListLogic.php b/app/Classes/Modules/PackingLists/ControllersLogic/Packages/SwitchPackagePackingListLogic.php new file mode 100644 index 00000000..cdbc7917 --- /dev/null +++ b/app/Classes/Modules/PackingLists/ControllersLogic/Packages/SwitchPackagePackingListLogic.php @@ -0,0 +1,68 @@ + 'Switched Package Packing List', + 'message' => 'You have successfully switched the Package Packing List' + ]; + } + + /** @var SwitchesPackagePackingList */ + private $switchesPackagePackingList; + + /** @var FetchesPackage */ + private $fetchesPackage; + + /** @var FetchesPackingList */ + private $fetchesPackingList; + + /** + * UpdatePackageLogic constructor. + * @param SwitchesPackagePackingList $switchesPackagePackingList + * @param FetchesPackage $fetchesPackage + * @param FetchesPackingList $fetchesPackingList + */ + public function __construct(SwitchesPackagePackingList $switchesPackagePackingList, FetchesPackage $fetchesPackage, FetchesPackingList $fetchesPackingList) + { + $this->switchesPackagePackingList = $switchesPackagePackingList; + $this->fetchesPackage = $fetchesPackage; + $this->fetchesPackingList = $fetchesPackingList; + } + + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + $package = $this->fetchesPackage->execute(['id' => $request->route('id')]); + + $packing_list = $this->fetchesPackingList->execute(['id' => $request->input('packing_list_id')]); + + $query = $this->switchesPackagePackingList->execute($package, $packing_list); + + return $this->resourceResponse(new PackageResource($query)); + } + +} diff --git a/app/Classes/Modules/PackingLists/Services/Packages/SwitchesPackagePackingList.php b/app/Classes/Modules/PackingLists/Services/Packages/SwitchesPackagePackingList.php new file mode 100644 index 00000000..9abedc0b --- /dev/null +++ b/app/Classes/Modules/PackingLists/Services/Packages/SwitchesPackagePackingList.php @@ -0,0 +1,25 @@ +packing_list_id = $packing_list->id; + + return $this->handler($model); + + } +} diff --git a/app/Http/Controllers/PackingLists/Packages/SwitchPackagePackingListController.php b/app/Http/Controllers/PackingLists/Packages/SwitchPackagePackingListController.php new file mode 100644 index 00000000..42c85cff --- /dev/null +++ b/app/Http/Controllers/PackingLists/Packages/SwitchPackagePackingListController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} diff --git a/routes/packing_list.php b/routes/packing_list.php index ea64c7e1..231d8b99 100644 --- a/routes/packing_list.php +++ b/routes/packing_list.php @@ -24,6 +24,7 @@ Route::group(['namespace' => 'PackingLists', 'as' => 'packing_list.', 'prefix' = Route::post('/create', 'CreatePackageController@create')->name('create'); Route::put('/update/{id}', 'UpdatePackageController@update')->name('update'); Route::delete('/delete/{id}', 'DeletePackageController@delete')->name('delete'); + Route::put('/switch-packing-list/{id}', 'SwitchPackagePackingListController@switch')->name('switch.packing_list'); Route::group(['namespace' => 'PackageItems', 'prefix' => 'item', 'as' => 'item.'], function () { Route::get('/{id}/show', 'FetchPackageItemController@fetch')->name('show');