'Created Address', 'message' => 'You have successfully created a new Address' ]; } /** @var CanCreateAddress */ private $canCreateAddress; /** @var FetchesDistrict */ private $fetchesDistrict; /** @var FetchesCompanyModule */ private $fetchesCompanyModule; /** @var CreatesAddress */ private $createsAddress; /** * CreateAddressLogic constructor. * @param CanCreateAddress $canCreateAddress * @param FetchesDistrict $fetchesDistrict * @param FetchesCompanyModule $fetchesCompanyModule * @param CreatesAddress $createsAddress */ public function __construct(CanCreateAddress $canCreateAddress, FetchesDistrict $fetchesDistrict, FetchesCompanyModule $fetchesCompanyModule, CreatesAddress $createsAddress) { $this->canCreateAddress = $canCreateAddress; $this->fetchesDistrict = $fetchesDistrict; $this->fetchesCompanyModule = $fetchesCompanyModule; $this->createsAddress = $createsAddress; } /** * @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 { $district = $this->fetchesDistrict->execute(['id' => $request->input('district_id')]); $object = new AddressObject($request->input('street_one'), $request->input('street_two'), $district->country_id, $district->state_id, $district->id, $request->input('post_code'), $request->input('reference')); $this->canCreateAddress->passes($object); $address = $this->createsAddress->execute($this->fetchesCompanyModule->execute(['id' => $request->input('company_module_id')]), $object); return $this->resourceResponse(new AddressResource($address)); } }