mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-19 12:34:18 +00:00
4087df6649
# Conflicts: # app/Classes/Modules/Addresses/ControllersLogic/CreateAddressLogic.php # app/Classes/Modules/Addresses/ControllersLogic/UpdateAddressLogic.php # app/Models/Address.php
128 lines
5.0 KiB
PHP
128 lines
5.0 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\Modules\Addresses\ControllersLogic;
|
|
|
|
|
|
use App\Classes\Exceptions\AccessForbiddenException;
|
|
use App\Classes\Exceptions\MalformedRequestException;
|
|
use App\Classes\Exceptions\RequestValidationException;
|
|
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
|
use App\Classes\General\Interfaces\Contactable;
|
|
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\FetchesCompanyModule;
|
|
use App\Classes\Modules\Contacts\DataTransferObjects\ContactObject;
|
|
use App\Classes\Modules\Contacts\Processors\CreateContactProcessor;
|
|
use App\Classes\Modules\Remarks\DataTransferObjects\RemarkObject;
|
|
use App\Classes\Modules\Remarks\Processors\CreateRemarkProcessor;
|
|
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
|
use App\Classes\ValueObjects\Constants\RemarkTypes;
|
|
use App\Http\Resources\AddressResource;
|
|
use App\Models\Address;
|
|
use App\Transformers\AddressTransformer;
|
|
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 FetchesCompanyModule */
|
|
private $fetchesCompanyModule;
|
|
|
|
/** @var CreatesAddress */
|
|
private $createsAddress;
|
|
|
|
/** @var CreateContactProcessor */
|
|
private $createContactProcessor;
|
|
|
|
/** @var CreateRemarkProcessor */
|
|
private $createRemarkProcessor;
|
|
|
|
/**
|
|
* CreateAddressLogic constructor.
|
|
* @param CanCreateAddress $canCreateAddress
|
|
* @param FetchesDistrict $fetchesDistrict
|
|
* @param FetchesCompanyModule $fetchesCompanyModule
|
|
* @param CreatesAddress $createsAddress
|
|
* @param CreateContactProcessor $createContactProcessor
|
|
* @param CreateRemarkProcessor $createRemarkProcessor
|
|
*/
|
|
public function __construct(CanCreateAddress $canCreateAddress, FetchesDistrict $fetchesDistrict, FetchesCompanyModule $fetchesCompanyModule, CreatesAddress $createsAddress, CreateContactProcessor $createContactProcessor, CreateRemarkProcessor $createRemarkProcessor)
|
|
{
|
|
$this->canCreateAddress = $canCreateAddress;
|
|
$this->fetchesDistrict = $fetchesDistrict;
|
|
$this->fetchesCompanyModule = $fetchesCompanyModule;
|
|
$this->createsAddress = $createsAddress;
|
|
$this->createContactProcessor = $createContactProcessor;
|
|
$this->createRemarkProcessor = $createRemarkProcessor;
|
|
}
|
|
|
|
/**
|
|
* @param Request $request
|
|
* @return JsonResponse
|
|
* @throws AccessForbiddenException
|
|
* @throws MalformedRequestException
|
|
* @throws 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('type'), ApprovalStatus::APPROVED, $request->input('reference'));
|
|
|
|
$this->canCreateAddress->passes($object);
|
|
|
|
/** @var Address $address */
|
|
$address = $this->createsAddress->execute($this->fetchesCompanyModule->execute(['id' => $request->input('company_module_id')]), $object);
|
|
|
|
if ($request->input('phone')) {
|
|
$contactObject = new ContactObject($request->input('person_in_charge'), $request->input('phone'), '', '');
|
|
$this->createContactProcessor->execute($contactObject, $address);
|
|
}
|
|
|
|
if ($request->input('remark')) {
|
|
$remarkObject = new RemarkObject($request->input('remark'), Auth()->user()->id);
|
|
$this->createRemarkProcessor->execute($address, $remarkObject);
|
|
}
|
|
|
|
/* return fractal()
|
|
->item($address, new AddressTransformer())
|
|
->parseIncludes('remark')
|
|
->respond(200, [], JSON_PRETTY_PRINT);*/
|
|
|
|
$addressExtraFields = [
|
|
'property_type' => $request->input('property_type'),
|
|
'tools_required_unload' => $request->input('tools_required_unload'),
|
|
'pickup_time_from' => $request->input('pickup_time_from'),
|
|
'pickup_time_to' => $request->input('pickup_time_to'),
|
|
];
|
|
|
|
$addressExtraFieldsObject = new RemarkObject(json_encode($addressExtraFields), Auth()->user()->id, RemarkTypes::ADDRESS_EXTRA_COLUMNS);
|
|
$this->createRemarkProcessor->execute($address, $addressExtraFieldsObject);
|
|
|
|
return $this->resourceResponse(new AddressResource($address));
|
|
|
|
}
|
|
|
|
} |