mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-22 14:04:06 +00:00
83 lines
2.8 KiB
PHP
83 lines
2.8 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\PackingListBaseResource;
|
|
use App\Http\Resources\PackingListResource;
|
|
use App\Http\Resources\PackingListWithStorageResource;
|
|
use ErrorException;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
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')));
|
|
|
|
$data = json_encode($request->input('storages'));
|
|
Log::info("ListPackingListsLogic storages A: {$data}");
|
|
|
|
if($request->input('storages')){
|
|
Log::info("ListPackingListsLogic storages B: {$data}");
|
|
foreach ($query->items() as $item) {
|
|
$item['storages'] = $request->input('storages');
|
|
}
|
|
return $this->collectionResponse(PackingListWithStorageResource::collection($query));
|
|
}
|
|
else{
|
|
$filters = json_decode($request->input('filters'), true);
|
|
if(isset($filters['include_packages'])){
|
|
//'include_packages' filter is an attempt to reduce the request-response time to only load basic information unless explicitly indicated to be included
|
|
foreach ($query->items() as $item) {
|
|
$item['include_packages'] = $filters['include_packages'];
|
|
}
|
|
return $this->collectionResponse(PackingListBaseResource::collection($query));
|
|
}
|
|
|
|
return $this->collectionResponse(PackingListResource::collection($query));
|
|
}
|
|
}
|
|
}
|