mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/portal.git
synced 2026-08-19 04:23:59 +00:00
67 lines
1.7 KiB
PHP
67 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\Modules\Companies\ControllersLogic;
|
|
|
|
|
|
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
|
use App\Classes\Modules\Companies\Services\FetchesCompany;
|
|
use App\Classes\Modules\Companies\Standards\Rules\CanFetchCompany;
|
|
use App\Classes\Modules\Companies\DataTransferObjects\CompanyObject;
|
|
use App\Http\Resources\CompanyResource;
|
|
use ErrorException;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
|
|
class FetchCompanyLogic extends AbstractControllerLogic
|
|
{
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
protected function notification():array {
|
|
return [
|
|
'title' => 'Retrieved Company',
|
|
'message' => 'You have successfully retrieved a Company'
|
|
];
|
|
}
|
|
|
|
/** @var CanFetchCompany */
|
|
private $canFetchCompany;
|
|
|
|
/** @var FetchesCompany */
|
|
private $fetchesCompany;
|
|
|
|
/**
|
|
* FetchCompanyControllerLogic constructor.
|
|
* @param CanFetchCompany $canFetchCompany
|
|
* @param FetchesCompany $fetchesCompany
|
|
*/
|
|
public function __construct(CanFetchCompany $canFetchCompany, FetchesCompany $fetchesCompany)
|
|
{
|
|
$this->canFetchCompany = $canFetchCompany;
|
|
$this->fetchesCompany = $fetchesCompany;
|
|
}
|
|
|
|
|
|
/**
|
|
* @param Request $request
|
|
* @return JsonResponse
|
|
* @throws ErrorException
|
|
*/
|
|
public function logic(Request $request) : JsonResponse
|
|
{
|
|
try {
|
|
|
|
$this->canFetchCompany->passes();
|
|
|
|
$query = $this->fetchesCompany->execute(['id' => $request->route('id')]);
|
|
|
|
return $this->resourceResponse(new CompanyResource($query));
|
|
|
|
} catch (\Exception $exception){
|
|
throw new ErrorException($exception->getMessage(), $exception->getCode());
|
|
}
|
|
|
|
}
|
|
|
|
} |