mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-19 20:44:19 +00:00
68 lines
2.0 KiB
PHP
68 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\Modules\PackingLists\ControllersLogic;
|
|
|
|
|
|
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
|
use App\Classes\Modules\PackingLists\Services\ListsPackingLists;
|
|
use App\Classes\Modules\PackingLists\Standards\Rules\CanListPackingLists;
|
|
use App\Http\Resources\PackingListResource;
|
|
use App\Http\Resources\PackingListWithStorageResource;
|
|
use ErrorException;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
|
|
class ListPackingListsLogic extends AbstractControllerLogic
|
|
{
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
protected function notification():array {
|
|
return [
|
|
'title' => 'Retrieved PackingLists',
|
|
'message' => 'You have successfully retrieved a list of PackingLists'
|
|
];
|
|
}
|
|
|
|
/** @var CanListPackingLists */
|
|
private $canListPackingLists;
|
|
|
|
/** @var ListsPackingLists */
|
|
private $listsPackingLists;
|
|
|
|
/**
|
|
* ListPackingListsLogic constructor.
|
|
* @param CanListPackingLists $canListPackingLists
|
|
* @param ListsPackingLists $listsPackingLists
|
|
*/
|
|
public function __construct(CanListPackingLists $canListPackingLists, ListsPackingLists $listsPackingLists)
|
|
{
|
|
$this->canListPackingLists = $canListPackingLists;
|
|
$this->listsPackingLists = $listsPackingLists;
|
|
}
|
|
|
|
|
|
/**
|
|
* @param Request $request
|
|
* @return JsonResponse
|
|
* @throws ErrorException
|
|
*/
|
|
public function logic(Request $request) : JsonResponse
|
|
{
|
|
$this->canListPackingLists->passes();
|
|
|
|
$query = $this->listsPackingLists->execute($this->listsPackingLists->deserializeFilters($request->input('filters')));
|
|
|
|
if($request->input('storages')){
|
|
foreach ($query->items() as $item) {
|
|
$item['storages'] = $request->input('storages');
|
|
}
|
|
return $this->collectionResponse(PackingListWithStorageResource::collection($query));
|
|
}
|
|
else{
|
|
return $this->collectionResponse(PackingListResource::collection($query));
|
|
}
|
|
}
|
|
}
|