Files
shipping-portal/app/Classes/Modules/ContainerPackingLists/ControllersLogic/FetchContainerPackingListLogic 2.php
T
2021-07-24 11:39:40 +08:00

67 lines
2.0 KiB
PHP

<?php
namespace App\Classes\Modules\ContainerPackingLists\ControllersLogic;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\ContainerPackingLists\Services\FetchesContainerPackingList;
use App\Classes\Modules\ContainerPackingLists\Standards\Rules\CanFetchContainerPackingList;
use App\Http\Resources\ContainerPackingListResource;
use ErrorException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class FetchContainerPackingListLogic extends AbstractControllerLogic
{
/**
* @return array
*/
protected function notification():array {
return [
'title' => 'Retrieved ContainerPackingList',
'message' => 'You have successfully retrieved a ContainerPackingList'
];
}
/** @var CanFetchContainerPackingList */
private $canFetchContainerPackingList;
/** @var FetchesContainerPackingList */
private $fetchesContainerPackingList;
/**
* FetchContainerPackingListControllersLogic constructor.
* @param CanFetchContainerPackingList $canFetchContainerPackingList
* @param FetchesContainerPackingList $fetchesContainerPackingList
*/
public function __construct(CanFetchContainerPackingList $canFetchContainerPackingList, FetchesContainerPackingList $fetchesContainerPackingList)
{
$this->canFetchContainerPackingList = $canFetchContainerPackingList;
$this->fetchesContainerPackingList = $fetchesContainerPackingList;
}
/**
* @param Request $request
* @return JsonResponse
* @throws ErrorException
*/
public function logic(Request $request) : JsonResponse
{
try {
$this->canFetchContainerPackingList->passes();
$query = $this->fetchesContainerPackingList->execute(['id' => $request->route('id')]);
return $this->resourceResponse(new ContainerPackingListResource($query));
} catch (\Exception $exception){
throw new ErrorException($exception->getMessage(), $exception->getCode());
}
}
}