mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 04:23:55 +00:00
1dfb75545f
Fetch Currency Rate Logic Class Create Currency Rate Logic Class Update Currency Rate Logic Class Currency Rate Converter Rate
99 lines
3.1 KiB
PHP
99 lines
3.1 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\Modules\CurrencyRates\ControllersLogic;
|
|
|
|
use App\Classes\General\Abstracts\AbstractControllersLogic;
|
|
|
|
use App\Classes\Modules\Currencies\Services\FetchesCurrency;
|
|
|
|
use App\Classes\Modules\CurrencyRates\Standards\Rules\CanCreateCurrencyRate;
|
|
use App\Classes\Modules\CurrencyRates\Services\CreatesCurrencyRate;
|
|
use App\Classes\Modules\Currencies\Services\CreatesCurrencyRateLog;
|
|
use App\Classes\Modules\CurrencyRates\DataTransferObjects\CurrencyRateObject;
|
|
|
|
use App\Http\Resources\CurrencyRateResource;
|
|
|
|
use ErrorException;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class CreateCurrencyRateLogic extends AbstractControllersLogic
|
|
{
|
|
/**
|
|
* @return array
|
|
*/
|
|
protected function notification():array {
|
|
return [
|
|
'title' => 'Created Currency Rate',
|
|
'message' => 'You have successfully created a new Currency Rate'
|
|
];
|
|
}
|
|
|
|
/** @var CanCreateCurrencyRate */
|
|
private $canCreateCurrencyRate;
|
|
|
|
/** @var CreatesCurrencyRate */
|
|
private $createsCurrencyRate;
|
|
|
|
/** @var CreatesCurrencyRateLog */
|
|
private $createsCurrencyRateLog;
|
|
|
|
/** @var FetchesCurrency */
|
|
private $fetchesCurrency;
|
|
|
|
/**
|
|
* CreateCurrencyRateLogic constructor.
|
|
* @param CanCreateCurrencyRate $canCreateCurrencyRate
|
|
* @param CreatesCurrencyRate $createsCurrencyRate
|
|
* @param FetchesCurrency $fetchesCurrency
|
|
*/
|
|
public function __construct(
|
|
CanCreateCurrencyRate $canCreateCurrencyRate,
|
|
CreatesCurrencyRate $createsCurrencyRate,
|
|
CreatesCurrencyRateLog $createsCurrencyRateLog,
|
|
FetchesCurrency $fetchesCurrency
|
|
)
|
|
{
|
|
$this->canCreateCurrencyRate = $canCreateCurrencyRate;
|
|
$this->createsCurrencyRate = $createsCurrencyRate;
|
|
$this->createsCurrencyRateLog = $createsCurrencyRateLog;
|
|
$this->fetchesCurrency = $fetchesCurrency;
|
|
}
|
|
|
|
/**
|
|
* @param Request $request
|
|
* @return JsonResponse
|
|
* @throws ErrorException
|
|
*/
|
|
public function logic(Request $request) : JsonResponse
|
|
{
|
|
try {
|
|
DB::beginTransaction();
|
|
|
|
$currency_query = $this->fetchesCurrency->execute([
|
|
'id' => $request->input('currency_id', 1),
|
|
]);
|
|
|
|
$currency_rate_object = new CurrencyRateObject(
|
|
$request->input('currency_id'),
|
|
number_format( (float) $request->input('selling'), 5, '.', ''),
|
|
$request->input('payment_method_type')
|
|
);
|
|
|
|
$this->canCreateCurrencyRate->passes($currency_rate_object);
|
|
$currency_rate_query = $this->createsCurrencyRate->execute($currency_rate_object);
|
|
|
|
$currency_rate_log_query = $this->createsCurrencyRateLog->execute($currency_rate_query);
|
|
|
|
DB::commit();
|
|
|
|
return $this->resourceResponse(new CurrencyRateResource($currency_rate_query));
|
|
|
|
} catch (\Exception $exception) {
|
|
dd($exception);
|
|
throw new ErrorException($exception->getMessage(), $exception->getCode());
|
|
}
|
|
|
|
}
|
|
} |