Files
shipping-portal/app/Classes/Modules/PackingLists/ControllersLogic/CreateContainerPackingListLogic.php
T
2021-07-23 21:27:18 +08:00

75 lines
2.5 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\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 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, FetchesCompany $fetchesCompany, CreatesPackingList $createsPackingList)
{
$this->canCreatePackingList = $canCreatePackingList;
$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));
}
}