update segment constant logic

This commit is contained in:
edmondlang
2022-04-19 20:50:09 +08:00
parent cfd6757a84
commit 98dc43d23a
@@ -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 {