Files
exchange-2.0/app/Classes/Modules/Segments/ControllersLogic/FetchSegmentLogic.php
T
omair saleh 05401f6bbc large commit
2021-03-11 13:06:40 +08:00

59 lines
1.6 KiB
PHP

<?php
namespace App\Classes\Modules\Segments\ControllersLogic;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Segments\Standards\Rules\CanFetchSegment;
use App\Classes\Modules\Segments\Services\FetchesSegment;
use App\Http\Resources\SegmentResource;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class FetchSegmentLogic extends AbstractControllerLogic
{
/**
* @return array
*/
protected function notification():array {
return [
'title' => 'Retrieved Segment',
'message' => 'You have successfully retrieved a segment'
];
}
/** @var CanFetchSegment */
private $canFetchSegment;
/** @var FetchesSegment */
private $fetchesSegment;
/**
* FetchSegmentLogic constructor.
* @param CanFetchSegment $canFetchSegment
* @param FetchesSegment $fetchesSegment
*/
public function __construct(CanFetchSegment $canFetchSegment, FetchesSegment $fetchesSegment)
{
$this->canFetchSegment = $canFetchSegment;
$this->fetchesSegment = $fetchesSegment;
}
/**
* @param Request $request
* @return JsonResponse
* @throws \App\Classes\Exceptions\AccessForbiddenException
* @throws \App\Classes\Exceptions\RequestValidationException
*/
public function logic(Request $request) : JsonResponse
{
$this->canFetchSegment->passes();
$query = $this->fetchesSegment->execute(['id' => $request->route('id')]);
return $this->resourceResponse(new SegmentResource($query));
}
}