mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-21 21:43:57 +00:00
dec78bf8d7
Update Currency Selling Logic Class Delete Currency Selling Logic Class Create Currency Log Service Class
98 lines
3.0 KiB
PHP
98 lines
3.0 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\Modules\Currencies\ControllersLogic;
|
|
|
|
use App\Http\Resources\CurrencyResource;
|
|
|
|
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
|
|
|
use App\Classes\Modules\Currencies\Services\FetchesCurrency;
|
|
|
|
use App\Classes\Modules\Currencies\Standards\Rules\CanUpdateCurrency;
|
|
use App\Classes\Modules\Currencies\Services\UpdatesCurrencyRate;
|
|
use App\Classes\Modules\Currencies\Services\CreatesCurrencyLog;
|
|
use App\Classes\Modules\Currencies\DataTransferObjects\CurrencyObject;
|
|
|
|
use ErrorException;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class UpdateCurrencyRateLogic extends AbstractControllerLogic
|
|
{
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
protected function notification():array {
|
|
return [
|
|
'title' => 'Updated Currency Rate',
|
|
'message' => 'You have successfully updated the Currency Rate'
|
|
];
|
|
}
|
|
|
|
/** @var CanUpdateCurrency */
|
|
private $canUpdateCurrency;
|
|
|
|
/** @var UpdatesCurrencyRate */
|
|
private $updatesCurrencyRate;
|
|
|
|
/** @var FetchesCurrency */
|
|
private $fetchesCurrency;
|
|
|
|
/** @var CreatesCurrencyLog */
|
|
private $createsCurrencyLog;
|
|
|
|
/**
|
|
* UpdateStandardSegmentConstantLogic constructor.
|
|
* @param CanUpdateCurrency $canUpdateCurrency
|
|
* @param UpdatesCurrencyRate $updatesCurrencyRate
|
|
* @param FetchesCurrency $fetchesCurrency
|
|
*/
|
|
public function __construct(
|
|
CanUpdateCurrency $canUpdateCurrency,
|
|
UpdatesCurrencyRate $updatesCurrencyRate,
|
|
CreatesCurrencyLog $createsCurrencyLog,
|
|
FetchesCurrency $fetchesCurrency
|
|
)
|
|
{
|
|
$this->canUpdateCurrency = $canUpdateCurrency;
|
|
$this->updatesCurrencyRate = $updatesCurrencyRate;
|
|
$this->createsCurrencyLog = $createsCurrencyLog;
|
|
$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->route('id')]);
|
|
|
|
$currency_object = new CurrencyObject(
|
|
$currency_query->country_id,
|
|
$currency_query->name,
|
|
$currency_query->short_code,
|
|
$currency_query->symbol,
|
|
$request->input('selling', $currency_query->selling)
|
|
);
|
|
$this->canUpdateCurrency->passes($currency_object);
|
|
$currency_query = $this->updatesCurrencyRate->execute($currency_query, $currency_object);
|
|
|
|
$currency_log_query = $this->createsCurrencyLog->execute($currency_query);
|
|
|
|
DB::commit();
|
|
|
|
return $this->resourceResponse(new CurrencyResource($currency_query));
|
|
|
|
} catch (\Exception $exception){
|
|
throw new ErrorException($exception->getMessage(), $exception->getCode());
|
|
}
|
|
}
|
|
|
|
} |