mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 12:33:56 +00:00
64 lines
1.6 KiB
PHP
64 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\Modules\Accounts\ControllersLogic;
|
|
|
|
use App\Classes\Modules\Accounts\Services\FetchesUser;
|
|
use App\Classes\Modules\Accounts\Standards\Rules\CanFetchUser;
|
|
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
|
use App\Http\Resources\UserResource;
|
|
use ErrorException;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
|
|
class FetchUserLogic extends AbstractControllerLogic
|
|
{
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
protected function notification():array {
|
|
return [
|
|
'title' => 'Fetch Users',
|
|
'message' => 'You have successfully retrieved the user'
|
|
];
|
|
}
|
|
|
|
/** @var CanFetchUser */
|
|
private $canFetchUser;
|
|
|
|
/** @var FetchesUser */
|
|
private $fetchessUser;
|
|
|
|
/**
|
|
* FetchUserLogic constructor.
|
|
* @param CanFetchUser $canFetchUser
|
|
* @param FetchesUser $fetchessUser
|
|
*/
|
|
public function __construct(CanFetchUser $canFetchUser, FetchesUser $fetchessUser)
|
|
{
|
|
$this->canFetchUser = $canFetchUser;
|
|
$this->fetchessUser = $fetchessUser;
|
|
}
|
|
|
|
/**
|
|
* @param Request $request
|
|
* @return JsonResponse
|
|
* @throws ErrorException
|
|
*/
|
|
public function logic(Request $request) : JsonResponse
|
|
{
|
|
try {
|
|
|
|
$this->canFetchUser->passes();
|
|
|
|
$query = $this->fetchessUser->execute(['id' => $request->input('user_id')]);
|
|
|
|
return $this->collectionResponse(UserResource::collection($query));
|
|
|
|
|
|
} catch (\Exception $exception){
|
|
throw new ErrorException($exception->getMessage(), $exception->getCode());
|
|
}
|
|
}
|
|
|
|
} |