mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 04:23:55 +00:00
104 lines
3.4 KiB
PHP
104 lines
3.4 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\Segments\Services\FetchesSegment;
|
|
|
|
use App\Classes\Modules\SegmentConstants\Standards\Rules\CanCreateSegmentConstant;
|
|
|
|
use App\Classes\Modules\SegmentConstants\Services\CreatesSegmentConstant;
|
|
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 CreateSegmentConstantLogic extends AbstractControllerLogic
|
|
{
|
|
/**
|
|
* @return array
|
|
*/
|
|
protected function notification():array {
|
|
return [
|
|
'title' => 'Created Segment Constant',
|
|
'message' => 'You have successfully created a new Segment Constant'
|
|
];
|
|
}
|
|
|
|
/** @var CanCreateSegmentConstant */
|
|
private $canCreateSegmentConstant;
|
|
|
|
/** @var CreatesSegmentConstant */
|
|
private $createsSegmentConstant;
|
|
|
|
/** @var FetchesSegmentConstant */
|
|
private $fetchesSegmentConstant;
|
|
|
|
/** @var FetchesSegment */
|
|
private $fetchesSegment;
|
|
|
|
/**
|
|
* CreateSegmentConstantLogic constructor.
|
|
* @param CanCreateSegmentConstant $canCreateSegmentConstant
|
|
* @param createsSegmentConstant $createsSegmentConstantTax
|
|
* @param FetchesSegmentConstant $fetchesSegmentConstant
|
|
* @param FetchesSegment $fetchesSegment
|
|
*/
|
|
public function __construct(
|
|
CanCreateSegmentConstant $canCreateSegmentConstant,
|
|
CreatesSegmentConstant $createsSegmentConstant,
|
|
FetchesSegmentConstant $fetchesSegmentConstant,
|
|
FetchesSegment $fetchesSegment
|
|
)
|
|
{
|
|
$this->canCreateSegmentConstant = $canCreateSegmentConstant;
|
|
$this->createsSegmentConstant = $createsSegmentConstant;
|
|
$this->fetchesSegmentConstant = $fetchesSegmentConstant;
|
|
$this->fetchesSegment = $fetchesSegment;
|
|
}
|
|
|
|
/**
|
|
* @param Request $request
|
|
* @return JsonResponse
|
|
* @throws ErrorException
|
|
*/
|
|
public function logic(Request $request) : JsonResponse
|
|
{
|
|
try {
|
|
DB::beginTransaction();
|
|
|
|
$segment_query = $this->fetchesSegment->execute([
|
|
'id' => $request->input('segment_id'),
|
|
]);
|
|
|
|
$standard_segment_constant_query = $this->fetchesSegmentConstant->execute([
|
|
'id' => $request->input('standard_segment_constant_id'),
|
|
]);
|
|
|
|
$segment_constant_object = new SegmentConstantObject(
|
|
$request->input('segment_id'),
|
|
$standard_segment_constant_query->name,
|
|
$standard_segment_constant_query->reference,
|
|
$standard_segment_constant_query->detail->type,
|
|
$request->input('detail')
|
|
);
|
|
|
|
$this->canCreateSegmentConstant->passes($segment_constant_object);
|
|
$standard_segment_constant_query = $this->createsSegmentConstant->execute($segment_query, $segment_constant_object);
|
|
|
|
DB::commit();
|
|
|
|
return $this->resourceResponse(new SegmentConstantResource($standard_segment_constant_query));
|
|
|
|
} catch (\Exception $exception) {
|
|
throw new ErrorException($exception->getMessage(), $exception->getCode());
|
|
}
|
|
|
|
}
|
|
} |