mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/portal.git
synced 2026-08-19 04:23:59 +00:00
87 lines
3.1 KiB
PHP
87 lines
3.1 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\Modules\Segments\ControllersLogic;
|
|
|
|
use Illuminate\Http\Request;
|
|
use App\Models\SegmentConstant;
|
|
use Illuminate\Http\JsonResponse;
|
|
use App\Http\Resources\ConstantResource;
|
|
use App\Classes\ValueObjects\Constants\SegmentConstants;
|
|
use App\Classes\Modules\Segments\Services\FetchesSegment;
|
|
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
|
use App\Classes\Modules\Segments\Services\FetchesConstant;
|
|
use App\Classes\Modules\Segments\Services\UpdatesConstant;
|
|
use App\Classes\Modules\Segments\Standards\Rules\CanUpdateConstant;
|
|
use App\Classes\Modules\Segments\DataTransferObjects\ConstantObject;
|
|
use App\Classes\Modules\Segments\Services\UpdatesConstantValueByState;
|
|
|
|
class UpdateConstantStateLogic extends AbstractControllerLogic
|
|
{
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
protected function notification():array {
|
|
return [
|
|
'title' => 'Updated Segment Constant',
|
|
'message' => 'You have successfully updated the Segment Constant'
|
|
];
|
|
}
|
|
|
|
/** @var CanUpdateConstant */
|
|
private $canUpdateConstant;
|
|
|
|
/** @var UpdatesConstant */
|
|
private $updatesConstant;
|
|
|
|
/** @var FetchesSegment */
|
|
private $fetchesSegment;
|
|
|
|
/** @var FetchesConstant */
|
|
private $fetchesConstant;
|
|
|
|
/** @var UpdatesConstantValueByState */
|
|
private $updatesConstantValueByState;
|
|
|
|
|
|
/**
|
|
* UpdateConstantLogic constructor.
|
|
* @param CanUpdateConstant $canUpdateConstant
|
|
* @param UpdatesConstant $updatesConstant
|
|
* @param FetchesSegment $fetchesSegment
|
|
* @param FetchesConstant $fetchesConstant
|
|
* @param UpdatesConstantValueByState $updatesConstantValueByState
|
|
*/
|
|
public function __construct(CanUpdateConstant $canUpdateConstant, UpdatesConstant $updatesConstant, FetchesSegment $fetchesSegment, FetchesConstant $fetchesConstant,UpdatesConstantValueByState $updatesConstantValueByState)
|
|
{
|
|
$this->canUpdateConstant = $canUpdateConstant;
|
|
$this->updatesConstant = $updatesConstant;
|
|
$this->fetchesSegment = $fetchesSegment;
|
|
$this->fetchesConstant = $fetchesConstant;
|
|
$this->updatesConstantValueByState = $updatesConstantValueByState;
|
|
}
|
|
/**
|
|
* @param Request $request
|
|
* @return JsonResponse
|
|
* @throws \App\Classes\Exceptions\AccessForbiddenException
|
|
* @throws \App\Classes\Exceptions\MalformedRequestException
|
|
* @throws \App\Classes\Exceptions\RequestValidationException
|
|
*/
|
|
public function logic(Request $request) : JsonResponse
|
|
{
|
|
$segment = $this->fetchesSegment->execute(['id' => $request->route('id')]);
|
|
|
|
$constant = $this->fetchesConstant->execute(['segment_id' => $segment->id, 'reference' => SegmentConstants::STATE_RATE]);
|
|
|
|
$constantValue = $this->updatesConstantValueByState->execute($constant->value, $request->input('status_id'), $request->input('rate'));
|
|
|
|
$object = new ConstantObject(SegmentConstants::STATE_RATE, (array) $constantValue);
|
|
$this->canUpdateConstant->passes($object);
|
|
|
|
$constant = $this->updatesConstant->execute($constant, $object);
|
|
|
|
|
|
return $this->resourceResponse(new ConstantResource($constant));
|
|
}
|
|
|
|
} |