mirror of
https://gitlab.com/uldvstar/exchange-2.0.git
synced 2026-08-19 04:24:16 +00:00
1dfb75545f
Fetch Currency Rate Logic Class Create Currency Rate Logic Class Update Currency Rate Logic Class Currency Rate Converter Rate
67 lines
1.9 KiB
PHP
67 lines
1.9 KiB
PHP
<?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());
|
|
}
|
|
|
|
}
|
|
|
|
} |