Files
shipping-portal/app/Classes/Modules/ContainerPackingLists/ControllersLogic/CreateContainerPackingListLogic.php
T
2021-07-24 16:21:11 +08:00

68 lines
2.4 KiB
PHP

<?php
namespace App\Classes\Modules\ContainerPackingLists\ControllersLogic;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\ContainerPackingLists\Services\CreatesContainerPackingList;
use App\Classes\Modules\ContainerPackingLists\Standards\Rules\CanCreateContainerPackingList;
use App\Classes\Modules\ContainerPackingLists\DataTransferObjects\ContainerPackingListObject;
use App\Classes\Modules\PackingLists\Services\FetchesPackingList;
use App\Http\Resources\ContainerPackingListResource;
use ErrorException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class CreateContainerPackingListLogic extends AbstractControllerLogic
{
/**
* @return array
*/
protected function notification():array {
return [
'title' => 'Created PackingList',
'message' => 'You have successfully created a new PackingList'
];
}
/** @var CanCreateContainerPackingList */
private $canCreateContainerPackingList;
/** @var FetchesPackingList */
private $fetchesPackingList;
/** @var CreatesPackingList */
private $createsContainerPackingList;
public function __construct(CanCreateContainerPackingList $canCreateContainerPackingList, FetchesPackingList $fetchesPackingList, CreatesContainerPackingList $createsContainerPackingList)
{
$this->canCreateContainerPackingList = $canCreateContainerPackingList;
$this->fetchesPackingList = $fetchesPackingList;
$this->createsContainerPackingList = $createsContainerPackingList;
}
/**
* @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
{
$packingList = $this->fetchesPackingList->execute(['id' => $request->input('packing_list_id')]);
$object = new ContainerPackingListObject( $packingList->id , $request->input('container_reference'), $request->input('container_type'), $request->input('seal_reference'));
$this->canCreateContainerPackingList->passes($object);
$query = $this->createsContainerPackingList->execute($object);
return $this->resourceResponse(new ContainerPackingListResource($query));
}
}