'Create Base Price', 'message' => 'You have successfully created a Base Price' ]; } /** @var CanUpdateConstant */ private $canUpdateConstant; /** @var UpdatesConstant */ private $updatesConstant; /** @var FetchesSegment */ private $fetchesSegment; /** @var FetchesConstant */ private $fetchesConstant; /** @var CanCreateConstant */ private $canCreateConstant; /** @var CreatesConstant */ private $createsConstant; /** @var UpdatesBasePriceConstantByDates */ private $updatesBasePriceConstantByDates; /** * UpdateConstantLogic constructor. * @param CanUpdateConstant $canUpdateConstant * @param UpdatesConstant $updatesConstant * @param FetchesSegment $fetchesSegment * @param FetchesConstant $fetchesConstant * @param CanCreateConstant $canCreateConstant * @param CreatesConstant $createsConstant * @param UpdatesBasePriceConstantByDates $updatesBasePriceConstantByDates */ public function __construct( CanUpdateConstant $canUpdateConstant, UpdatesConstant $updatesConstant, FetchesSegment $fetchesSegment, FetchesConstant $fetchesConstant, CanCreateConstant $canCreateConstant, CreatesConstant $createsConstant, UpdatesBasePriceConstantByDates $updatesBasePriceConstantByDates ) { $this->canUpdateConstant = $canUpdateConstant; $this->updatesConstant = $updatesConstant; $this->fetchesSegment = $fetchesSegment; $this->fetchesConstant = $fetchesConstant; $this->canCreateConstant = $canCreateConstant; $this->createsConstant = $createsConstant; $this->updatesBasePriceConstantByDates = $updatesBasePriceConstantByDates; } /** * @param Request $request * @return JsonResponse * @throws \App\Classes\Exceptions\AccessForbiddenException * @throws \App\Classes\Exceptions\MalformedRequestException * @throws \App\Classes\Exceptions\RequestValidationException */ public function logic(Request $request) : JsonResponse { $segment = $this->fetchesSegment->execute(['id' => $request->route('id')]); try { $constant = $this->fetchesConstant->execute(['segment_id' => $segment->id, 'reference' => SegmentConstants::BASE_PRICE]); } catch (ResourceNotFoundException $exception){ $constantObject = []; $object = new ConstantObject( SegmentConstants::BASE_PRICE, $constantObject ); $constant = $this->createsConstant->execute($segment, $object); } $constantValue = $this->updatesBasePriceConstantByDates->execute($constant->value, $request->input('dateFrom'), $request->input('dateTo'), $request->input('rate')); $object = new ConstantObject(SegmentConstants::BASE_PRICE, $constantValue); $this->canUpdateConstant->passes($object); $constant = $this->updatesConstant->execute($constant, $object); return $this->resourceResponse(new ConstantResource($constant)); } }