mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-19 12:34:18 +00:00
80 lines
2.7 KiB
PHP
80 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\Modules\PackingLists\ControllersLogic;
|
|
|
|
|
|
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
|
use App\Classes\Modules\PackingLists\Services\CreatesPackingList;
|
|
use App\Classes\Modules\PackingLists\Services\FetchesDistrict;
|
|
use App\Classes\Modules\PackingLists\Standards\Rules\CanCreatePackingList;
|
|
use App\Classes\Modules\PackingLists\DataTransferObjects\PackingListObject;
|
|
use App\Classes\Modules\Companies\Services\FetchesCompany;
|
|
use App\Http\Resources\PackingListResource;
|
|
use ErrorException;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
|
|
class CreatePackingListLogic extends AbstractControllerLogic
|
|
{
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
protected function notification():array {
|
|
return [
|
|
'title' => 'Created PackingList',
|
|
'message' => 'You have successfully created a new PackingList'
|
|
];
|
|
}
|
|
|
|
/** @var CanCreatePackingList */
|
|
private $canCreatePackingList;
|
|
|
|
/** @var FetchesDistrict */
|
|
private $fetchesDistrict;
|
|
|
|
/** @var FetchesCompany */
|
|
private $fetchesCompany;
|
|
|
|
/** @var CreatesPackingList */
|
|
private $createsPackingList;
|
|
|
|
/**
|
|
* CreatePackingListLogic constructor.
|
|
* @param CanCreatePackingList $canCreatePackingList
|
|
* @param FetchesDistrict $fetchesDistrict
|
|
* @param FetchesCompany $fetchesCompany
|
|
* @param CreatesPackingList $createsPackingList
|
|
*/
|
|
public function __construct(CanCreatePackingList $canCreatePackingList, FetchesDistrict $fetchesDistrict, FetchesCompany $fetchesCompany, CreatesPackingList $createsPackingList)
|
|
{
|
|
$this->canCreatePackingList = $canCreatePackingList;
|
|
$this->fetchesDistrict = $fetchesDistrict;
|
|
$this->fetchesCompany = $fetchesCompany;
|
|
$this->createsPackingList = $createsPackingList;
|
|
}
|
|
|
|
/**
|
|
* @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 PackingListObject($request->input('street_one'), $request->input('street_two'), $district->country_id, $district->state_id, $district->id, $request->input('post_code'));
|
|
|
|
$this->canCreatePackingList->passes($object);
|
|
|
|
$query = $this->createsPackingList->execute($this->fetchesCompany->execute(['id' => $request->input('company_id')]), $object);
|
|
|
|
return $this->resourceResponse(new PackingListResource($query));
|
|
|
|
}
|
|
|
|
}
|