mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 20:43:56 +00:00
00994d6ac1
Update create section api to support type
65 lines
1.9 KiB
PHP
65 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\Modules\Segments\ControllersLogic;
|
|
|
|
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
|
|
|
use App\Classes\Modules\Segments\Standards\Rules\CanCreateSegment;
|
|
use App\Classes\Modules\Segments\Services\CreatesSegment;
|
|
use App\Classes\Modules\Segments\DataTransferObjects\SegmentObject;
|
|
use App\Http\Resources\SegmentResource;
|
|
|
|
use ErrorException;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class CreateSegmentLogic extends AbstractControllerLogic
|
|
{
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
protected function notification():array {
|
|
return [
|
|
'title' => 'Created Segment',
|
|
'message' => 'You have successfully created a new Segment'
|
|
];
|
|
}
|
|
|
|
/** @var CanCreateSegment */
|
|
private $canCreateSegment;
|
|
|
|
/** @var CreatesSegment */
|
|
private $createsSegment;
|
|
|
|
|
|
/**
|
|
* CreateSegmentLogic constructor.
|
|
* @param CanCreateSegment $canCreateSegment
|
|
* @param CreatesSegment $createsSegment
|
|
*/
|
|
public function __construct(CanCreateSegment $canCreateSegment, CreatesSegment $createsSegment)
|
|
{
|
|
$this->canCreateSegment = $canCreateSegment;
|
|
$this->createsSegment = $createsSegment;
|
|
}
|
|
|
|
/**
|
|
* @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_object = new SegmentObject($request->input('name'), $request->input('type') ?? 2);
|
|
|
|
$this->canCreateSegment->passes($segment_object);
|
|
$segment = $this->createsSegment->execute($segment_object);
|
|
|
|
return $this->resourceResponse(new SegmentResource($segment));
|
|
|
|
}
|
|
} |