mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 04:23:55 +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,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class CurrencyId implements Filter
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return Builder|mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->where('currency_id', $value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class PaymentMethodType implements Filter
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return Builder|mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->where('payment_method_type', $value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -67,8 +67,7 @@ class CreateCurrencyLogic extends AbstractControllersLogic
|
||||
$request->input('country_id'),
|
||||
$request->input('name'),
|
||||
$request->input('short_code'),
|
||||
$request->input('symbol'),
|
||||
number_format( (float) $request->input('selling'), 5, '.', '')
|
||||
$request->input('symbol')
|
||||
);
|
||||
$this->canCreateCurrency->passes($currency_object);
|
||||
$currency_query = $this->createsCurrency->execute($currency_object);
|
||||
|
||||
@@ -57,6 +57,7 @@ class ListCurrencyLogic extends AbstractControllersLogic
|
||||
return $this->collectionResponse(CurrencyResource::collection($query));
|
||||
|
||||
} catch (\Exception $exception){
|
||||
dd($exception);
|
||||
throw new ErrorException($exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
|
||||
|
||||
@@ -1,99 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Currencies\ControllersLogic;
|
||||
|
||||
use App\Http\Resources\CurrencyResource;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllersLogic;
|
||||
|
||||
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 AbstractControllersLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @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 CreatesCurrencyLog $createsCurrencyLog
|
||||
* @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());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -11,7 +11,6 @@ class CurrencyObject implements DataTransferObject
|
||||
private $name;
|
||||
private $short_code;
|
||||
private $symbol;
|
||||
private $selling;
|
||||
|
||||
|
||||
/**
|
||||
@@ -20,21 +19,18 @@ class CurrencyObject implements DataTransferObject
|
||||
* @param null|string $name
|
||||
* @param null|string $short_code
|
||||
* @param null|string $symbol
|
||||
* @param float|null $selling
|
||||
*/
|
||||
public function __construct(
|
||||
?int $country_id,
|
||||
?string $name,
|
||||
?string $short_code,
|
||||
?string $symbol,
|
||||
?float $selling
|
||||
?string $symbol
|
||||
)
|
||||
{
|
||||
$this->country_id = $country_id;
|
||||
$this->name = $name;
|
||||
$this->short_code = $short_code;
|
||||
$this->symbol = $symbol;
|
||||
$this->selling = $selling;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -68,12 +64,4 @@ class CurrencyObject implements DataTransferObject
|
||||
{
|
||||
return $this->symbol;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float
|
||||
*/
|
||||
public function getSelling(): ?float
|
||||
{
|
||||
return $this->selling;
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,6 @@ class CreatesCurrency extends AbstractUpdateRecord
|
||||
$model->name = $object->getName();
|
||||
$model->short_code = $object->getShortCode();
|
||||
$model->symbol = $object->getSymbol();
|
||||
$model->selling = $object->getSelling();
|
||||
return $this->handler($model);
|
||||
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ class CurrencyValidation extends AbstractValidation
|
||||
'name' => $object->getName(),
|
||||
'short_code' => $object->getShortCode(),
|
||||
'symbol' => $object->getSymbol(),
|
||||
'selling' => $object->getSelling()
|
||||
];
|
||||
}
|
||||
|
||||
@@ -32,7 +31,6 @@ class CurrencyValidation extends AbstractValidation
|
||||
'name' => 'required',
|
||||
'short_code' => 'required',
|
||||
'short_code' => 'required',
|
||||
'selling' => 'required',
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
<?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\Services\CalculatesCurrencyRate;
|
||||
|
||||
use App\Http\Resources\CalculateCurrencyRateResource;
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class CalculateCurrencyRateLogic extends AbstractControllersLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Calculated Currency Rate',
|
||||
'message' => 'You have successfully rate calculated a Currency'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var FetchesCurrencyRate */
|
||||
private $fetchesCurrencyRate;
|
||||
|
||||
/** @var CalculatesCurrencyRate */
|
||||
private $calculatesCurrencyRate;
|
||||
|
||||
/**
|
||||
* @param CanListStandardSegmentConstants $canListStandardSegmentConstants
|
||||
* @param FetchesCurrencyRate $fetchesCurrencyRate
|
||||
* @param CalculatesCurrencyRate $calculatesCurrencyRate
|
||||
*/
|
||||
public function __construct(FetchesCurrencyRate $fetchesCurrencyRate, CalculatesCurrencyRate $calculatesCurrencyRate)
|
||||
{
|
||||
$this->fetchesCurrencyRate = $fetchesCurrencyRate;
|
||||
$this->calculatesCurrencyRate = $calculatesCurrencyRate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws ErrorException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
try {
|
||||
$amount = $request->input('amount');
|
||||
$conversion_currency_rate = $this->fetchesCurrencyRate->execute(
|
||||
[
|
||||
'id' => $request->input('conversion_currency_rate_id'),
|
||||
]
|
||||
);
|
||||
$convertable_currency_rate = $this->fetchesCurrencyRate->execute(
|
||||
[
|
||||
'id' => $request->input('convertable_currency_rate_id')
|
||||
]
|
||||
);
|
||||
|
||||
$convert_amount = $this->calculatesCurrencyRate->execute($conversion_currency_rate, $convertable_currency_rate, $amount);
|
||||
|
||||
return $this->resourceResponse(new CalculateCurrencyRateResource($conversion_currency_rate, $convertable_currency_rate, $convert_amount));
|
||||
|
||||
} catch (\Exception $exception){
|
||||
throw new ErrorException($exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
<?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());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\CurrencyRates\ControllersLogic;
|
||||
|
||||
use App\Http\Resources\CurrencyRateResource;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllersLogic;
|
||||
|
||||
use App\Classes\Modules\CurrencyRates\Services\FetchesCurrencyRate;
|
||||
|
||||
use App\Classes\Modules\CurrencyRates\Standards\Rules\CanDeleteCurrencyRate;
|
||||
use App\Classes\Modules\CurrencyRates\Services\DeletesCurrencyRate;
|
||||
use App\Classes\Modules\CurrencyRates\DataTransferObjects\SegmentObject;
|
||||
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class DeleteCurrencyRateLogic extends AbstractControllersLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Delete Currency Rate',
|
||||
'message' => 'You have successfully deleted the Currency Rate'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CanDeleteCurrencyRate */
|
||||
private $canDeleteCurrencyRate;
|
||||
|
||||
/** @var DeletesCurrencyRate */
|
||||
private $deletesCurrencyRate;
|
||||
|
||||
/** @var FetchesCurrencyRate */
|
||||
private $fetchesCurrencyRate;
|
||||
|
||||
|
||||
/**
|
||||
* DeleteCurrencyRateRateLogic constructor.
|
||||
* @param CanDeleteCurrencyRate $canDeleteCurrencyRate
|
||||
* @param DeletesCurrencyRate $deletesCurrencyRate
|
||||
* @param FetchesCurrencyRate $fetchesCurrencyRate
|
||||
*/
|
||||
public function __construct(
|
||||
CanDeleteCurrencyRate $canDeleteCurrencyRate,
|
||||
DeletesCurrencyRate $deletesCurrencyRate,
|
||||
FetchesCurrencyRate $fetchesCurrencyRate
|
||||
)
|
||||
{
|
||||
$this->canDeleteCurrencyRate = $canDeleteCurrencyRate;
|
||||
$this->deletesCurrencyRate = $deletesCurrencyRate;
|
||||
$this->fetchesCurrencyRate = $fetchesCurrencyRate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws ErrorException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
$currency_rate = $this->fetchesCurrencyRate->execute(['id' => $request->route('id')]);
|
||||
$this->canDeleteCurrencyRate->passes();
|
||||
$this->deletesCurrencyRate->execute($currency_rate);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return $this->resourceResponse(new CurrencyRateResource($currency_rate));
|
||||
|
||||
} catch (\Exception $exception){
|
||||
throw new ErrorException($exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\CurrencyRates\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllersLogic;
|
||||
use App\Classes\Modules\CurrencyRates\Services\ListsCurrencyRates;
|
||||
use App\Classes\Modules\CurrencyRates\Standards\Rules\CanListCurrencyRates;
|
||||
use App\Http\Resources\CurrencyRateResource;
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ListCurrencyRatesLogic extends AbstractControllersLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Retrieved Currency Rate',
|
||||
'message' => 'You have successfully retrieved a list of Currency Rate'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CanListCurrencyRates */
|
||||
private $canListCurrencyRates;
|
||||
|
||||
/** @var ListsCurrencyRates */
|
||||
private $listsCurrencyRates;
|
||||
|
||||
/**
|
||||
* ListCurrencyRatesLogic constructor.
|
||||
* @param CanListCurrencyRates $canListCurrencyRates
|
||||
* @param ListsCurrencyRates $listsCurrencyRates
|
||||
*/
|
||||
public function __construct(CanListCurrencyRates $canListCurrencyRates, ListsCurrencyRates $listsCurrencyRates)
|
||||
{
|
||||
$this->canListCurrencyRates = $canListCurrencyRates;
|
||||
$this->listsCurrencyRates = $listsCurrencyRates;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws ErrorException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
try {
|
||||
$this->canListCurrencyRates->passes();
|
||||
|
||||
$query = $this->listsCurrencyRates->execute(
|
||||
[
|
||||
'currency_id' => $request->input('currency_id'),
|
||||
'payment_method_type' => $request->input('payment_method_type')
|
||||
]
|
||||
);
|
||||
|
||||
return $this->collectionResponse(CurrencyRateResource::collection($query));
|
||||
|
||||
} catch (\Exception $exception){
|
||||
throw new ErrorException($exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
<?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\CanUpdateCurrencyRate;
|
||||
|
||||
use App\Classes\Modules\CurrencyRates\Services\UpdatesCurrencyRate;
|
||||
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 UpdateCurrencyRateLogic extends AbstractControllersLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Updated Currency Rate',
|
||||
'message' => 'You have successfully updated the Currency Rate'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CanUpdateCurrencyRate */
|
||||
private $canUpdateCurrencyRate;
|
||||
|
||||
/** @var UpdatesCurrencyRate */
|
||||
private $updatesCurrencyRate;
|
||||
|
||||
/** @var CreatesCurrencyRateLog */
|
||||
private $createsCurrencyRateLog;
|
||||
|
||||
/** @var FetchesCurrencyRate */
|
||||
private $fetchesCurrencyRate;
|
||||
|
||||
/**
|
||||
* UpdateStandardCurrencyRateLogic constructor.
|
||||
* @param CanUpdateCurrencyRate $canUpdateCurrencyRate
|
||||
* @param UpdatesCurrencyRate $updatesCurrencyRate
|
||||
* @param FetchesCurrencyRate $fetchesCurrencyRate
|
||||
*/
|
||||
public function __construct(
|
||||
CanUpdateCurrencyRate $canUpdateCurrencyRate,
|
||||
UpdatesCurrencyRate $updatesCurrencyRate,
|
||||
CreatesCurrencyRateLog $createsCurrencyRateLog,
|
||||
FetchesCurrencyRate $fetchesCurrencyRate
|
||||
)
|
||||
{
|
||||
$this->canUpdateCurrencyRate = $canUpdateCurrencyRate;
|
||||
$this->updatesCurrencyRate = $updatesCurrencyRate;
|
||||
$this->createsCurrencyRateLog = $createsCurrencyRateLog;
|
||||
$this->fetchesCurrencyRate = $fetchesCurrencyRate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws ErrorException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
$currency_rate_query = $this->fetchesCurrencyRate->execute(['id' => $request->route('id')]);
|
||||
|
||||
$currency_object_object = new CurrencyRateObject(
|
||||
$currency_rate_query->currency_id,
|
||||
$request->input('selling', $currency_rate_query->selling),
|
||||
$currency_rate_query->payment_method_type
|
||||
);
|
||||
|
||||
$this->canUpdateCurrencyRate->passes($currency_object_object);
|
||||
$currency_rate_query = $this->updatesCurrencyRate->execute($currency_rate_query, $currency_object_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());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\CurrencyRates\DataTransferObjects;
|
||||
|
||||
use App\Classes\Interfaces\DataTransferObject;
|
||||
|
||||
class CurrencyRateObject implements DataTransferObject
|
||||
{
|
||||
/** @var int|null */
|
||||
private $currency_id;
|
||||
|
||||
/** @var string|null */
|
||||
private $selling;
|
||||
|
||||
/** @var string|null */
|
||||
private $payment_method_type;
|
||||
|
||||
/**
|
||||
* CurrencyRateObject constructor.
|
||||
* @param int|null $currency_id
|
||||
* @param string|null $selling
|
||||
* @param string|null $payment_method_type
|
||||
*/
|
||||
public function __construct(
|
||||
?int $currency_id,
|
||||
?string $selling,
|
||||
?string $payment_method_type
|
||||
)
|
||||
{
|
||||
$this->currency_id = $currency_id;
|
||||
$this->selling = $selling;
|
||||
$this->payment_method_type = $payment_method_type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getCurrencyId(): ?int
|
||||
{
|
||||
return $this->currency_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getSelling(): ?string
|
||||
{
|
||||
return $this->selling;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPaymentMethodType(): ?string
|
||||
{
|
||||
return $this->payment_method_type;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\CurrencyRates\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Models\CurrencyRate;
|
||||
|
||||
class CalculatesCurrencyRate extends AbstractUpdateRecord
|
||||
{
|
||||
|
||||
public function execute(CurrencyRate $conversion_currency_rate, CurrencyRate $convertable_currency_rate, $amount)
|
||||
{
|
||||
return $convert_amount = ($conversion_currency_rate->selling / $convertable_currency_rate->selling) * $amount;
|
||||
}
|
||||
|
||||
public function execute_rate(CurrencyRate $conversion_currency_rate, CurrencyRate $convertable_currency_rate)
|
||||
{
|
||||
return $convert_rate = ($conversion_currency_rate->selling / $convertable_currency_rate->selling);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\CurrencyRates\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Classes\Modules\CurrencyRates\DataTransferObjects\CurrencyRateObject;
|
||||
use App\Models\CurrencyRate;
|
||||
|
||||
class CreatesCurrencyRate extends AbstractUpdateRecord
|
||||
{
|
||||
|
||||
/**
|
||||
* @param CurrencyRateObject $object
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(CurrencyRateObject $object)
|
||||
{
|
||||
$model = new CurrencyRate();
|
||||
$model->currency_id = $object->getCurrencyId();
|
||||
$model->selling = $object->getSelling();
|
||||
$model->payment_method_type = $object->getPaymentMethodType();
|
||||
|
||||
return $this->handler($model);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Currencies\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Models\CurrencyRate;
|
||||
use App\Models\CurrencyRateLog;
|
||||
|
||||
class CreatesCurrencyRateLog extends AbstractUpdateRecord
|
||||
{
|
||||
/**
|
||||
* @param Currency $object
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(CurrencyRate $object) {
|
||||
$model = new CurrencyRateLog();
|
||||
$model->currency_rate_id = $object->id;
|
||||
$model->selling = $object->selling;
|
||||
$model->created_by = \Auth::user()->id;
|
||||
return $this->handler($model);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\CurrencyRates\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractDeleteRecord;
|
||||
use App\Models\CurrencyRate;
|
||||
|
||||
class DeletesCurrencyRAte extends AbstractDeleteRecord
|
||||
{
|
||||
|
||||
public function execute(CurrencyRate $model) {
|
||||
return $this->handler($model);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\CurrencyRates\Services;
|
||||
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractFetchRecord;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Models\CurrencyRate;
|
||||
|
||||
class FetchesCurrencyRate extends AbstractFetchRecord
|
||||
{
|
||||
|
||||
/** @var CurrencyRate */
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* FetchesCurrencyRate constructor.
|
||||
* @param CurrencyRate $repository
|
||||
*/
|
||||
public function __construct(CurrencyRate $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Builder
|
||||
*/
|
||||
public function getRepository(): Builder
|
||||
{
|
||||
return $this->repository->newQuery();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\CurrencyRates\Services;
|
||||
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractListRecord;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Models\CurrencyRate;
|
||||
|
||||
class ListsCurrencyRates extends AbstractListRecord
|
||||
{
|
||||
|
||||
/** @var CurrencyRate */
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* ListsCurrencyRates constructor.
|
||||
* @param CurrencyRate $repository
|
||||
*/
|
||||
public function __construct(CurrencyRate $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Builder
|
||||
*/
|
||||
function getRepository(): Builder
|
||||
{
|
||||
return $this->repository->newQuery();
|
||||
}
|
||||
}
|
||||
+5
-5
@@ -1,20 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Currencies\Services;
|
||||
namespace App\Classes\Modules\CurrencyRates\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Classes\Modules\Currencies\DataTransferObjects\CurrencyObject;
|
||||
use App\Models\Currency;
|
||||
use App\Classes\Modules\CurrencyRates\DataTransferObjects\CurrencyRateObject;
|
||||
use App\Models\CurrencyRate;
|
||||
|
||||
class UpdatesCurrencyRate extends AbstractUpdateRecord
|
||||
{
|
||||
|
||||
/**
|
||||
* @param CurrencyObject $object
|
||||
* @param CurrencyRateObject $object
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(Currency $model, CurrencyObject $object)
|
||||
public function execute(CurrencyRate $model, CurrencyRateObject $object)
|
||||
{
|
||||
$model->selling = $object->getSelling();
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\CurrencyRates\Standards\Rules;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\Modules\CurrencyRates\DataTransferObjects\SegmentObject;
|
||||
use App\Classes\Modules\CurrencyRates\Standards\Validators\CurrencyRateValidation;
|
||||
|
||||
class CanCreateCurrencyRate extends AbstractRule
|
||||
{
|
||||
|
||||
/** @var CurrencyRateValidation */
|
||||
private $currencyRateValidation;
|
||||
|
||||
/**
|
||||
* CanCreateCurrencyRate constructor.
|
||||
* @param CurrencyRateValidation $CurrencyRateValidation
|
||||
*/
|
||||
public function __construct(CurrencyRateValidation $currencyRateValidation)
|
||||
{
|
||||
$this->currencyRateValidation = $currencyRateValidation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
if (!\Auth::user()->can('add currency_rate')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SegmentObject $object
|
||||
* @return bool
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
protected function validators($object): bool
|
||||
{
|
||||
return $this->currencyRateValidation->validate($object, 'POST');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SegmentObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function criteria($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\CurrencyRates\Standards\Rules;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\Modules\CurrencyRates\DataTransferObjects\CurrencyRateObject;
|
||||
|
||||
class CanDeleteCurrencyRate extends AbstractRule
|
||||
{
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
|
||||
if (!\Auth::user()->can('delete currency_rate')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CurrencyRateObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function validators($object): bool
|
||||
{
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param CurrencyRateObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function criteria($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\CurrencyRates\Standards\Rules;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\Modules\CurrencyRates\DataTransferObjects\CurrencyRateObject;
|
||||
|
||||
class CanFetchCurrencyRate extends AbstractRule
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CurrencyRateObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function validators($object): bool
|
||||
{
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param CurrencyRateObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function criteria($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\CurrencyRates\Standards\Rules;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\Modules\CurrencyRates\DataTransferObjects\CurrencyRateObject;
|
||||
|
||||
class CanListCurrencyRates extends AbstractRule
|
||||
{
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
|
||||
if (!\Auth::user()->can('view currency_rate')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SegmentObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function validators($object): bool
|
||||
{
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param SegmentObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function criteria($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\CurrencyRates\Standards\Rules;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\Modules\CurrencyRates\DataTransferObjects\SegmentCompanyObject;
|
||||
use App\Classes\Modules\CurrencyRates\Standards\Validators\CurrencyRateValidation;
|
||||
|
||||
class CanUpdateCurrencyRate extends AbstractRule
|
||||
{
|
||||
|
||||
/** @var CurrencyRateValidation */
|
||||
private $currencyRateValidation;
|
||||
|
||||
/**
|
||||
* CanUpdateCurrencyRate constructor.
|
||||
* @param CurrencyRateValidation $CurrencyRateValidation
|
||||
*/
|
||||
public function __construct(CurrencyRateValidation $currencyRateValidation)
|
||||
{
|
||||
$this->currencyRateValidation = $currencyRateValidation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
|
||||
if (!\Auth::user()->can('view currency_rate')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CurrencyRateValidation $object
|
||||
* @return bool
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
protected function validators($object): bool
|
||||
{
|
||||
return $this->currencyRateValidation->validate($object, 'PUT');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CurrencyRateValidation $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function criteria($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\CurrencyRates\Standards\Validators;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractValidation;
|
||||
use App\Classes\Modules\CurrencyRates\DataTransferObjects\CurrencyRateObject;
|
||||
|
||||
class CurrencyRateValidation extends AbstractValidation
|
||||
{
|
||||
/**
|
||||
* @param CurrencyRateObject $object
|
||||
* @return array
|
||||
*/
|
||||
protected function data($object): array {
|
||||
|
||||
$data = [
|
||||
'currency_id'=> $object->getCurrencyId(),
|
||||
'selling' => $object->getSelling(),
|
||||
'payment_method_type' => $object->getPaymentMethodType(),
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function rules(?string $type = 'POST'): array {
|
||||
return [
|
||||
'currency_id' => $type == 'POST' ? 'required' : '',
|
||||
'selling' => 'required',
|
||||
'payment_method_type' => 'required',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function messages(): array {
|
||||
return [];
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\Classes\ValueObjects\Constants;
|
||||
|
||||
final class CurrencyType {
|
||||
final class PaymentMethodType {
|
||||
public const CASH = 1;
|
||||
public const CHEQUE = 2;
|
||||
public const PA = 3;
|
||||
Reference in New Issue
Block a user