mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/portal.git
synced 2026-08-20 13:04:11 +00:00
72 lines
2.4 KiB
PHP
72 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\Modules\Transports\ControllersLogic;
|
|
|
|
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
|
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
|
use App\Classes\Modules\Transports\Services\CreatesTransport;
|
|
use App\Classes\Modules\Transports\Standards\Rules\CanCreateTransport;
|
|
use App\Classes\Modules\Transports\DataTransferObjects\TransportObject;
|
|
use App\Classes\Modules\ContainerPackingLists\Services\FetchesContainerPackingList;
|
|
use App\Http\Resources\TransportResource;
|
|
use ErrorException;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
|
|
class CreateTransportLogic extends AbstractControllerLogic
|
|
{
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
protected function notification():array {
|
|
return [
|
|
'title' => 'Created Transport',
|
|
'message' => 'You have successfully created a new Transport'
|
|
];
|
|
}
|
|
|
|
/** @var CanCreateTransport */
|
|
private $canCreateTransport;
|
|
|
|
/** @var FetchesContainerPackingList */
|
|
private $fetchesContainerPackingList;
|
|
|
|
/** @var CreatesTransport */
|
|
private $createsTransport;
|
|
|
|
/**
|
|
* CreateTransportLogic constructor.
|
|
* @param CanCreateTransport $canCreateTransport
|
|
* @param FetchesContainerPackingList $fetchesContainerPackingList
|
|
* @param CreatesTransport $createsTransport
|
|
*/
|
|
public function __construct(CanCreateTransport $canCreateTransport, FetchesContainerPackingList $fetchesContainerPackingList, CreatesTransport $createsTransport)
|
|
{
|
|
$this->canCreateTransport = $canCreateTransport;
|
|
$this->fetchesContainerPackingList = $fetchesContainerPackingList;
|
|
$this->createsTransport = $createsTransport;
|
|
}
|
|
|
|
/**
|
|
* @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
|
|
{
|
|
|
|
$object = new TransportObject($request->input('type'), $request->input('courier'), $request->input('tracking_number'), null, null, ApprovalStatus::PENDING_SUBMISSION);
|
|
|
|
$this->canCreateTransport->passes($object);
|
|
|
|
$query = $this->createsTransport->execute($this->fetchesContainerPackingList->execute(['id' => $request->input('container_id')]), $object);
|
|
|
|
return $this->resourceResponse(new TransportResource($query));
|
|
|
|
}
|
|
|
|
}
|