diff --git a/app/Classes/Modules/Segments/ControllersLogic/UpdateConstantLogic.php b/app/Classes/Modules/Segments/ControllersLogic/UpdateConstantLogic.php index 1cf23d0c..daa5c620 100644 --- a/app/Classes/Modules/Segments/ControllersLogic/UpdateConstantLogic.php +++ b/app/Classes/Modules/Segments/ControllersLogic/UpdateConstantLogic.php @@ -5,7 +5,9 @@ namespace App\Classes\Modules\Segments\ControllersLogic; use App\Classes\Exceptions\ResourceNotFoundException; use App\Classes\General\Abstracts\AbstractControllerLogic; use App\Classes\Modules\Segments\DataTransferObjects\ConstantObject; +use App\Classes\Modules\Segments\DataTransferObjects\SegmentObject; use App\Classes\Modules\Segments\Services\CreatesConstant; +use App\Classes\Modules\Segments\Services\CreatesSegment; use App\Classes\Modules\Segments\Services\FetchesConstant; use App\Classes\Modules\Segments\Services\FetchesSegment; use App\Classes\Modules\Segments\Standards\Rules\CanCreateConstant; @@ -48,6 +50,9 @@ class UpdateConstantLogic extends AbstractControllerLogic /** @var CreatesConstant */ private $createsConstant; + /** @var CreatesSegment */ + private $createsSegment; + /** @var UpdatesConstantValue */ private $updatesConstantValue; @@ -60,6 +65,7 @@ class UpdateConstantLogic extends AbstractControllerLogic * @param CanCreateConstant $canCreateConstant * @param CreatesConstant $createsConstant * @param UpdatesConstantValueByState $updatesConstantValueByState + * @param CreatesSegment $createsSegment */ public function __construct( CanUpdateConstant $canUpdateConstant, @@ -68,7 +74,8 @@ class UpdateConstantLogic extends AbstractControllerLogic FetchesConstant $fetchesConstant, CanCreateConstant $canCreateConstant, CreatesConstant $createsConstant, - UpdatesConstantValue $updatesConstantValue + UpdatesConstantValue $updatesConstantValue, + CreatesSegment $createsSegment ) { $this->canUpdateConstant = $canUpdateConstant; @@ -78,6 +85,7 @@ class UpdateConstantLogic extends AbstractControllerLogic $this->canCreateConstant = $canCreateConstant; $this->createsConstant = $createsConstant; $this->updatesConstantValue = $updatesConstantValue; + $this->createsSegment = $createsSegment; } /** * @param Request $request @@ -88,8 +96,16 @@ class UpdateConstantLogic extends AbstractControllerLogic */ public function logic(Request $request) : JsonResponse { + try { - $segment = $this->fetchesSegment->execute(['id' => $request->route('id')]); + $segment = $this->fetchesSegment->execute(['id' => $request->route('id')]); + + } catch (ResourceNotFoundException $exception){ + + $object = new SegmentObject('Standard Segment', 1); + + $segment = $this->createsSegment->execute($object); + } try {