Files
shipping-portal/app/Classes/Modules/PackingLists/ControllersLogic/UpdatePackingListLogic.php
T
2021-07-23 01:25:48 +08:00

87 lines
3.0 KiB
PHP

<?php
namespace App\Classes\Modules\PackingLists\ControllersLogic;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\PackingLists\Services\UpdatesPackingList;
use App\Classes\Modules\PackingLists\Services\FetchesPackingList;
use App\Classes\Modules\PackingLists\Services\FetchesDistrict;
use App\Classes\Modules\PackingLists\Standards\Rules\CanUpdatePackingList;
use App\Classes\Modules\PackingLists\DataTransferObjects\PackingListObject;
use App\Http\Resources\PackingListResource;
use ErrorException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class UpdatePackingListLogic extends AbstractControllerLogic
{
/**
* @return array
*/
protected function notification():array {
return [
'title' => 'Updated PackingList',
'message' => 'You have successfully updated the PackingList'
];
}
/** @var CanUpdatePackingList */
private $canUpdatePackingList;
/** @var UpdatesPackingList */
private $updatesPackingList;
/** @var FetchesPackingList */
private $fetchesPackingList;
/** @var FetchesDistrict */
private $fetchesDistrict;
/**
* UpdatePackingListLogic constructor.
* @param CanUpdatePackingList $canUpdatePackingList
* @param UpdatesPackingList $updatesPackingList
* @param FetchesPackingList $fetchesPackingList
* @param FetchesDistrict $fetchesDistrict
*/
public function __construct(CanUpdatePackingList $canUpdatePackingList, UpdatesPackingList $updatesPackingList, FetchesPackingList $fetchesPackingList, FetchesDistrict $fetchesDistrict)
{
$this->canUpdatePackingList = $canUpdatePackingList;
$this->updatesPackingList = $updatesPackingList;
$this->fetchesPackingList = $fetchesPackingList;
$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 PackingListObject($request->input('street_one'), $request->input('street_two'), $district->country_id, $district->state_id, $district->id, $request->input('post_code'));
//$object = new PackingListObject($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->canUpdatePackingList->passes($object);
$query = $this->fetchesPackingList->execute(['id' => $request->route('id')]);
$query = $this->updatesPackingList->execute($query, $object);
return $this->resourceResponse(new PackingListResource($query));
} catch (\Exception $exception){
throw new ErrorException($exception->getMessage(), $exception->getCode());
}
}
}