mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-09-01 02:43:58 +00:00
List Currency Rate Logic Class
Fetch Currency Rate Logic Class Create Currency Rate Logic Class Update Currency Rate Logic Class Currency Rate Converter Rate
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\CurrencyRates\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllersLogic;
|
||||
use App\Classes\Modules\CurrencyRates\Services\FetchesCurrencyRate;
|
||||
use App\Classes\Modules\CurrencyRates\Standards\Rules\CanFetchCurrencyRate;
|
||||
use App\Classes\Modules\CurrencyRates\DataTransferObjects\CurrencyRateObject;
|
||||
use App\Http\Resources\CurrencyRateResource;
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class FetchCurrencyRateLogic extends AbstractControllersLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Retrieved Currency Rate',
|
||||
'message' => 'You have successfully retrieved a Currency Rate'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CanFetchCurrencyRate */
|
||||
private $canFetchCurrencyRate;
|
||||
|
||||
/** @var FetchesCurrencyRate */
|
||||
private $fetchesCurrencyRate;
|
||||
|
||||
/**
|
||||
* FetchCurrencyRateControllersLogic constructor.
|
||||
* @param CanFetchCurrencyRate $canFetchCurrencyRate
|
||||
* @param FetchesCurrencyRate $fetchesCurrencyRate
|
||||
*/
|
||||
public function __construct(CanFetchCurrencyRate $canFetchCurrencyRate, FetchesCurrencyRate $fetchesCurrencyRate)
|
||||
{
|
||||
$this->canFetchCurrencyRate = $canFetchCurrencyRate;
|
||||
$this->fetchesCurrencyRate = $fetchesCurrencyRate;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws ErrorException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
try {
|
||||
|
||||
$this->canFetchCurrencyRate->passes();
|
||||
|
||||
$query = $this->fetchesCurrencyRate->execute(['id' => $request->route('id')]);
|
||||
|
||||
return $this->resourceResponse(new CurrencyRateResource($query));
|
||||
|
||||
} catch (\Exception $exception){
|
||||
throw new ErrorException($exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user