mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/portal.git
synced 2026-08-19 12:34:01 +00:00
79 lines
2.5 KiB
PHP
79 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\Modules\Addresses\ControllersLogic;
|
|
|
|
|
|
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
|
use App\Classes\Modules\Addresses\Services\CreatesAddress;
|
|
use App\Classes\Modules\Addresses\Services\FetchesDistrict;
|
|
use App\Classes\Modules\Addresses\Standards\Rules\CanCreateAddress;
|
|
use App\Classes\Modules\Addresses\DataTransferObjects\AddressObject;
|
|
use App\Classes\Modules\Companies\Services\FetchesCompany;
|
|
use App\Http\Resources\AddressResource;
|
|
use ErrorException;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
|
|
class CreateAddressLogic extends AbstractControllerLogic
|
|
{
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
protected function notification():array {
|
|
return [
|
|
'title' => 'Created Address',
|
|
'message' => 'You have successfully created a new Address'
|
|
];
|
|
}
|
|
|
|
/** @var CanCreateAddress */
|
|
private $canCreateAddress;
|
|
|
|
/** @var FetchesDistrict */
|
|
private $fetchesDistrict;
|
|
|
|
/** @var FetchesCompany */
|
|
private $fetchesCompany;
|
|
|
|
/** @var CreatesAddress */
|
|
private $createsAddress;
|
|
|
|
/**
|
|
* CreateAddressLogic constructor.
|
|
* @param CanCreateAddress $canCreateAddress
|
|
* @param FetchesDistrict $fetchesDistrict
|
|
* @param FetchesCompany $fetchesCompany
|
|
* @param CreatesAddress $createsAddress
|
|
*/
|
|
public function __construct(CanCreateAddress $canCreateAddress, FetchesDistrict $fetchesDistrict, FetchesCompany $fetchesCompany, CreatesAddress $createsAddress)
|
|
{
|
|
$this->canCreateAddress = $canCreateAddress;
|
|
$this->fetchesDistrict = $fetchesDistrict;
|
|
$this->fetchesCompany = $fetchesCompany;
|
|
$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'));
|
|
|
|
$this->canCreateAddress->passes($object);
|
|
|
|
$query = $this->createsAddress->execute($this->fetchesCompany->execute(['id' => $request->input('company_id')]), $object);
|
|
|
|
return $this->resourceResponse(new AddressResource($query));
|
|
|
|
}
|
|
|
|
} |