mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/portal.git
synced 2026-08-20 04:53:59 +00:00
87 lines
2.8 KiB
PHP
87 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\Modules\Remarks\ControllersLogic;
|
|
|
|
|
|
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
|
use App\Classes\Modules\Remarks\Services\UpdatesRemark;
|
|
use App\Classes\Modules\Remarks\Services\FetchesRemark;
|
|
use App\Classes\Modules\Remarks\Services\FetchesDistrict;
|
|
use App\Classes\Modules\Remarks\Standards\Rules\CanUpdateRemark;
|
|
use App\Classes\Modules\Remarks\DataTransferObjects\RemarkObject;
|
|
use App\Http\Resources\RemarkResource;
|
|
use ErrorException;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
|
|
class UpdateRemarkLogic extends AbstractControllerLogic
|
|
{
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
protected function notification():array {
|
|
return [
|
|
'title' => 'Updated Remark',
|
|
'message' => 'You have successfully updated the Remark'
|
|
];
|
|
}
|
|
|
|
/** @var CanUpdateRemark */
|
|
private $canUpdateRemark;
|
|
|
|
/** @var UpdatesRemark */
|
|
private $updatesRemark;
|
|
|
|
/** @var FetchesRemark */
|
|
private $fetchesRemark;
|
|
|
|
/** @var FetchesDistrict */
|
|
private $fetchesDistrict;
|
|
|
|
/**
|
|
* UpdateRemarkLogic constructor.
|
|
* @param CanUpdateRemark $canUpdateRemark
|
|
* @param UpdatesRemark $updatesRemark
|
|
* @param FetchesRemark $fetchesRemark
|
|
* @param FetchesDistrict $fetchesDistrict
|
|
*/
|
|
public function __construct(CanUpdateRemark $canUpdateRemark, UpdatesRemark $updatesRemark, FetchesRemark $fetchesRemark, FetchesDistrict $fetchesDistrict)
|
|
{
|
|
$this->canUpdateRemark = $canUpdateRemark;
|
|
$this->updatesRemark = $updatesRemark;
|
|
$this->fetchesRemark = $fetchesRemark;
|
|
$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 RemarkObject($request->input('street_one'), $request->input('street_two'), $district->country_id, $district->state_id, $district->id, $request->input('post_code'));
|
|
//$object = new RemarkObject($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->canUpdateRemark->passes($object);
|
|
|
|
$query = $this->fetchesRemark->execute(['id' => $request->route('id')]);
|
|
|
|
$query = $this->updatesRemark->execute($query, $object);
|
|
|
|
return $this->resourceResponse(new RemarkResource($query));
|
|
|
|
|
|
} catch (\Exception $exception){
|
|
throw new ErrorException($exception->getMessage(), $exception->getCode());
|
|
}
|
|
|
|
}
|
|
|
|
}
|