mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-19 04:24:12 +00:00
87 lines
3.4 KiB
PHP
87 lines
3.4 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\Services\FetchesDistrict;
|
|
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;
|
|
|
|
/** @var FetchesDistrict */
|
|
private $fetchesDistrict;
|
|
|
|
/**
|
|
* UpdateContainerPackingListLogic constructor.
|
|
* @param CanUpdateContainerPackingList $canUpdateContainerPackingList
|
|
* @param UpdatesContainerPackingList $updatesContainerPackingList
|
|
* @param FetchesContainerPackingList $fetchesContainerPackingList
|
|
* @param FetchesDistrict $fetchesDistrict
|
|
*/
|
|
public function __construct(CanUpdateContainerPackingList $canUpdateContainerPackingList, UpdatesContainerPackingList $updatesContainerPackingList, FetchesContainerPackingList $fetchesContainerPackingList, FetchesDistrict $fetchesDistrict)
|
|
{
|
|
$this->canUpdateContainerPackingList = $canUpdateContainerPackingList;
|
|
$this->updatesContainerPackingList = $updatesContainerPackingList;
|
|
$this->fetchesContainerPackingList = $fetchesContainerPackingList;
|
|
$this->fetchesDistrict = $fetchesDistrict;
|
|
}
|
|
|
|
|
|
/**
|
|
* @param Request $request
|
|
* @return JsonResponse
|
|
* @throws ErrorException
|
|
*/
|
|
public function logic(Request $request) : JsonResponse
|
|
{
|
|
try {
|
|
|
|
$district = $this->fetchesDistrict->execute(['id' => $request->input('district_id')]);
|
|
$object = new ContainerPackingListObject($request->input('street_one'), $request->input('street_two'), $district->country_id, $district->state_id, $district->id, $request->input('post_code'));
|
|
//$object = new ContainerPackingListObject($request->input('company_id'), $request->input('street_one'), $request->input('street_two'), $request->input('city'), $request->input('state'), $request->input('post_code'), $request->input('country'), $request->input('default'), $request->input('billing'));
|
|
|
|
$this->canUpdateContainerPackingList->passes($object);
|
|
|
|
$query = $this->fetchesContainerPackingList->execute(['id' => $request->route('id')]);
|
|
|
|
$query = $this->updatesContainerPackingList->execute($query, $object);
|
|
|
|
return $this->resourceResponse(new ContainerPackingListResource($query));
|
|
|
|
|
|
} catch (\Exception $exception){
|
|
throw new ErrorException($exception->getMessage(), $exception->getCode());
|
|
}
|
|
|
|
}
|
|
|
|
}
|