From 3899dd8416749b7dd47b86950ebf002e2ec8960e Mon Sep 17 00:00:00 2001 From: edmondlang Date: Fri, 22 Apr 2022 00:18:12 +0800 Subject: [PATCH 1/5] update base price api --- .../ControllersLogic/CreateBasePriceLogic.php | 121 ++++++++++++++++++ .../UpdatesBasePriceConstantByDates.php | 29 +++++ .../Segments/CreateBasePriceController.php | 20 +++ .../settings/forms/BasePriceFormComponent.vue | 80 ++++++++++++ resources/views/pages/settings.blade.php | 65 ++++++++-- routes/segment.php | 2 + 6 files changed, 309 insertions(+), 8 deletions(-) create mode 100644 app/Classes/Modules/Segments/ControllersLogic/CreateBasePriceLogic.php create mode 100644 app/Classes/Modules/Segments/Services/UpdatesBasePriceConstantByDates.php create mode 100644 app/Http/Controllers/Segments/CreateBasePriceController.php create mode 100644 resources/assets/vue/components/settings/forms/BasePriceFormComponent.vue diff --git a/app/Classes/Modules/Segments/ControllersLogic/CreateBasePriceLogic.php b/app/Classes/Modules/Segments/ControllersLogic/CreateBasePriceLogic.php new file mode 100644 index 00000000..a589995c --- /dev/null +++ b/app/Classes/Modules/Segments/ControllersLogic/CreateBasePriceLogic.php @@ -0,0 +1,121 @@ + 'Create Base Price', + 'message' => 'You have successfully created a Base Price' + ]; + } + + /** @var CanUpdateConstant */ + private $canUpdateConstant; + + /** @var UpdatesConstant */ + private $updatesConstant; + + /** @var FetchesSegment */ + private $fetchesSegment; + + /** @var FetchesConstant */ + private $fetchesConstant; + + /** @var CanCreateConstant */ + private $canCreateConstant; + + /** @var CreatesConstant */ + private $createsConstant; + + + /** @var UpdatesBasePriceConstantByDates */ + private $updatesBasePriceConstantByDates; + + /** + * UpdateConstantLogic constructor. + * @param CanUpdateConstant $canUpdateConstant + * @param UpdatesConstant $updatesConstant + * @param FetchesSegment $fetchesSegment + * @param FetchesConstant $fetchesConstant + * @param CanCreateConstant $canCreateConstant + * @param CreatesConstant $createsConstant + * @param UpdatesBasePriceConstantByDates $updatesBasePriceConstantByDates + */ + public function __construct( + CanUpdateConstant $canUpdateConstant, + UpdatesConstant $updatesConstant, + FetchesSegment $fetchesSegment, + FetchesConstant $fetchesConstant, + CanCreateConstant $canCreateConstant, + CreatesConstant $createsConstant, + UpdatesBasePriceConstantByDates $updatesBasePriceConstantByDates + ) + { + $this->canUpdateConstant = $canUpdateConstant; + $this->updatesConstant = $updatesConstant; + $this->fetchesSegment = $fetchesSegment; + $this->fetchesConstant = $fetchesConstant; + $this->canCreateConstant = $canCreateConstant; + $this->createsConstant = $createsConstant; + $this->updatesBasePriceConstantByDates = $updatesBasePriceConstantByDates; + } + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\AccessForbiddenException + * @throws \App\Classes\Exceptions\MalformedRequestException + * @throws \App\Classes\Exceptions\RequestValidationException + */ + public function logic(Request $request) : JsonResponse + { + $segment = $this->fetchesSegment->execute(['id' => $request->route('id')]); + + try { + + $constant = $this->fetchesConstant->execute(['segment_id' => $segment->id, 'reference' => SegmentConstants::BASE_PRICE]); + + } catch (ResourceNotFoundException $exception){ + + $constantObject = []; + + $object = new ConstantObject( + SegmentConstants::BASE_PRICE, + $constantObject + ); + + $constant = $this->createsConstant->execute($segment, $object); + } + + $constantValue = $this->updatesBasePriceConstantByDates->execute($constant->value, $request->input('dateFrom'), $request->input('dateTo'), $request->input('rate')); + + $object = new ConstantObject(SegmentConstants::BASE_PRICE, $constantValue); + + $this->canUpdateConstant->passes($object); + + $constant = $this->updatesConstant->execute($constant, $object); + + return $this->resourceResponse(new ConstantResource($constant)); + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Segments/Services/UpdatesBasePriceConstantByDates.php b/app/Classes/Modules/Segments/Services/UpdatesBasePriceConstantByDates.php new file mode 100644 index 00000000..db49d2c8 --- /dev/null +++ b/app/Classes/Modules/Segments/Services/UpdatesBasePriceConstantByDates.php @@ -0,0 +1,29 @@ +format('Y-m-d')] = $rate; + } + + return $objectArray; + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/Segments/CreateBasePriceController.php b/app/Http/Controllers/Segments/CreateBasePriceController.php new file mode 100644 index 00000000..b8f63eeb --- /dev/null +++ b/app/Http/Controllers/Segments/CreateBasePriceController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/resources/assets/vue/components/settings/forms/BasePriceFormComponent.vue b/resources/assets/vue/components/settings/forms/BasePriceFormComponent.vue new file mode 100644 index 00000000..62d8deda --- /dev/null +++ b/resources/assets/vue/components/settings/forms/BasePriceFormComponent.vue @@ -0,0 +1,80 @@ + + \ No newline at end of file diff --git a/resources/views/pages/settings.blade.php b/resources/views/pages/settings.blade.php index 7426821c..d254ac2b 100644 --- a/resources/views/pages/settings.blade.php +++ b/resources/views/pages/settings.blade.php @@ -47,6 +47,26 @@ +
+
+
+
+
+
+
+
+ +
+
+
Base Price
+
+
+
+
+
+
+
+
@@ -213,6 +233,43 @@
+
+
+ +
+
+
+
+
+ Base Price +
+
+
+ + + + +
+
+
+
+
+
+ Base Price :0.00
+ + + +
+
+
+
+
+
+
+
@@ -238,14 +295,6 @@
-
-
- Base Price :0.00
- - - -
-