'Created Segment Constant', 'message' => 'You have successfully created a new Segment Constant' ]; } /** @var CanCreateSegmentConstant */ private $canCreateSegmentConstant; /** @var CreatesSegmentConstant */ private $createsSegmentConstant; /** @var FetchesSegmentConstant */ private $fetchesSegmentConstant; /** @var FetchesSegment */ private $fetchesSegment; /** * CreateSegmentConstantLogic constructor. * @param CanCreateSegmentConstant $canCreateSegmentConstant * @param CreatesSegmentConstant $createsSegmentConstant * @param FetchesSegmentConstant $fetchesSegmentConstant * @param FetchesSegment $fetchesSegment */ public function __construct( CanCreateSegmentConstant $canCreateSegmentConstant, CreatesSegmentConstant $createsSegmentConstant, FetchesSegmentConstant $fetchesSegmentConstant, FetchesSegment $fetchesSegment ) { $this->canCreateSegmentConstant = $canCreateSegmentConstant; $this->createsSegmentConstant = $createsSegmentConstant; $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'), ]); $standard_segment_constant_query = $this->fetchesSegmentConstant->execute([ 'id' => $request->input('standard_segment_constant_id'), ]); $segment_constant_object = new SegmentConstantObject( $request->input('segment_id'), $standard_segment_constant_query->name, $standard_segment_constant_query->reference, $standard_segment_constant_query->detail->type, $request->input('detail') ); $this->canCreateSegmentConstant->passes($segment_constant_object); $standard_segment_constant_query = $this->createsSegmentConstant->execute($segment_query, $segment_constant_object); DB::commit(); return $this->resourceResponse(new SegmentConstantResource($standard_segment_constant_query)); } catch (\Exception $exception) { throw new ErrorException($exception->getMessage(), $exception->getCode()); } } }