diff --git a/app/Classes/Modules/SegmentConstants/ControllerLogic/CreateSegmentConstantLogic.php b/app/Classes/Modules/SegmentConstants/ControllerLogic/CreateSegmentConstantLogic.php new file mode 100644 index 00000000..7f27e3f3 --- /dev/null +++ b/app/Classes/Modules/SegmentConstants/ControllerLogic/CreateSegmentConstantLogic.php @@ -0,0 +1,187 @@ + 'Created Segment Constant', + 'message' => 'You have successfully created a new Segment Constant' + ]; + } + + /** @var CanCreateSegmentConstant */ + private $canCreateSegmentConstant; + + /** @var CreatesSegmentConstantTax */ + private $createsSegmentConstantTax; + + /** @var CreatesSegmentConstantBillingFee */ + private $createsSegmentConstantBillingFee; + + /** @var CreatesSegmentConstantServiceCharge */ + private $createsSegmentConstantServiceCharge; + + /** @var CreatesSegmentConstantBookingAmountMax */ + private $createsSegmentConstantBookingAmountMax; + + /** @var CreatesSegmentConstantPaymentAttemptExpiryTime */ + private $createsSegmentConstantPaymentAttemptExpiryTime; + + /** @var FetchesSegmentConstant */ + private $fetchesSegmentConstant; + + /** @var FetchesSegment */ + private $fetchesSegment; + + /** + * CreateSegmentConstantLogic constructor. + * @param CanCreateSegmentConstant $canCreateSegmentConstant + * @param CreatesSegmentConstantTax $createsSegmentConstantTax + * @param CreatesSegmentConstantBillingFee $createsSegmentConstantBillingFee + * @param CreatesSegmentConstantServiceCharge $createsSegmentConstantServiceCharge + * @param CreatesSegmentConstantBookingAmountMax $createsSegmentConstantBookingAmountMax + * @param CreatesSegmentConstantPaymentAttemptExpiryTime $createsSegmentConstantPaymentAttemptExpiryTime + * @param FetchesSegmentConstant $fetchesSegmentConstant + * @param FetchesSegment $fetchesSegment + */ + public function __construct( + CanCreateSegmentConstant $canCreateSegmentConstant, + CreatesSegmentConstantTax $createsSegmentConstantTax, + CreatesSegmentConstantBillingFee $createsSegmentConstantBillingFee, + CreatesSegmentConstantServiceCharge $createsSegmentConstantServiceCharge, + CreatesSegmentConstantBookingAmountMax $createsSegmentConstantBookingAmountMax, + CreatesSegmentConstantPaymentAttemptExpiryTime $createsSegmentConstantPaymentAttemptExpiryTime, + FetchesSegmentConstant $fetchesSegmentConstant, + FetchesSegment $fetchesSegment + ) + { + $this->canCreateSegmentConstant = $canCreateSegmentConstant; + $this->createsSegmentConstantTax = $createsSegmentConstantTax; + $this->createsSegmentConstantBillingFee = $createsSegmentConstantBillingFee; + $this->createsSegmentConstantServiceCharge = $createsSegmentConstantServiceCharge; + $this->createsSegmentConstantBookingAmountMax = $createsSegmentConstantBookingAmountMax; + $this->createsSegmentConstantPaymentAttemptExpiryTime = $createsSegmentConstantPaymentAttemptExpiryTime; + $this->fetchesSegmentConstant = $fetchesSegmentConstant; + $this->fetchesSegment = $fetchesSegment; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + try { + DB::beginTransaction(); + + $segment_query = $this->fetchesSegment->execute([ + 'id' => $request->input('segment_id'), + ]); + + $segment_constant_query = $this->fetchesSegmentConstant->execute([ + 'id' => $request->input('standard_segment_constant_id'), + ]); + + if ($segment_constant_query->reference == 'TAX') { + $segment_constant_object = new SegmentConstantTaxObject( + $request->input('segment_id'), + $segment_constant_query->name, + $segment_constant_query->reference, + $segment_constant_query->detail->type, + $request->input('value') + ); + + $this->canCreateSegmentConstant->passes($segment_constant_object); + $segment_constant_query = $this->createsSegmentConstantTax->execute($segment_query, $segment_constant_object); + } + elseif ($segment_constant_query->reference == 'BILLING_FEE') { + $segment_constant_object = new SegmentConstantBillingFeeObject( + $request->input('segment_id'), + $segment_constant_query->name, + $segment_constant_query->reference, + $segment_constant_query->detail->type, + $request->input('value') + ); + $this->canCreateSegmentConstant->passes($segment_constant_object); + $segment_constant_query = $this->createsSegmentConstantBillingFee->execute($segment_query, $segment_constant_object); + } + elseif ($segment_constant_query->reference == 'SERVICE_CHARGE') { + $segment_constant_object = new SegmentConstantServiceChargeObject( + $request->input('segment_id'), + $segment_constant_query->name, + $segment_constant_query->reference, + $segment_constant_query->detail->type, + $request->input('value') + ); + $this->canCreateSegmentConstant->passes($segment_constant_object); + $segment_constant_query = $this->createsSegmentConstantServiceCharge->execute($segment_query, $segment_constant_object); + } + elseif ($segment_constant_query->reference == 'BOOKING_AMOUNT_MAX') { + $segment_constant_object = new SegmentConstantBookingAmountMaxObject( + $request->input('segment_id'), + $segment_constant_query->name, + $segment_constant_query->reference, + $segment_constant_query->detail->type, + $request->input('value'), + $segment_constant_query->detail->currency_id + ); + $this->canCreateSegmentConstant->passes($segment_constant_object); + $segment_constant_query = $this->createsSegmentConstantBookingAmountMax->execute($segment_query, $segment_constant_object); + } + elseif ($segment_constant_query->reference == 'PAYMENT_ATTEMP_EXPIRY_TIME') { + $segment_constant_object = new SegmentConstantPaymentAttemptExpiryTimeObject( + $request->input('segment_id'), + $segment_constant_query->name, + $segment_constant_query->reference, + $segment_constant_query->detail->type, + $request->input('value') + ); + $this->canCreateSegmentConstant->passes($segment_constant_object); + $segment_constant_query = $this->createsSegmentConstantPaymentAttemptExpiryTime->execute($segment_query, $segment_constant_object); + } + + DB::commit(); + + return $this->resourceResponse(new SegmentConstantResource($segment_constant_query)); + + } catch (\Exception $exception) { + throw new ErrorException($exception->getMessage(), $exception->getCode()); + } + + } +} \ No newline at end of file diff --git a/app/Classes/Modules/SegmentConstants/ControllerLogic/UpdateSegmentConstantLogic.php b/app/Classes/Modules/SegmentConstants/ControllerLogic/UpdateSegmentConstantLogic.php new file mode 100644 index 00000000..c4ecf270 --- /dev/null +++ b/app/Classes/Modules/SegmentConstants/ControllerLogic/UpdateSegmentConstantLogic.php @@ -0,0 +1,175 @@ + 'Updated Segment Constant', + 'message' => 'You have successfully updated the Segment Constant' + ]; + } + + /** @var CanUpdateStandardSegmentConstant */ + private $canUpdateStandardSegmentConstant; + + /** @var UpdatesSegmentConstantTax */ + private $updatesSegmentConstantTax; + + /** @var UpdatesSegmentConstantBillingFee */ + private $updatesSegmentConstantBillingFee; + + /** @var UpdatesSegmentConstantServiceCharge */ + private $updatesSegmentConstantServiceCharge; + + /** @var UpdatesSegmentConstantBookingAmountMax */ + private $updatesSegmentConstantBookingAmountMax; + + /** @var UpdatesSegmentConstantPaymentAttemptExpiryTime */ + private $updatesSegmentConstantPaymentAttemptExpiryTime; + + /** @var FetchesSegmentConstant */ + private $fetchesSegmentConstant; + + /** + * UpdateStandardSegmentConstantLogic constructor. + * @param CanUpdateStandardSegmentConstant $canUpdateStandardSegmentConstant + * @param UpdatesSegmentConstantTax $updatesSegmentConstantTax + * @param UpdatesSegmentConstantBillingFee $updatesSegmentConstantBillingFee + * @param UpdatesSegmentConstantServiceCharge $updatesSegmentConstantServiceCharge + * @param UpdatesSegmentConstantBookingAmountMax $updatesSegmentConstantBookingAmountMax + * @param UpdatesSegmentConstantPaymentAttemptExpiryTime $updatesSegmentConstantPaymentAttemptExpiryTime + * @param FetchesSegmentConstant $fetchesSegmentConstant + */ + public function __construct( + CanUpdateStandardSegmentConstant $canUpdateStandardSegmentConstant, + UpdatesSegmentConstantTax $updatesSegmentConstantTax, + UpdatesSegmentConstantBillingFee $updatesSegmentConstantBillingFee, + UpdatesSegmentConstantServiceCharge $updatesSegmentConstantServiceCharge, + UpdatesSegmentConstantBookingAmountMax $updatesSegmentConstantBookingAmountMax, + UpdatesSegmentConstantPaymentAttemptExpiryTime $updatesSegmentConstantPaymentAttemptExpiryTime, + FetchesSegmentConstant $fetchesSegmentConstant + ) + { + $this->canUpdateStandardSegmentConstant = $canUpdateStandardSegmentConstant; + $this->updatesSegmentConstantTax = $updatesSegmentConstantTax; + $this->updatesSegmentConstantBillingFee = $updatesSegmentConstantBillingFee; + $this->updatesSegmentConstantServiceCharge = $updatesSegmentConstantServiceCharge; + $this->updatesSegmentConstantBookingAmountMax = $updatesSegmentConstantBookingAmountMax; + $this->updatesSegmentConstantPaymentAttemptExpiryTime = $updatesSegmentConstantPaymentAttemptExpiryTime; + $this->fetchesSegmentConstant = $fetchesSegmentConstant; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + try { + DB::beginTransaction(); + + $segment_constant_query = $this->fetchesSegmentConstant->execute(['id' => $request->route('id')]); + + if ($segment_constant_query->reference == 'TAX') { + $segment_constant_object = new SegmentConstantTaxObject( + $segment_constant_query->segment_id, + $segment_constant_query->name, + $segment_constant_query->reference, + $segment_constant_query->detail->type, + $request->input('value') + ); + + $this->canUpdateStandardSegmentConstant->passes($segment_constant_object); + $segment_constant_query = $this->updatesSegmentConstantTax->execute($segment_constant_query, $segment_constant_object); + } + elseif ($segment_constant_query->reference == 'BILLING_FEE') { + $segment_constant_object = new SegmentConstantBillingFeeObject( + $segment_constant_query->segment_id, + $segment_constant_query->name, + $segment_constant_query->reference, + $segment_constant_query->detail->type, + $request->input('value') + ); + $this->canUpdateStandardSegmentConstant->passes($segment_constant_object); + $segment_constant_query = $this->updatesSegmentConstantBillingFee->execute($segment_constant_query, $segment_constant_object); + } + elseif ($segment_constant_query->reference == 'SERVICE_CHARGE') { + $segment_constant_object = new SegmentConstantServiceChargeObject( + $segment_constant_query->segment_id, + $segment_constant_query->name, + $segment_constant_query->reference, + $segment_constant_query->detail->type, + $request->input('value') + ); + $this->canUpdateStandardSegmentConstant->passes($segment_constant_object); + $segment_constant_query = $this->updatesSegmentConstantServiceCharge->execute($segment_constant_query, $segment_constant_object); + } + elseif ($segment_constant_query->reference == 'BOOKING_AMOUNT_MAX') { + $segment_constant_object = new SegmentConstantBookingAmountMaxObject( + $segment_constant_query->segment_id, + $segment_constant_query->name, + $segment_constant_query->reference, + $segment_constant_query->detail->type, + $request->input('value'), + $segment_constant_query->detail->currency_id + ); + $this->canUpdateStandardSegmentConstant->passes($segment_constant_object); + $segment_constant_query = $this->updatesSegmentConstantBookingAmountMax->execute($segment_constant_query, $segment_constant_object); + } + elseif ($segment_constant_query->reference == 'PAYMENT_ATTEMP_EXPIRY_TIME') { + $segment_constant_object = new SegmentConstantPaymentAttemptExpiryTimeObject( + $segment_constant_query->segment_id, + $segment_constant_query->name, + $segment_constant_query->reference, + $segment_constant_query->detail->type, + $request->input('value') + ); + $this->canUpdateStandardSegmentConstant->passes($segment_constant_object); + $segment_constant_query = $this->updatesSegmentConstantPaymentAttemptExpiryTime->execute($segment_constant_query, $segment_constant_object); + } + + DB::commit(); + + return $this->resourceResponse(new SegmentConstantResource($segment_constant_query)); + + } catch (\Exception $exception){ + throw new ErrorException($exception->getMessage(), $exception->getCode()); + } + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/SegmentConstants/ControllerLogic/UpdateStandardSegmentConstantLogic.php b/app/Classes/Modules/SegmentConstants/ControllerLogic/UpdateStandardSegmentConstantLogic.php index 22874fa7..bdb42ff5 100644 --- a/app/Classes/Modules/SegmentConstants/ControllerLogic/UpdateStandardSegmentConstantLogic.php +++ b/app/Classes/Modules/SegmentConstants/ControllerLogic/UpdateStandardSegmentConstantLogic.php @@ -2,8 +2,6 @@ namespace App\Classes\Modules\SegmentConstants\ControllersLogic; -use App\Http\Resources\SegmentConstantResource; - use App\Classes\General\Abstracts\AbstractControllerLogic; use App\Classes\Modules\SegmentConstants\Services\FetchesSegmentConstant; @@ -25,6 +23,8 @@ use App\Classes\Modules\SegmentConstants\DataTransferObjects\SegmentConstantBook use App\Classes\Modules\SegmentConstants\Services\UpdatesSegmentConstantPaymentAttemptExpiryTime; use App\Classes\Modules\SegmentConstants\DataTransferObjects\SegmentConstantPaymentAttemptExpiryTimeObject; +use App\Http\Resources\SegmentConstantResource; + use ErrorException; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; @@ -107,6 +107,7 @@ class UpdateStandardSegmentConstantLogic extends AbstractControllerLogic if ($segment_constant_query->reference == 'TAX') { $segment_constant_object = new SegmentConstantTaxObject( + $segment_constant_query->segment_id, $segment_constant_query->name, $segment_constant_query->reference, $segment_constant_query->detail->type, @@ -118,6 +119,7 @@ class UpdateStandardSegmentConstantLogic extends AbstractControllerLogic } elseif ($segment_constant_query->reference == 'BILLING_FEE') { $segment_constant_object = new SegmentConstantBillingFeeObject( + $segment_constant_query->segment_id, $segment_constant_query->name, $segment_constant_query->reference, $segment_constant_query->detail->type, @@ -128,6 +130,7 @@ class UpdateStandardSegmentConstantLogic extends AbstractControllerLogic } elseif ($segment_constant_query->reference == 'SERVICE_CHARGE') { $segment_constant_object = new SegmentConstantServiceChargeObject( + $segment_constant_query->segment_id, $segment_constant_query->name, $segment_constant_query->reference, $segment_constant_query->detail->type, @@ -138,6 +141,7 @@ class UpdateStandardSegmentConstantLogic extends AbstractControllerLogic } elseif ($segment_constant_query->reference == 'BOOKING_AMOUNT_MAX') { $segment_constant_object = new SegmentConstantBookingAmountMaxObject( + $segment_constant_query->segment_id, $segment_constant_query->name, $segment_constant_query->reference, $segment_constant_query->detail->type, @@ -149,6 +153,7 @@ class UpdateStandardSegmentConstantLogic extends AbstractControllerLogic } elseif ($segment_constant_query->reference == 'PAYMENT_ATTEMP_EXPIRY_TIME') { $segment_constant_object = new SegmentConstantPaymentAttemptExpiryTimeObject( + $segment_constant_query->segment_id, $segment_constant_query->name, $segment_constant_query->reference, $segment_constant_query->detail->type, diff --git a/app/Classes/Modules/SegmentConstants/DataTransferObjects/SegmentConstantBillingFeeObject.php b/app/Classes/Modules/SegmentConstants/DataTransferObjects/SegmentConstantBillingFeeObject.php index 27b6b676..2cac6d93 100644 --- a/app/Classes/Modules/SegmentConstants/DataTransferObjects/SegmentConstantBillingFeeObject.php +++ b/app/Classes/Modules/SegmentConstants/DataTransferObjects/SegmentConstantBillingFeeObject.php @@ -6,6 +6,9 @@ use App\Classes\Interfaces\DataTransferObject; class SegmentConstantBillingFeeObject implements DataTransferObject { + /** @var int|null */ + private $segment_id; + /** @var string|null */ private $name; @@ -20,24 +23,35 @@ class SegmentConstantBillingFeeObject implements DataTransferObject /** * SegmentConstantObject constructor. + * @param string|null $segment_id * @param string|null $name * @param string|null $reference * @param string|null $type * @param int|null $value */ public function __construct( + ?int $segment_id, ?string $name, ?string $reference, ?string $type, ?int $value ) { + $this->segment_id = $segment_id; $this->name = $name; $this->reference = $reference; $this->type = $type; $this->value = $value; } + /** + * @return int + */ + public function getSegmentId(): ?int + { + return $this->segment_id; + } + /** * @return string */ diff --git a/app/Classes/Modules/SegmentConstants/DataTransferObjects/SegmentConstantBookingAmountMaxObject.php b/app/Classes/Modules/SegmentConstants/DataTransferObjects/SegmentConstantBookingAmountMaxObject.php index 3575af1f..709cdb18 100644 --- a/app/Classes/Modules/SegmentConstants/DataTransferObjects/SegmentConstantBookingAmountMaxObject.php +++ b/app/Classes/Modules/SegmentConstants/DataTransferObjects/SegmentConstantBookingAmountMaxObject.php @@ -6,6 +6,9 @@ use App\Classes\Interfaces\DataTransferObject; class SegmentConstantBookingAmountMaxObject implements DataTransferObject { + /** @var int|null */ + private $segment_id; + /** @var string|null */ private $name; @@ -23,6 +26,7 @@ class SegmentConstantBookingAmountMaxObject implements DataTransferObject /** * SegmentConstantObject constructor. + * @param string|null $segment_id * @param string|null $name * @param string|null $reference * @param string|null $type @@ -30,6 +34,7 @@ class SegmentConstantBookingAmountMaxObject implements DataTransferObject * @param int|null $currency_id */ public function __construct( + ?int $segment_id, ?string $name, ?string $reference, ?string $type, @@ -37,6 +42,7 @@ class SegmentConstantBookingAmountMaxObject implements DataTransferObject ?int $currency_id ) { + $this->segment_id = $segment_id; $this->name = $name; $this->reference = $reference; $this->type = $type; @@ -44,6 +50,14 @@ class SegmentConstantBookingAmountMaxObject implements DataTransferObject $this->currency_id = $currency_id; } + /** + * @return int + */ + public function getSegmentId(): ?int + { + return $this->segment_id; + } + /** * @return string */ diff --git a/app/Classes/Modules/SegmentConstants/DataTransferObjects/SegmentConstantPaymentAttemptExpiryTimeObject.php b/app/Classes/Modules/SegmentConstants/DataTransferObjects/SegmentConstantPaymentAttemptExpiryTimeObject.php index 758835d5..7b97584f 100644 --- a/app/Classes/Modules/SegmentConstants/DataTransferObjects/SegmentConstantPaymentAttemptExpiryTimeObject.php +++ b/app/Classes/Modules/SegmentConstants/DataTransferObjects/SegmentConstantPaymentAttemptExpiryTimeObject.php @@ -6,6 +6,9 @@ use App\Classes\Interfaces\DataTransferObject; class SegmentConstantPaymentAttemptExpiryTimeObject implements DataTransferObject { + /** @var int|null */ + private $segment_id; + /** @var string|null */ private $name; @@ -20,24 +23,35 @@ class SegmentConstantPaymentAttemptExpiryTimeObject implements DataTransferObjec /** * SegmentConstantObject constructor. + * @param string|null $segment_id * @param string|null $name * @param string|null $reference * @param string|null $type * @param int|null $value */ public function __construct( + ?int $segment_id, ?string $name, ?string $reference, ?string $type, ?int $value ) { + $this->segment_id = $segment_id; $this->name = $name; $this->reference = $reference; $this->type = $type; $this->value = $value; } + /** + * @return int + */ + public function getSegmentId(): ?int + { + return $this->segment_id; + } + /** * @return string */ diff --git a/app/Classes/Modules/SegmentConstants/DataTransferObjects/SegmentConstantServiceChargeObject.php b/app/Classes/Modules/SegmentConstants/DataTransferObjects/SegmentConstantServiceChargeObject.php index 67d6e284..4f3adfa1 100644 --- a/app/Classes/Modules/SegmentConstants/DataTransferObjects/SegmentConstantServiceChargeObject.php +++ b/app/Classes/Modules/SegmentConstants/DataTransferObjects/SegmentConstantServiceChargeObject.php @@ -6,6 +6,9 @@ use App\Classes\Interfaces\DataTransferObject; class SegmentConstantServiceChargeObject implements DataTransferObject { + /** @var int|null */ + private $segment_id; + /** @var string|null */ private $name; @@ -20,24 +23,35 @@ class SegmentConstantServiceChargeObject implements DataTransferObject /** * SegmentConstantObject constructor. + * @param string|null $segment_id * @param string|null $name * @param string|null $reference * @param string|null $type * @param int|null $value */ public function __construct( + ?int $segment_id, ?string $name, ?string $reference, ?string $type, ?int $value ) { + $this->segment_id = $segment_id; $this->name = $name; $this->reference = $reference; $this->type = $type; $this->value = $value; } + /** + * @return int + */ + public function getSegmentId(): ?int + { + return $this->segment_id; + } + /** * @return string */ diff --git a/app/Classes/Modules/SegmentConstants/DataTransferObjects/SegmentConstantTaxObject.php b/app/Classes/Modules/SegmentConstants/DataTransferObjects/SegmentConstantTaxObject.php index d07eb19b..b7125cd1 100644 --- a/app/Classes/Modules/SegmentConstants/DataTransferObjects/SegmentConstantTaxObject.php +++ b/app/Classes/Modules/SegmentConstants/DataTransferObjects/SegmentConstantTaxObject.php @@ -6,6 +6,9 @@ use App\Classes\Interfaces\DataTransferObject; class SegmentConstantTaxObject implements DataTransferObject { + /** @var int|null */ + private $segment_id; + /** @var string|null */ private $name; @@ -20,24 +23,35 @@ class SegmentConstantTaxObject implements DataTransferObject /** * SegmentConstantObject constructor. + * @param string|null $segment_id * @param string|null $name * @param string|null $reference * @param string|null $type * @param int|null $value */ public function __construct( + ?int $segment_id, ?string $name, ?string $reference, ?string $type, ?int $value ) { + $this->segment_id = $segment_id; $this->name = $name; $this->reference = $reference; $this->type = $type; $this->value = $value; } + /** + * @return int + */ + public function getSegmentId(): ?int + { + return $this->segment_id; + } + /** * @return string */ diff --git a/app/Classes/Modules/SegmentConstants/Services/CreatesSegmentConstantBillingFee.php b/app/Classes/Modules/SegmentConstants/Services/CreatesSegmentConstantBillingFee.php new file mode 100644 index 00000000..55133247 --- /dev/null +++ b/app/Classes/Modules/SegmentConstants/Services/CreatesSegmentConstantBillingFee.php @@ -0,0 +1,30 @@ +segment_id = $segment->id; + $model->name = $object->getName(); + $model->reference = $object->getReference(); + $model->detail = json_encode([ + 'type' => $object->getType(), + 'value' => $object->getValue() + ]); + + return $this->handler($model); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/SegmentConstants/Services/CreatesSegmentConstantBookingAmountMax.php b/app/Classes/Modules/SegmentConstants/Services/CreatesSegmentConstantBookingAmountMax.php new file mode 100644 index 00000000..61971f50 --- /dev/null +++ b/app/Classes/Modules/SegmentConstants/Services/CreatesSegmentConstantBookingAmountMax.php @@ -0,0 +1,31 @@ +segment_id = $segment->id; + $model->name = $object->getName(); + $model->reference = $object->getReference(); + $model->detail = json_encode([ + 'type' => $object->getType(), + 'value' => $object->getValue(), + 'currency_id' => $object->getCurrencyId() + ]); + + return $this->handler($model); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/SegmentConstants/Services/CreatesSegmentConstantPaymentAttemptExpiryTime.php b/app/Classes/Modules/SegmentConstants/Services/CreatesSegmentConstantPaymentAttemptExpiryTime.php new file mode 100644 index 00000000..ae6077b8 --- /dev/null +++ b/app/Classes/Modules/SegmentConstants/Services/CreatesSegmentConstantPaymentAttemptExpiryTime.php @@ -0,0 +1,30 @@ +segment_id = $object->getSegmentId(); + $model->name = $object->getName(); + $model->reference = $object->getReference(); + $model->detail = json_encode([ + 'type' => $object->getType(), + 'value' => $object->getValue(), + ]); + + return $this->handler($model); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/SegmentConstants/Services/CreatesSegmentConstantServiceCharge.php b/app/Classes/Modules/SegmentConstants/Services/CreatesSegmentConstantServiceCharge.php new file mode 100644 index 00000000..695b7df9 --- /dev/null +++ b/app/Classes/Modules/SegmentConstants/Services/CreatesSegmentConstantServiceCharge.php @@ -0,0 +1,30 @@ +segment_id = $object->getSegmentId(); + $model->name = $object->getName(); + $model->reference = $object->getReference(); + $model->detail = json_encode([ + 'type' => $object->getType(), + 'value' => $object->getValue() + ]); + + return $this->handler($model); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/SegmentConstants/Services/CreatesSegmentConstantTax.php b/app/Classes/Modules/SegmentConstants/Services/CreatesSegmentConstantTax.php new file mode 100644 index 00000000..64b2e7a5 --- /dev/null +++ b/app/Classes/Modules/SegmentConstants/Services/CreatesSegmentConstantTax.php @@ -0,0 +1,30 @@ +segment_id = $object->getSegmentId(); + $model->name = $object->getName(); + $model->reference = $object->getReference(); + $model->detail = json_encode([ + 'type' => $object->getType(), + 'value' => $object->getValue() + ]); + + return $this->handler($model); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/SegmentConstants/Standards/Rules/CanCreateSegmentConstant.php b/app/Classes/Modules/SegmentConstants/Standards/Rules/CanCreateSegmentConstant.php new file mode 100644 index 00000000..f8004575 --- /dev/null +++ b/app/Classes/Modules/SegmentConstants/Standards/Rules/CanCreateSegmentConstant.php @@ -0,0 +1,55 @@ +segmentConstantValidation = $segmentConstantValidation; + } + + /** + * @return bool + */ + protected function authorized(): bool + { + // TODO Set Authorization rules + if (!\Auth::user()->can('add segment_constant')) { + return false; + } + + return true; + } + + /** + * @param SegmentObject $object + * @return bool + * @throws \App\Classes\Exceptions\RequestValidationException + */ + protected function validators($object): bool + { + return $this->segmentConstantValidation->validate($object, 'POST'); + } + + /** + * @param SegmentObject $object + * @return bool + */ + protected function criteria($object): bool + { + return true; + } +} \ No newline at end of file diff --git a/app/Classes/Modules/SegmentConstants/Standards/Rules/CanUpdateStandardSegmentConstant.php b/app/Classes/Modules/SegmentConstants/Standards/Rules/CanUpdateStandardSegmentConstant.php index fb4f39a3..daee97ba 100644 --- a/app/Classes/Modules/SegmentConstants/Standards/Rules/CanUpdateStandardSegmentConstant.php +++ b/app/Classes/Modules/SegmentConstants/Standards/Rules/CanUpdateStandardSegmentConstant.php @@ -43,7 +43,7 @@ class CanUpdateStandardSegmentConstant extends AbstractRule */ protected function validators($object): bool { - return $this->segmentConstantValidation->validate($object); + return $this->segmentConstantValidation->validate($object, 'PUT'); } /** diff --git a/app/Classes/Modules/SegmentConstants/Standards/Validators/SegmentConstantValidation.php b/app/Classes/Modules/SegmentConstants/Standards/Validators/SegmentConstantValidation.php index d382d343..9a09a074 100644 --- a/app/Classes/Modules/SegmentConstants/Standards/Validators/SegmentConstantValidation.php +++ b/app/Classes/Modules/SegmentConstants/Standards/Validators/SegmentConstantValidation.php @@ -17,6 +17,7 @@ class SegmentConstantValidation extends AbstractValidation $this->reference = $object->getReference(); if ($this->reference == 'TAX') { return [ + 'segment_id'=> $object->getSegmentId(), 'name' => $object->getName(), 'reference' => $object->getReference(), 'type' => $object->getType(), @@ -25,6 +26,7 @@ class SegmentConstantValidation extends AbstractValidation } elseif ($this->reference == 'BILLING_FEE') { return [ + 'segment_id' => $object->getSegmentId(), 'name' => $object->getName(), 'reference' => $object->getReference(), 'type' => $object->getType(), @@ -33,6 +35,7 @@ class SegmentConstantValidation extends AbstractValidation } elseif ($this->reference == 'SERVICE_CHARGE') { return [ + 'segment_id' => $object->getSegmentId(), 'name' => $object->getName(), 'reference' => $object->getReference(), 'type' => $object->getType(), @@ -41,6 +44,7 @@ class SegmentConstantValidation extends AbstractValidation } elseif ($this->reference == 'BOOKING_AMOUNT_MAX') { return [ + 'segment_id' => $object->getSegmentId(), 'name' => $object->getName(), 'reference' => $object->getReference(), 'type' => $object->getType(), @@ -50,6 +54,7 @@ class SegmentConstantValidation extends AbstractValidation } elseif ($this->reference == 'PAYMENT_ATTEMP_EXPIRY_TIME') { return [ + 'segment_id' => $object->getSegmentId(), 'name' => $object->getName(), 'reference' => $object->getReference(), 'type' => $object->getType(), @@ -61,10 +66,11 @@ class SegmentConstantValidation extends AbstractValidation /** * @return array */ - protected function rules(): array { + protected function rules(?string $type = 'POST'): array { if ($this->reference == 'TAX') { return [ + 'segment_id' => $type == 'POST' ? 'required' : '', 'name' => 'required', 'reference' => 'required', 'type' => 'required', @@ -73,6 +79,7 @@ class SegmentConstantValidation extends AbstractValidation } elseif ($this->reference == 'BILLING_FEE') { return [ + 'segment_id' => $type == 'POST' ? 'required' : '', 'name' => 'required', 'reference' => 'required', 'type' => 'required', @@ -81,6 +88,7 @@ class SegmentConstantValidation extends AbstractValidation } elseif ($this->reference == 'SERVICE_CHARGE') { return [ + 'segment_id' => $type == 'POST' ? 'required' : '', 'name' => 'required', 'reference' => 'required', 'type' => 'required', @@ -89,6 +97,7 @@ class SegmentConstantValidation extends AbstractValidation } elseif ($this->reference == 'BOOKING_AMOUNT_MAX') { return [ + 'segment_id' => $type == 'POST' ? 'required' : '', 'name' => 'required', 'reference' => 'required', 'type' => 'required', @@ -98,6 +107,7 @@ class SegmentConstantValidation extends AbstractValidation } elseif ($this->reference == 'PAYMENT_ATTEMP_EXPIRY_TIME') { return [ + 'segment_id' => $type == 'POST' ? 'required' : '', 'name' => 'required', 'reference' => 'required', 'type' => 'required', diff --git a/app/Classes/Modules/Segments/ControllerLogic/CreateSegmentLogic.php b/app/Classes/Modules/Segments/ControllerLogic/CreateSegmentLogic.php new file mode 100644 index 00000000..557117c6 --- /dev/null +++ b/app/Classes/Modules/Segments/ControllerLogic/CreateSegmentLogic.php @@ -0,0 +1,75 @@ + 'Created Segment', + 'message' => 'You have successfully created a new Segment' + ]; + } + + /** @var CanCreateSegment */ + private $canCreateSegment; + + /** @var CreatesSegment */ + private $createsSegment; + + /** + * CreateSegmentLogic constructor. + * @param CanCreateSegment $canCreateSegment + * @param CreatesSegment $createsSegment + */ + public function __construct( + CanCreateSegment $canCreateSegment, + CreatesSegment $createsSegment + ) + { + $this->canCreateSegment = $canCreateSegment; + $this->createsSegment = $createsSegment; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + try { + DB::beginTransaction(); + + $segment_object = new SegmentObject( + $request->input('name') + ); + + $this->canCreateSegment->passes($segment_object); + $segment_query = $this->createsSegment->execute($segment_object); + + DB::commit(); + + return $this->resourceResponse(new SegmentResource($segment_query)); + + } catch (\Exception $exception) { + throw new ErrorException($exception->getMessage(), $exception->getCode()); + } + + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Segments/ControllerLogic/DeleteSegmentLogic.php b/app/Classes/Modules/Segments/ControllerLogic/DeleteSegmentLogic.php new file mode 100644 index 00000000..24284c29 --- /dev/null +++ b/app/Classes/Modules/Segments/ControllerLogic/DeleteSegmentLogic.php @@ -0,0 +1,83 @@ + 'Delete Segment', + 'message' => 'You have successfully deleted the Segment' + ]; + } + + /** @var CanDeleteSegment */ + private $canDeleteSegment; + + /** @var DeletesSegment */ + private $deletesSegment; + + /** @var FetchesSegment */ + private $fetchesSegment; + + /** + * UpdateStandardSegmentConstantLogic constructor. + * @param CanUpdateSegment $canDeleteSegment + * @param UpdatesSegment $deletesSegment + * @param FetchesSegment $fetchesSegment + */ + public function __construct( + CanDeleteSegment $canDeleteSegment, + DeletesSegment $deletesSegment, + FetchesSegment $fetchesSegment + ) + { + $this->canDeleteSegment = $canDeleteSegment; + $this->deletesSegment = $deletesSegment; + $this->fetchesSegment = $fetchesSegment; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + try { + DB::beginTransaction(); + + $segment_query = $this->fetchesSegment->execute(['id' => $request->route('id')]); + $this->canDeleteSegment->passes(); + $this->deletesSegment->execute($segment_query); + + DB::commit(); + + return $this->resourceResponse(new SegmentResource($segment_query)); + + } catch (\Exception $exception){ + dd($exception); + throw new ErrorException($exception->getMessage(), $exception->getCode()); + } + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Segments/ControllerLogic/UpdateSegmentLogic.php b/app/Classes/Modules/Segments/ControllerLogic/UpdateSegmentLogic.php new file mode 100644 index 00000000..8ce9038d --- /dev/null +++ b/app/Classes/Modules/Segments/ControllerLogic/UpdateSegmentLogic.php @@ -0,0 +1,86 @@ + 'Updated Segment', + 'message' => 'You have successfully updated the Segment' + ]; + } + + /** @var CanUpdateSegment */ + private $canUpdateSegment; + + /** @var UpdatesSegment */ + private $updatesSegment; + + /** @var FetchesSegment */ + private $fetchesSegment; + + /** + * UpdateStandardSegmentConstantLogic constructor. + * @param CanUpdateSegment $canUpdateSegment + * @param UpdatesSegment $updatesSegment + * @param FetchesSegment $fetchesSegment + */ + public function __construct( + CanUpdateSegment $canUpdateSegment, + UpdatesSegment $updatesSegment, + FetchesSegment $fetchesSegment + ) + { + $this->canUpdateSegment = $canUpdateSegment; + $this->updatesSegment = $updatesSegment; + $this->fetchesSegment = $fetchesSegment; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + try { + DB::beginTransaction(); + + $segment_query = $this->fetchesSegment->execute(['id' => $request->route('id')]); + + $segment_object = new SegmentObject( + $request->input('name', $segment_query->name) + ); + $this->canUpdateSegment->passes($segment_object); + $segment_query = $this->updatesSegment->execute($segment_query, $segment_object); + + DB::commit(); + + return $this->resourceResponse(new SegmentResource($segment_query)); + + } catch (\Exception $exception){ + throw new ErrorException($exception->getMessage(), $exception->getCode()); + } + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Segments/DataTransferObjects/SegmentObject.php b/app/Classes/Modules/Segments/DataTransferObjects/SegmentObject.php new file mode 100644 index 00000000..dc4de3ed --- /dev/null +++ b/app/Classes/Modules/Segments/DataTransferObjects/SegmentObject.php @@ -0,0 +1,30 @@ +name = $name; + } + + /** + * @return string + */ + public function getName(): ?string + { + return $this->name; + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Segments/Services/CreatesSegment.php b/app/Classes/Modules/Segments/Services/CreatesSegment.php new file mode 100644 index 00000000..f3dc2a1c --- /dev/null +++ b/app/Classes/Modules/Segments/Services/CreatesSegment.php @@ -0,0 +1,23 @@ +name = $object->getName(); + + return $this->handler($model); + + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Segments/Services/DeletesSegment.php b/app/Classes/Modules/Segments/Services/DeletesSegment.php new file mode 100644 index 00000000..88d44d60 --- /dev/null +++ b/app/Classes/Modules/Segments/Services/DeletesSegment.php @@ -0,0 +1,14 @@ +handler($model); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Segments/Services/FetchesSegment.php b/app/Classes/Modules/Segments/Services/FetchesSegment.php new file mode 100644 index 00000000..25e5dbbe --- /dev/null +++ b/app/Classes/Modules/Segments/Services/FetchesSegment.php @@ -0,0 +1,33 @@ +repository = $repository; + } + + + /** + * @return Builder + */ + public function getRepository(): Builder + { + return $this->repository->newQuery(); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Segments/Services/UpdatesSegment.php b/app/Classes/Modules/Segments/Services/UpdatesSegment.php new file mode 100644 index 00000000..fed1fb2d --- /dev/null +++ b/app/Classes/Modules/Segments/Services/UpdatesSegment.php @@ -0,0 +1,22 @@ +name = $object->getName(); + return $this->handler($model); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Segments/Standards/Rules/CanCreateSegment.php b/app/Classes/Modules/Segments/Standards/Rules/CanCreateSegment.php new file mode 100644 index 00000000..50f7e81d --- /dev/null +++ b/app/Classes/Modules/Segments/Standards/Rules/CanCreateSegment.php @@ -0,0 +1,55 @@ +segmentValidation = $segmentValidation; + } + + /** + * @return bool + */ + protected function authorized(): bool + { + // TODO Set Authorization rules + if (!\Auth::user()->can('add segment')) { + return false; + } + + return true; + } + + /** + * @param SegmentObject $object + * @return bool + * @throws \App\Classes\Exceptions\RequestValidationException + */ + protected function validators($object): bool + { + return $this->segmentValidation->validate($object); + } + + /** + * @param SegmentObject $object + * @return bool + */ + protected function criteria($object): bool + { + return true; + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Segments/Standards/Rules/CanDeleteSegments.php b/app/Classes/Modules/Segments/Standards/Rules/CanDeleteSegments.php new file mode 100644 index 00000000..197b0a5f --- /dev/null +++ b/app/Classes/Modules/Segments/Standards/Rules/CanDeleteSegments.php @@ -0,0 +1,45 @@ +can('delete segment')) { + return false; + } + + return true; + + } + + /** + * @param SegmentObject $object + * @return bool + */ + protected function validators($object): bool + { + return true; + + } + + + /** + * @param SegmentObject $object + * @return bool + */ + protected function criteria($object): bool + { + return true; + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Segments/Standards/Rules/CanUpdateSegment.php b/app/Classes/Modules/Segments/Standards/Rules/CanUpdateSegment.php new file mode 100644 index 00000000..ed01004a --- /dev/null +++ b/app/Classes/Modules/Segments/Standards/Rules/CanUpdateSegment.php @@ -0,0 +1,58 @@ +segmentValidation = $segmentValidation; + } + + /** + * @return bool + */ + protected function authorized(): bool + { + // TODO Set Authorization rules + + if (!\Auth::user()->can('edit segment')) { + return false; + } + + return true; + } + + /** + * @param SegmentValidation $object + * @return bool + * @throws \App\Classes\Exceptions\RequestValidationException + */ + protected function validators($object): bool + { + return $this->segmentValidation->validate($object); + } + + /** + * @param SegmentValidation $object + * @return bool + */ + protected function criteria($object): bool + { + return true; + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Segments/Standards/Validators/SegmentValidation.php b/app/Classes/Modules/Segments/Standards/Validators/SegmentValidation.php new file mode 100644 index 00000000..364a4c88 --- /dev/null +++ b/app/Classes/Modules/Segments/Standards/Validators/SegmentValidation.php @@ -0,0 +1,38 @@ + $object->getName(), + ]; + } + + /** + * @return array + */ + protected function rules(): array + { + return [ + 'name' => 'required', + ]; + } + + /** + * @return array + */ + protected function messages(): array + { + return []; + } +} \ No newline at end of file diff --git a/app/Http/Controllers/SegmentConstants/CreateSegmentConstantController.php b/app/Http/Controllers/SegmentConstants/CreateSegmentConstantController.php new file mode 100644 index 00000000..7520e1d1 --- /dev/null +++ b/app/Http/Controllers/SegmentConstants/CreateSegmentConstantController.php @@ -0,0 +1,19 @@ +execute($request); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/SegmentConstants/UpdateSegmentConstantController.php b/app/Http/Controllers/SegmentConstants/UpdateSegmentConstantController.php new file mode 100644 index 00000000..c34914dc --- /dev/null +++ b/app/Http/Controllers/SegmentConstants/UpdateSegmentConstantController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/Segments/CreateSegmentController.php b/app/Http/Controllers/Segments/CreateSegmentController.php new file mode 100644 index 00000000..2950bdc3 --- /dev/null +++ b/app/Http/Controllers/Segments/CreateSegmentController.php @@ -0,0 +1,19 @@ +execute($request); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Segments/DeleteSegmentController.php b/app/Http/Controllers/Segments/DeleteSegmentController.php new file mode 100644 index 00000000..adf0043b --- /dev/null +++ b/app/Http/Controllers/Segments/DeleteSegmentController.php @@ -0,0 +1,19 @@ +execute($request); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Segments/UpdateSegmentController.php b/app/Http/Controllers/Segments/UpdateSegmentController.php new file mode 100644 index 00000000..51dfe25e --- /dev/null +++ b/app/Http/Controllers/Segments/UpdateSegmentController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/database/seeds/AdminUserPermissionsTableSeeder.php b/database/seeds/AdminUserPermissionsTableSeeder.php index ad723699..75a0edb8 100644 --- a/database/seeds/AdminUserPermissionsTableSeeder.php +++ b/database/seeds/AdminUserPermissionsTableSeeder.php @@ -29,15 +29,15 @@ class AdminUserPermissionsTableSeeder extends Seeder Permission::create(['name' => 'edit standard_segment_constant', 'guard_name' => 'web']); Permission::create(['name' => 'delete standard_segment_constant', 'guard_name' => 'web']); - Permission::create(['name' => 'view non_segment', 'guard_name' => 'web']); - Permission::create(['name' => 'add non_segment', 'guard_name' => 'web']); - Permission::create(['name' => 'edit non_segment', 'guard_name' => 'web']); - Permission::create(['name' => 'delete non_segment', 'guard_name' => 'web']); + Permission::create(['name' => 'view segment', 'guard_name' => 'web']); + Permission::create(['name' => 'add segment', 'guard_name' => 'web']); + Permission::create(['name' => 'edit segment', 'guard_name' => 'web']); + Permission::create(['name' => 'delete segment', 'guard_name' => 'web']); - Permission::create(['name' => 'view non_segment_constant', 'guard_name' => 'web']); - Permission::create(['name' => 'add non_segment_constant', 'guard_name' => 'web']); - Permission::create(['name' => 'edit non_segment_constant', 'guard_name' => 'web']); - Permission::create(['name' => 'delete non_segment_constant', 'guard_name' => 'web']); + Permission::create(['name' => 'view segment_constant', 'guard_name' => 'web']); + Permission::create(['name' => 'add segment_constant', 'guard_name' => 'web']); + Permission::create(['name' => 'edit segment_constant', 'guard_name' => 'web']); + Permission::create(['name' => 'delete segment_constant', 'guard_name' => 'web']); /////////////////////////////////////////////////////////////////////// diff --git a/routes/segment.php b/routes/segment.php index 6038c6e8..4ca1f3fb 100644 --- a/routes/segment.php +++ b/routes/segment.php @@ -3,11 +3,19 @@ use Illuminate\Support\Facades\Route; Route::group(['namespace' => 'StandardSegments'], function () { - Route::group(['middleware' => 'valid.token'], function () { Route::group(['prefix' => 'standard-segment'], function () { Route::get('/list', 'ListStandardSegmentsController@list')->name('standard_segment.update'); - Route::put('/update/{id}', 'StandardSegmentController@update')->name('standard_segment.update'); }); }); +}); + +Route::group(['namespace' => 'Segments'], function () { + Route::group(['middleware' => 'valid.token'], function () { + Route::group(['prefix' => 'segment'], function () { + Route::post('/create', 'CreateSegmentController@create')->name('segment.create'); + Route::put('/update/{id}', 'UpdateSegmentController@update')->name('segment.update'); + Route::delete('/delete/{id}', 'DeleteSegmentController@delete')->name('segment.delete'); + }); + }); }); \ No newline at end of file diff --git a/routes/segment_constant.php b/routes/segment_constant.php index fe2ff141..7f61aaa4 100644 --- a/routes/segment_constant.php +++ b/routes/segment_constant.php @@ -3,11 +3,21 @@ use Illuminate\Support\Facades\Route; Route::group(['namespace' => 'StandardSegmentConstants'], function () { - Route::group(['middleware' => 'valid.token'], function () { Route::group(['prefix' => 'standard-segment-constant'], function () { Route::get('/list', 'ListStandardSegmentConstantsController@list')->name('standard_segment.update'); Route::put('/update/{id}', 'UpdateStandardSegmentConstantController@update')->name('standard_segment_constant.update'); }); }); +}); + + +Route::group(['namespace' => 'SegmentConstants'], function () { + Route::group(['middleware' => 'valid.token'], function () { + Route::group(['prefix' => 'segment-constant'], function () { + // Route::get('/list', 'ListStandardSegmentConstantsController@list')->name('standard_segment.update'); + Route::post('/create', 'CreateSegmentConstantController@create')->name('segment_constant.create'); + Route::put('/update/{id}', 'UpdateSegmentConstantController@update')->name('segment_constant.update'); + }); + }); }); \ No newline at end of file