mirror of
https://gitlab.com/uldvstar/exchange-2.0.git
synced 2026-08-19 04:24:16 +00:00
-Update Non Standard Segment Logic Class
-Update Non Segment Constant Service Class -Create Non Standard Segment Constant Logic Class -Update Non Standard Segment Constant Logic Class -Delete Non Standard Segment Logic Class
This commit is contained in:
@@ -0,0 +1,187 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\SegmentConstants\ControllersLogic;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
|
||||
use App\Classes\Modules\SegmentConstants\Services\FetchesSegmentConstant;
|
||||
use App\Classes\Modules\Segments\Services\FetchesSegment;
|
||||
|
||||
use App\Classes\Modules\SegmentConstants\Standards\Rules\CanCreateSegmentConstant;
|
||||
|
||||
use App\Classes\Modules\SegmentConstants\Services\CreatesSegmentConstantTax;
|
||||
use App\Classes\Modules\SegmentConstants\DataTransferObjects\SegmentConstantTaxObject;
|
||||
|
||||
use App\Classes\Modules\SegmentConstants\Services\CreatesSegmentConstantBillingFee;
|
||||
use App\Classes\Modules\SegmentConstants\DataTransferObjects\SegmentConstantBillingFeeObject;
|
||||
|
||||
use App\Classes\Modules\SegmentConstants\Services\CreatesSegmentConstantServiceCharge;
|
||||
use App\Classes\Modules\SegmentConstants\DataTransferObjects\SegmentConstantServiceChargeObject;
|
||||
|
||||
use App\Classes\Modules\SegmentConstants\Services\CreatesSegmentConstantBookingAmountMax;
|
||||
use App\Classes\Modules\SegmentConstants\DataTransferObjects\SegmentConstantBookingAmountMaxObject;
|
||||
|
||||
use App\Classes\Modules\SegmentConstants\Services\CreatesSegmentConstantPaymentAttemptExpiryTime;
|
||||
use App\Classes\Modules\SegmentConstants\DataTransferObjects\SegmentConstantPaymentAttemptExpiryTimeObject;
|
||||
|
||||
use App\Http\Resources\SegmentConstantResource;
|
||||
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class CreateSegmentConstantLogic extends AbstractControllerLogic
|
||||
{
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => '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());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,175 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\SegmentConstants\ControllersLogic;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
|
||||
use App\Classes\Modules\SegmentConstants\Services\FetchesSegmentConstant;
|
||||
|
||||
use App\Classes\Modules\SegmentConstants\Standards\Rules\CanUpdateStandardSegmentConstant;
|
||||
|
||||
use App\Classes\Modules\SegmentConstants\Services\UpdatesSegmentConstantTax;
|
||||
use App\Classes\Modules\SegmentConstants\DataTransferObjects\SegmentConstantTaxObject;
|
||||
|
||||
use App\Classes\Modules\SegmentConstants\Services\UpdatesSegmentConstantBillingFee;
|
||||
use App\Classes\Modules\SegmentConstants\DataTransferObjects\SegmentConstantBillingFeeObject;
|
||||
|
||||
use App\Classes\Modules\SegmentConstants\Services\UpdatesSegmentConstantServiceCharge;
|
||||
use App\Classes\Modules\SegmentConstants\DataTransferObjects\SegmentConstantServiceChargeObject;
|
||||
|
||||
use App\Classes\Modules\SegmentConstants\Services\UpdatesSegmentConstantBookingAmountMax;
|
||||
use App\Classes\Modules\SegmentConstants\DataTransferObjects\SegmentConstantBookingAmountMaxObject;
|
||||
|
||||
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;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class UpdateSegmentConstantLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => '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());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+7
-2
@@ -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,
|
||||
|
||||
+14
@@ -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
|
||||
*/
|
||||
|
||||
+14
@@ -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
|
||||
*/
|
||||
|
||||
+14
@@ -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
|
||||
*/
|
||||
|
||||
+14
@@ -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
|
||||
*/
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\SegmentConstants\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Classes\Modules\SegmentConstants\DataTransferObjects\SegmentConstantBillingFeeObject;
|
||||
use App\Models\SegmentConstant;
|
||||
use App\Models\Segment;
|
||||
|
||||
class CreatesSegmentConstantBillingFee extends AbstractUpdateRecord
|
||||
{
|
||||
/**
|
||||
* @param SegmentConstantBillingFeeObject $object
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(Segment $segment, SegmentConstantBillingFeeObject $object)
|
||||
{
|
||||
$model = new SegmentConstant();
|
||||
$model->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);
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\SegmentConstants\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Classes\Modules\SegmentConstants\DataTransferObjects\SegmentConstantBookingAmountMaxObject;
|
||||
use App\Models\SegmentConstant;
|
||||
use App\Models\Segment;
|
||||
|
||||
class CreatesSegmentConstantBookingAmountMax extends AbstractUpdateRecord
|
||||
{
|
||||
/**
|
||||
* @param SegmentConstantBookingAmountMaxObject $object
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(Segment $segment, SegmentConstantBookingAmountMaxObject $object)
|
||||
{
|
||||
$model = new SegmentConstant();
|
||||
$model->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);
|
||||
}
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\SegmentConstants\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Classes\Modules\SegmentConstants\DataTransferObjects\SegmentConstantPaymentAttempExpiryTimeObject;
|
||||
use App\Models\SegmentConstant;
|
||||
use App\Models\Segment;
|
||||
|
||||
class CreatesSegmentConstantPaymentAttemptExpiryTime extends AbstractUpdateRecord
|
||||
{
|
||||
/**
|
||||
* @param SegmentConstantPaymentAttempExpiryTimeObject $object
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(Segment $segment, SegmentConstantPaymentAttempExpiryTimeObject $object)
|
||||
{
|
||||
$model = new SegmentConstant();
|
||||
$model->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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\SegmentConstants\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Classes\Modules\SegmentConstants\DataTransferObjects\SegmentConstantServiceChargeObject;
|
||||
use App\Models\SegmentConstant;
|
||||
use App\Models\Segment;
|
||||
|
||||
class CreatesSegmentConstantServiceCharge extends AbstractUpdateRecord
|
||||
{
|
||||
/**
|
||||
* @param SegmentConstantServiceChargeObject $object
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(Segment $segment, SegmentConstantServiceChargeObject $object)
|
||||
{
|
||||
$model = new SegmentConstant();
|
||||
$model->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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\SegmentConstants\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Classes\Modules\SegmentConstants\DataTransferObjects\SegmentConstantTaxObject;
|
||||
use App\Models\SegmentConstant;
|
||||
use App\Models\Segment;
|
||||
|
||||
class CreatesSegmentConstantTax extends AbstractUpdateRecord
|
||||
{
|
||||
/**
|
||||
* @param SegmentConstantTaxObject $object
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(Segment $segment, SegmentConstantTaxObject $object)
|
||||
{
|
||||
$model = new SegmentConstant();
|
||||
$model->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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\SegmentConstants\Standards\Rules;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\Modules\SegmentConstants\DataTransferObjects\SegmentObject;
|
||||
use App\Classes\Modules\SegmentConstants\Standards\Validators\SegmentConstantValidation;
|
||||
|
||||
class CanCreateSegmentConstant extends AbstractRule
|
||||
{
|
||||
|
||||
/** @var SegmentConstantValidation */
|
||||
private $segmentConstantValidation;
|
||||
|
||||
/**
|
||||
* CanCreateSegmentConstant constructor.
|
||||
* @param SegmentConstantValidation $segmentConstantValidation
|
||||
*/
|
||||
public function __construct(SegmentConstantValidation $segmentConstantValidation)
|
||||
{
|
||||
$this->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;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -43,7 +43,7 @@ class CanUpdateStandardSegmentConstant extends AbstractRule
|
||||
*/
|
||||
protected function validators($object): bool
|
||||
{
|
||||
return $this->segmentConstantValidation->validate($object);
|
||||
return $this->segmentConstantValidation->validate($object, 'PUT');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+11
-1
@@ -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',
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Segments\ControllersLogic;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
|
||||
use App\Classes\Modules\Segments\Standards\Rules\CanCreateSegment;
|
||||
use App\Classes\Modules\Segments\Services\CreatesSegment;
|
||||
use App\Classes\Modules\Segments\DataTransferObjects\SegmentObject;
|
||||
use App\Http\Resources\SegmentResource;
|
||||
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class CreateSegmentLogic extends AbstractControllerLogic
|
||||
{
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => '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());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Segments\ControllersLogic;
|
||||
|
||||
use App\Http\Resources\SegmentResource;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
|
||||
use App\Classes\Modules\Segments\Services\FetchesSegment;
|
||||
|
||||
use App\Classes\Modules\Segments\Standards\Rules\CanDeleteSegment;
|
||||
use App\Classes\Modules\Segments\Services\DeletesSegment;
|
||||
use App\Classes\Modules\Segments\DataTransferObjects\SegmentObject;
|
||||
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class DeleteSegmentLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => '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());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Segments\ControllersLogic;
|
||||
|
||||
use App\Http\Resources\SegmentResource;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
|
||||
use App\Classes\Modules\Segments\Services\FetchesSegment;
|
||||
|
||||
use App\Classes\Modules\Segments\Standards\Rules\CanUpdateSegment;
|
||||
use App\Classes\Modules\Segments\Services\UpdatesSegment;
|
||||
use App\Classes\Modules\Segments\DataTransferObjects\SegmentObject;
|
||||
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class UpdateSegmentLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => '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());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Segments\DataTransferObjects;
|
||||
|
||||
use App\Classes\Interfaces\DataTransferObject;
|
||||
|
||||
class SegmentObject implements DataTransferObject
|
||||
{
|
||||
/** @var string|null */
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* SegmentObject constructor.
|
||||
* @param string|null $name
|
||||
*/
|
||||
public function __construct(
|
||||
?string $name
|
||||
)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): ?string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Segments\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Classes\Modules\Segments\DataTransferObjects\SegmentObject;
|
||||
use App\Models\Segment;
|
||||
|
||||
class CreatesSegment extends AbstractUpdateRecord
|
||||
{
|
||||
/**
|
||||
* @param SegmentObject $object
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(SegmentObject $object) {
|
||||
$model = new Segment();
|
||||
$model->name = $object->getName();
|
||||
|
||||
return $this->handler($model);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Segments\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractDeleteRecord;
|
||||
use App\Models\Segment;
|
||||
|
||||
class DeletesSegment extends AbstractDeleteRecord
|
||||
{
|
||||
|
||||
public function execute(Segment $model) {
|
||||
return $this->handler($model);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Segments\Services;
|
||||
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractFetchRecord;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Models\Segment;
|
||||
|
||||
class FetchesSegment extends AbstractFetchRecord
|
||||
{
|
||||
|
||||
/** @var Segment */
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* FetchesUser constructor.
|
||||
* @param Segment $repository
|
||||
*/
|
||||
public function __construct(Segment $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Builder
|
||||
*/
|
||||
public function getRepository(): Builder
|
||||
{
|
||||
return $this->repository->newQuery();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Segments\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Classes\Modules\Segments\DataTransferObjects\SegmentObject;
|
||||
use App\Models\Segment;
|
||||
|
||||
class UpdatesSegment extends AbstractUpdateRecord
|
||||
{
|
||||
|
||||
/**
|
||||
* @param SegmentObject $object
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(Segment $model, SegmentObject $object)
|
||||
{
|
||||
$model->name = $object->getName();
|
||||
return $this->handler($model);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Segments\Standards\Rules;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\Modules\Segments\DataTransferObjects\SegmentObject;
|
||||
use App\Classes\Modules\Segments\Standards\Validators\SegmentValidation;
|
||||
|
||||
class CanCreateSegment extends AbstractRule
|
||||
{
|
||||
|
||||
/** @var SegmentValidation */
|
||||
private $segmentValidation;
|
||||
|
||||
/**
|
||||
* CanCreateSegment constructor.
|
||||
* @param SegmentValidation $segmentValidation
|
||||
*/
|
||||
public function __construct(SegmentValidation $segmentValidation)
|
||||
{
|
||||
$this->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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Segments\Standards\Rules;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\Modules\Segments\DataTransferObjects\SegmentObject;
|
||||
|
||||
class CanDeleteSegment extends AbstractRule
|
||||
{
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
|
||||
if (!\Auth::user()->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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Segments\Standards\Rules;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\Modules\Segments\DataTransferObjects\SegmentObject;
|
||||
use App\Classes\Modules\Segments\Standards\Validators\SegmentValidation;
|
||||
|
||||
class CanUpdateSegment extends AbstractRule
|
||||
{
|
||||
|
||||
/** @var SegmentValidation */
|
||||
private $segmentValidation;
|
||||
|
||||
/**
|
||||
* CanCreateAddress constructor.
|
||||
* @param SegmentValidation $segmentValidation
|
||||
*/
|
||||
public function __construct(SegmentValidation $segmentValidation)
|
||||
{
|
||||
$this->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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Segments\Standards\Validators;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractValidation;
|
||||
use App\Classes\Modules\Segments\DataTransferObjects\SegmentObject;
|
||||
|
||||
class SegmentValidation extends AbstractValidation
|
||||
{
|
||||
/**
|
||||
* @param SegmentObject $object
|
||||
* @return array
|
||||
*/
|
||||
protected function data($object): array
|
||||
{
|
||||
return [
|
||||
'name' => $object->getName(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function rules(): array
|
||||
{
|
||||
return [
|
||||
'name' => 'required',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function messages(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\SegmentConstants;
|
||||
|
||||
use App\Classes\Modules\SegmentConstants\ControllersLogic\CreateSegmentConstantLogic;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class CreateSegmentConstantController
|
||||
{
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param CreateSegmentConstantLogic $logic
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function create(Request $request, CreateSegmentConstantLogic $logic): JsonResponse {
|
||||
return $logic->execute($request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\SegmentConstants;
|
||||
|
||||
use App\Classes\Modules\SegmentConstants\ControllersLogic\UpdateSegmentConstantLogic;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class UpdateSegmentConstantController
|
||||
{
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param UpdateSegmentConstantLogic $logic
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function update(Request $request, UpdateSegmentConstantLogic $logic): JsonResponse {
|
||||
return $logic->execute($request);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Segments;
|
||||
|
||||
use App\Classes\Modules\Segments\ControllersLogic\CreateSegmentLogic;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class CreateSegmentController
|
||||
{
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param CreateSegmentLogic $logic
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function create(Request $request, CreateSegmentLogic $logic): JsonResponse {
|
||||
return $logic->execute($request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Segments;
|
||||
|
||||
use App\Classes\Modules\Segments\ControllersLogic\DeleteSegmentLogic;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class DeleteSegmentController
|
||||
{
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param DeleteSegmentLogic $logic
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function delete(Request $request, DeleteSegmentLogic $logic): JsonResponse {
|
||||
return $logic->execute($request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Segments;
|
||||
|
||||
use App\Classes\Modules\Segments\ControllersLogic\UpdateSegmentLogic;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class UpdateSegmentController
|
||||
{
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param UpdateSegmentLogic $logic
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function update(Request $request, UpdateSegmentLogic $logic): JsonResponse {
|
||||
return $logic->execute($request);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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']);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
+10
-2
@@ -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');
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -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');
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user