From 1281990b08bf6bd3a3a3050a4abe84b9eb44d319 Mon Sep 17 00:00:00 2001 From: Fairuz Date: Sat, 24 Jul 2021 00:11:59 +0800 Subject: [PATCH] WIP - Order steps & remaining APIs --- .../CreatePackingListLogic.php | 34 +++++++++++++++---- .../PackingListPackageObject.php | 2 +- .../Services/CreatesPackingList.php | 23 +++---------- .../Services/CreatesPackingListPackage.php | 19 +++++++++++ .../Services/CreatesPackingListPackages.php | 32 ----------------- .../Rules/CanCreatePackingListPackage.php | 6 ++-- .../CreatePackingListController.php | 2 +- app/Models/PackingList.php | 2 +- app/Models/PackingListPackage.php | 4 +-- resources/views/swagger/json.blade.php | 18 ++-------- 10 files changed, 61 insertions(+), 81 deletions(-) create mode 100644 app/Classes/Modules/PackingLists/Services/CreatesPackingListPackage.php delete mode 100644 app/Classes/Modules/PackingLists/Services/CreatesPackingListPackages.php diff --git a/app/Classes/Modules/PackingLists/ControllersLogic/CreatePackingListLogic.php b/app/Classes/Modules/PackingLists/ControllersLogic/CreatePackingListLogic.php index be09d7a8..117107aa 100644 --- a/app/Classes/Modules/PackingLists/ControllersLogic/CreatePackingListLogic.php +++ b/app/Classes/Modules/PackingLists/ControllersLogic/CreatePackingListLogic.php @@ -5,9 +5,12 @@ namespace App\Classes\Modules\PackingLists\ControllersLogic; use App\Classes\General\Abstracts\AbstractControllerLogic; use App\Classes\Modules\PackingLists\Services\CreatesPackingList; +use App\Classes\Modules\PackingLists\Services\CreatesPackingListPackage; use App\Classes\Modules\PackingLists\Standards\Rules\CanCreatePackingList; +use App\Classes\Modules\PackingLists\Standards\Rules\CanCreatePackingListPackage; use App\Classes\Modules\PackingLists\DataTransferObjects\PackingListObject; -use App\Classes\Modules\Companies\Services\FetchesCompany; +use App\Classes\Modules\PackingLists\DataTransferObjects\PackingListPackageObject; +use App\Classes\Modules\Packages\Services\FetchesPackage; use App\Http\Resources\PackingListResource; use ErrorException; use Illuminate\Http\JsonResponse; @@ -29,12 +32,16 @@ class CreatePackingListLogic extends AbstractControllerLogic /** @var CanCreatePackingList */ private $canCreatePackingList; + private $canCreatePackingListPackage; + /** @var FetchesCompany */ - private $fetchesCompany; + private $fetchesPackage; /** @var CreatesPackingList */ private $createsPackingList; + private $createsPackingListPackage; + /** * CreatePackingListLogic constructor. * @param CanCreatePackingList $canCreatePackingList @@ -42,11 +49,13 @@ class CreatePackingListLogic extends AbstractControllerLogic * @param FetchesCompany $fetchesCompany * @param CreatesPackingList $createsPackingList */ - public function __construct(CanCreatePackingList $canCreatePackingList, FetchesCompany $fetchesCompany, CreatesPackingList $createsPackingList) + public function __construct(CanCreatePackingList $canCreatePackingList, CanCreatePackingListPackage $canCreatePackingListPackage, FetchesPackage $fetchesPackage, CreatesPackingList $createsPackingList, CreatesPackingListPackage $createsPackingListPackage) { $this->canCreatePackingList = $canCreatePackingList; - $this->fetchesCompany = $fetchesCompany; + $this->canCreatePackingListPackage = $canCreatePackingListPackage; + $this->fetchesPackage = $fetchesPackage; $this->createsPackingList = $createsPackingList; + $this->createsPackingListPackage = $createsPackingListPackage; } /** @@ -59,13 +68,24 @@ class CreatePackingListLogic extends AbstractControllerLogic public function logic(Request $request) : JsonResponse { - $district = $this->fetchesDistrict->execute(['id' => $request->input('district_id')]); + $package = $this->fetchesPackage->execute(['id'=>$request->input('package_id')]); - $object = new PackingListObject($request->input('street_one'), $request->input('street_two'), $district->country_id, $district->state_id, $district->id, $request->input('post_code')); + $reference_no = rand(1000000, 9999999); + + + $object = new PackingListObject($reference_no, 0); $this->canCreatePackingList->passes($object); - $query = $this->createsPackingList->execute($this->fetchesCompany->execute(['id' => $request->input('company_id')]), $object); + $packageList = $this->createsPackingList->execute( $object); + + + $object = new PackingListPackageObject($packageList->id, $package->id); + + $this->canCreatePackingListPackage->passes($object); + + $query = $this->createsPackingListPackage->execute($object); + return $this->resourceResponse(new PackingListResource($query)); diff --git a/app/Classes/Modules/PackingLists/DataTransferObjects/PackingListPackageObject.php b/app/Classes/Modules/PackingLists/DataTransferObjects/PackingListPackageObject.php index bf663f77..3c1aef5b 100644 --- a/app/Classes/Modules/PackingLists/DataTransferObjects/PackingListPackageObject.php +++ b/app/Classes/Modules/PackingLists/DataTransferObjects/PackingListPackageObject.php @@ -4,7 +4,7 @@ namespace App\Classes\Modules\PackingLists\DataTransferObjects; use App\Classes\General\Interfaces\DataTransferObject; -class PackingListObject implements DataTransferObject +class PackingListPackageObject implements DataTransferObject { private $packingListId; diff --git a/app/Classes/Modules/PackingLists/Services/CreatesPackingList.php b/app/Classes/Modules/PackingLists/Services/CreatesPackingList.php index 05f7c000..2cb151c5 100644 --- a/app/Classes/Modules/PackingLists/Services/CreatesPackingList.php +++ b/app/Classes/Modules/PackingLists/Services/CreatesPackingList.php @@ -3,30 +3,17 @@ namespace App\Classes\Modules\PackingLists\Services; use App\Classes\General\Eloquent\AbstractUpdateRecord; -use App\Classes\General\Eloquent\AbstractUpdateRelationshipRecord; use App\Classes\Modules\PackingLists\DataTransferObjects\PackingListObject; use App\Models\PackingList; -use App\Models\Company; -class CreatesPackingList extends AbstractUpdateRelationshipRecord +class CreatesPackingList extends AbstractUpdateRecord { - - /** - * @param Company $company - * @param PackingListObject $object - * @return \Illuminate\Database\Eloquent\Model - * @throws \App\Classes\Exceptions\MalformedRequestException - */ - public function execute(Company $company, PackingListObject $object) { + public function execute(PackingListObject $object) { $model = new PackingList(); - $model->street_one = $object->getStreetOne(); - $model->street_two = $object->getStreetTwo(); - $model->country_id = $object->getCountryId(); - $model->state_id = $object->getStateId(); - $model->district_id = $object->getDistrictId(); - $model->postcode = $object->getPostCode(); - return $this->handler($company->PackingLists(), $model); + $model->reference = $object->getReference(); + $model->status = $object->getStatus(); + return $this->handler($model); } } diff --git a/app/Classes/Modules/PackingLists/Services/CreatesPackingListPackage.php b/app/Classes/Modules/PackingLists/Services/CreatesPackingListPackage.php new file mode 100644 index 00000000..8d14744d --- /dev/null +++ b/app/Classes/Modules/PackingLists/Services/CreatesPackingListPackage.php @@ -0,0 +1,19 @@ +packing_list_id = $object->getPackingListId(); + $model->package_id = $object->getPackageId(); + + return $this->handler( $model); + } +} diff --git a/app/Classes/Modules/PackingLists/Services/CreatesPackingListPackages.php b/app/Classes/Modules/PackingLists/Services/CreatesPackingListPackages.php deleted file mode 100644 index acb2c390..00000000 --- a/app/Classes/Modules/PackingLists/Services/CreatesPackingListPackages.php +++ /dev/null @@ -1,32 +0,0 @@ -street_one = $object->getStreetOne(); - $model->street_two = $object->getStreetTwo(); - $model->country_id = $object->getCountryId(); - $model->state_id = $object->getStateId(); - $model->district_id = $object->getDistrictId(); - $model->postcode = $object->getPostCode(); - - return $this->handler($company->PackingLists(), $model); - - } -} diff --git a/app/Classes/Modules/PackingLists/Standards/Rules/CanCreatePackingListPackage.php b/app/Classes/Modules/PackingLists/Standards/Rules/CanCreatePackingListPackage.php index 579505b2..aca44c8b 100644 --- a/app/Classes/Modules/PackingLists/Standards/Rules/CanCreatePackingListPackage.php +++ b/app/Classes/Modules/PackingLists/Standards/Rules/CanCreatePackingListPackage.php @@ -10,14 +10,14 @@ use App\Classes\Modules\PackingLists\Standards\Validators\PackingListPackageVali class CanCreatePackingListPackage extends AbstractRule { - /** @var PackingListValidationPackage */ + /** @var PackingListPackageValidation */ private $packingListPackageValidation; /** * CanCreatePackingListPackage constructor. - * @param PackingListValidationPackage $packingListPackageValidation + * @param PackingListPackageValidation $packingListPackageValidation */ - public function __construct(PackingListValidationPackage $packingListPackageValidation) + public function __construct(PackingListPackageValidation $packingListPackageValidation) { $this->packingListPackageValidation = $packingListPackageValidation; } diff --git a/app/Http/Controllers/PackingLists/CreatePackingListController.php b/app/Http/Controllers/PackingLists/CreatePackingListController.php index 9f6bc16d..c0cec426 100644 --- a/app/Http/Controllers/PackingLists/CreatePackingListController.php +++ b/app/Http/Controllers/PackingLists/CreatePackingListController.php @@ -1,6 +1,6 @@ BelongsTo(PackageList::class, 'package_list_id', 'id'); + return $this->BelongsTo(PackageList::class, 'packing_list_id', 'id'); } } diff --git a/resources/views/swagger/json.blade.php b/resources/views/swagger/json.blade.php index b8eed680..397844e4 100644 --- a/resources/views/swagger/json.blade.php +++ b/resources/views/swagger/json.blade.php @@ -71,25 +71,11 @@ "description": "", "parameters": [ { - "name": "type", + "name": "package_id", "in": "query", - "description": "Transport type", + "description": "Package Id", "required": true, "type": "integer" - }, - { - "name": "courier", - "in": "query", - "description": "Courier Provider Name", - "required": true, - "type": "string" - }, - { - "name": "tracking_number", - "in": "query", - "description": "Tracking No.", - "required": true, - "type": "string" } ], "responses": {