diff --git a/app/Api/V2/Controllers/Controller.php b/app/Api/V2/Controllers/Controller.php index 02631c38cd..4717fdae0c 100644 --- a/app/Api/V2/Controllers/Controller.php +++ b/app/Api/V2/Controllers/Controller.php @@ -92,8 +92,8 @@ class Controller extends BaseController if ($page < 1) { $page = 1; } - if ($page > (2 ^ 16)) { - $page = (2 ^ 16); + if ($page > pow(2,16)) { + $page = pow(2,16); } $bag->set('page', $page); diff --git a/app/Api/V2/Controllers/Model/ExchangeRate/ShowController.php b/app/Api/V2/Controllers/Model/ExchangeRate/ShowController.php index 0517dc6eec..5085aa08ae 100644 --- a/app/Api/V2/Controllers/Model/ExchangeRate/ShowController.php +++ b/app/Api/V2/Controllers/Model/ExchangeRate/ShowController.php @@ -57,13 +57,13 @@ class ShowController extends Controller public function show(TransactionCurrency $from, TransactionCurrency $to): JsonResponse { -// $piggies = $this->repository->getAll(); -// - $pageSize = $this->parameters->get('limit'); - $rates = $this->repository->getRates($from, $to); + $pageSize = $this->parameters->get('limit'); + $page = $this->parameters->get('page'); + $rates = $this->repository->getRates($from, $to); $count = $rates->count(); - $rates = $rates->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize); - $paginator = new LengthAwarePaginator($rates, $count, $pageSize, $this->parameters->get('page')); + + $rates = $rates->slice(($page - 1) * $pageSize, $pageSize); + $paginator = new LengthAwarePaginator($rates, $count, $pageSize, $page); $transformer = new ExchangeRateTransformer(); $transformer->setParameters($this->parameters); // give params to transformer diff --git a/app/Repositories/UserGroups/ExchangeRate/ExchangeRateRepository.php b/app/Repositories/UserGroups/ExchangeRate/ExchangeRateRepository.php index 5ae0292cbd..e89a9d2521 100644 --- a/app/Repositories/UserGroups/ExchangeRate/ExchangeRateRepository.php +++ b/app/Repositories/UserGroups/ExchangeRate/ExchangeRateRepository.php @@ -35,17 +35,19 @@ class ExchangeRateRepository implements ExchangeRateRepositoryInterface #[\Override] public function getRates(TransactionCurrency $from, TransactionCurrency $to): Collection { + // orderBy('date', 'DESC')->toRawSql(); return $this->userGroup->currencyExchangeRates() - ->where(function (Builder $q) use ($from, $to) { - $q->where('from_currency_id', $from->id) - ->orWhere('to_currency_id', $to->id); + ->where(function (Builder $q1) use ($from, $to) { + $q1->where(function (Builder $q) use ($from, $to) { + $q->where('from_currency_id', $from->id) + ->where('to_currency_id', $to->id); + })->orWhere(function (Builder $q) use ($from, $to) { + $q->where('from_currency_id', $to->id) + ->where('to_currency_id', $from->id); + }); }) - ->orWhere(function (Builder $q) use ($from, $to) { - $q->where('from_currency_id', $to->id) - ->orWhere('to_currency_id', $from->id); - }) - ->orderBy('date', 'DESC')->get(); + ->orderBy('date', 'DESC')->get(['currency_exchange_rates.*']); } } diff --git a/resources/assets/v1/src/components/exchange-rates/Rates.vue b/resources/assets/v1/src/components/exchange-rates/Rates.vue index f2a1328379..053deb40ea 100644 --- a/resources/assets/v1/src/components/exchange-rates/Rates.vue +++ b/resources/assets/v1/src/components/exchange-rates/Rates.vue @@ -19,7 +19,6 @@ --> - @@ -53,6 +52,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + update + delete + + @@ -62,11 +97,15 @@ diff --git a/resources/assets/v1/src/create_transaction.js b/resources/assets/v1/src/create_transaction.js index 1dda1b3fd2..a5bb19dd7c 100644 --- a/resources/assets/v1/src/create_transaction.js +++ b/resources/assets/v1/src/create_transaction.js @@ -23,7 +23,7 @@ import CreateTransaction from './components/transactions/CreateTransaction'; import CustomDate from "./components/transactions/CustomDate"; import CustomString from "./components/transactions/CustomString"; import CustomTextarea from "./components/transactions/CustomTextarea"; -import StandardDate from "./components/transactions/StandardDate"; +import StandardDate from "./components/transactions/StandardDate"; import GroupDescription from "./components/transactions/GroupDescription"; import TransactionDescription from "./components/transactions/TransactionDescription"; import CustomTransactionFields from "./components/transactions/CustomTransactionFields"; diff --git a/routes/api.php b/routes/api.php index d5c3b0eec9..e0c649d9f0 100644 --- a/routes/api.php +++ b/routes/api.php @@ -114,7 +114,7 @@ Route::group( ], static function (): void { Route::get('', ['uses' => 'IndexController@index', 'as' => 'index']); - Route::get('{fromCurrencyCode}/{toCurrencyCode}', ['uses' => 'ShowController@show', 'as' => 'show']); + Route::get('rates/{fromCurrencyCode}/{toCurrencyCode}', ['uses' => 'ShowController@show', 'as' => 'show']); // Route::post('', ['uses' => 'StoreController@store', 'as' => 'store']); // // Route::put('{userGroup}', ['uses' => 'UpdateController@update', 'as' => 'update']);