mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 04:23:55 +00:00
92 lines
2.9 KiB
PHP
92 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\Modules\SegmentConstants\ControllersLogic;
|
|
|
|
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
|
|
|
use App\Classes\Modules\SegmentConstants\Services\FetchesSegmentConstant;
|
|
|
|
use App\Classes\Modules\SegmentConstants\Standards\Rules\CanUpdateSegmentConstant;
|
|
|
|
use App\Classes\Modules\SegmentConstants\Services\UpdatesSegmentConstant;
|
|
use App\Classes\Modules\SegmentConstants\DataTransferObjects\SegmentConstantObject;
|
|
|
|
use App\Http\Resources\SegmentConstantResource;
|
|
|
|
use ErrorException;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class UpdateSegmentConstantLogic extends AbstractControllerLogic
|
|
{
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
protected function notification():array {
|
|
return [
|
|
'title' => 'Updated Segment Constant',
|
|
'message' => 'You have successfully updated the Segment Constant'
|
|
];
|
|
}
|
|
|
|
/** @var CanUpdateSegmentConstant */
|
|
private $canUpdateSegmentConstant;
|
|
|
|
/** @var UpdatesSegmentConstant */
|
|
private $updatesSegmentConstant;
|
|
|
|
/** @var FetchesSegmentConstant */
|
|
private $fetchesSegmentConstant;
|
|
|
|
/**
|
|
* UpdateStandardSegmentConstantLogic constructor.
|
|
* @param CanUpdateSegmentConstant $canUpdateSegmentConstant
|
|
* @param UpdatesSegmentConstant $updatesSegmentConstant
|
|
* @param FetchesSegmentConstant $fetchesSegmentConstant
|
|
*/
|
|
public function __construct(
|
|
CanUpdateSegmentConstant $canUpdateSegmentConstant,
|
|
UpdatesSegmentConstant $updatesSegmentConstant,
|
|
FetchesSegmentConstant $fetchesSegmentConstant
|
|
)
|
|
{
|
|
$this->canUpdateSegmentConstant = $canUpdateSegmentConstant;
|
|
$this->updatesSegmentConstant = $updatesSegmentConstant;
|
|
$this->fetchesSegmentConstant = $fetchesSegmentConstant;
|
|
}
|
|
|
|
/**
|
|
* @param Request $request
|
|
* @return JsonResponse
|
|
* @throws ErrorException
|
|
*/
|
|
public function logic(Request $request) : JsonResponse
|
|
{
|
|
try {
|
|
DB::beginTransaction();
|
|
|
|
$segment_constant_query = $this->fetchesSegmentConstant->execute(['id' => $request->route('id')]);
|
|
|
|
$segment_constant_object = new SegmentConstantObject(
|
|
$segment_constant_query->segment_id,
|
|
$segment_constant_query->name,
|
|
$segment_constant_query->reference,
|
|
$segment_constant_query->detail->type,
|
|
$request->input('detail')
|
|
);
|
|
|
|
$this->canUpdateSegmentConstant->passes($segment_constant_object);
|
|
$segment_constant_query = $this->updatesSegmentConstant->execute($segment_constant_query, $segment_constant_object);
|
|
|
|
DB::commit();
|
|
|
|
return $this->resourceResponse(new SegmentConstantResource($segment_constant_query));
|
|
|
|
} catch (\Exception $exception){
|
|
throw new ErrorException($exception->getMessage(), $exception->getCode());
|
|
}
|
|
}
|
|
|
|
} |