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

73 lines
2.6 KiB
PHP

<?php
namespace App\Classes\Modules\ContainerPackingLists\ControllersLogic;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\ContainerPackingLists\Services\UpdatesContainerPackingList;
use App\Classes\Modules\ContainerPackingLists\Services\FetchesContainerPackingList;
use App\Classes\Modules\ContainerPackingLists\Standards\Rules\CanUpdateContainerPackingList;
use App\Classes\Modules\ContainerPackingLists\DataTransferObjects\ContainerPackingListObject;
use App\Http\Resources\ContainerPackingListResource;
use ErrorException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class UpdateContainerPackingListLogic extends AbstractControllerLogic
{
/**
* @return array
*/
protected function notification():array {
return [
'title' => 'Updated ContainerPackingList',
'message' => 'You have successfully updated the ContainerPackingList'
];
}
/** @var CanUpdateContainerPackingList */
private $canUpdateContainerPackingList;
/** @var UpdatesContainerPackingList */
private $updatesContainerPackingList;
/** @var FetchesContainerPackingList */
private $fetchesContainerPackingList;
/**
* UpdateContainerPackingListLogic constructor.
* @param CanUpdateContainerPackingList $canUpdateContainerPackingList
* @param UpdatesContainerPackingList $updatesContainerPackingList
* @param FetchesContainerPackingList $fetchesContainerPackingList
*/
public function __construct(CanUpdateContainerPackingList $canUpdateContainerPackingList, UpdatesContainerPackingList $updatesContainerPackingList, FetchesContainerPackingList $fetchesContainerPackingList)
{
$this->canUpdateContainerPackingList = $canUpdateContainerPackingList;
$this->updatesContainerPackingList = $updatesContainerPackingList;
$this->fetchesContainerPackingList = $fetchesContainerPackingList;
}
/**
* @param Request $request
* @return JsonResponse
* @throws ErrorException
*/
public function logic(Request $request) : JsonResponse
{
$container = $this->fetchesContainerPackingList->execute(['id' => $request->route('id')]);
$object = new ContainerPackingListObject( $container->packing_list_id , $request->input('container_reference'), $request->input('container_type'), $request->input('seal_reference'));
$this->canUpdateContainerPackingList->passes($object);
$query = $this->updatesContainerPackingList->execute($container, $object);
return $this->resourceResponse(new ContainerPackingListResource($query));
}
}