'Updated Supplier', 'message' => 'You have successfully updated the Supplier' ]; } /** @var CanCreateConstant */ private $canCreateConstant; /** @var CanUpdateConstant */ private $canUpdateConstant; /** @var FetchesSegment */ private $fetchesSegment; /** @var FetchesConstant */ private $fetchesConstant; /** @var UpdatesConstant */ private $updatesConstant; /** @var CreatesConstant */ private $createsConstant; /** * UpdateSupplierCurrenciesLogic constructor. * @param CanCreateConstant $canCreateConstant * @param CanUpdateConstant $canUpdateConstant * @param FetchesSegment $fetchesSegment * @param FetchesConstant $fetchesConstant * @param UpdatesConstant $updatesConstant * @param CreatesConstant $createsConstant */ public function __construct(CanCreateConstant $canCreateConstant, CanUpdateConstant $canUpdateConstant, FetchesSegment $fetchesSegment, FetchesConstant $fetchesConstant, UpdatesConstant $updatesConstant, CreatesConstant $createsConstant) { $this->canCreateConstant = $canCreateConstant; $this->canUpdateConstant = $canUpdateConstant; $this->fetchesSegment = $fetchesSegment; $this->fetchesConstant = $fetchesConstant; $this->updatesConstant = $updatesConstant; $this->createsConstant = $createsConstant; } /** * @param Request $request * @return JsonResponse * @throws ResourceNotFoundException * @throws \App\Classes\Exceptions\AccessForbiddenException * @throws \App\Classes\Exceptions\MalformedRequestException * @throws \App\Classes\Exceptions\RequestValidationException */ public function logic(Request $request) : JsonResponse { $supplierId = $request->route('id'); $object = new ConstantObject('Supplier\'s Currencies',SegmentConstants::SUPPLIER_CURRENCIES, [ 'id' => $supplierId, 'currencies' => $request->input('currencies') ] ); try { $constant = $this->fetchesConstant->execute(['supplier_currencies' => $supplierId]); $this->canUpdateConstant->passes($object); $this->updatesConstant->execute($constant, $object); } catch (ResourceNotFoundException $exception){ $this->canCreateConstant->passes($object); $segment = $this->fetchesSegment->execute(['type' => SegmentConstants::STANDARD_SEGMENT]); $this->createsConstant->execute($segment, $object); } return $this->response([]); } }