From 664a08d42f1e3342c64f70195e66a8672f449019 Mon Sep 17 00:00:00 2001 From: James Cole Date: Thu, 5 Oct 2023 18:52:01 +0200 Subject: [PATCH] Add limit param to all endpoints --- app/Api/V1/Controllers/Controller.php | 5 +++ .../Models/Account/ListController.php | 19 +++++------ .../Models/Account/ShowController.php | 2 +- .../Models/Attachment/ShowController.php | 2 +- .../Models/AvailableBudget/ShowController.php | 2 +- .../Models/Bill/ListController.php | 14 ++++---- .../Models/Bill/ShowController.php | 2 +- .../Models/Budget/ListController.php | 34 ++++++++----------- .../Models/Budget/ShowController.php | 2 +- .../Models/BudgetLimit/ListController.php | 2 +- .../Models/BudgetLimit/ShowController.php | 4 +-- .../Models/Category/ListController.php | 11 +++--- .../Models/Category/ShowController.php | 2 +- .../Models/ObjectGroup/ListController.php | 4 +-- .../Models/ObjectGroup/ShowController.php | 2 +- .../Models/PiggyBank/ListController.php | 4 +-- .../Models/PiggyBank/ShowController.php | 2 +- .../Models/Recurrence/ListController.php | 10 ++++-- .../Models/Recurrence/ShowController.php | 2 +- .../Models/Rule/ShowController.php | 2 +- .../Models/RuleGroup/ListController.php | 2 +- .../Models/RuleGroup/ShowController.php | 2 +- .../Controllers/Models/Tag/ListController.php | 11 +++--- .../Controllers/Models/Tag/ShowController.php | 2 +- .../Models/Transaction/ListController.php | 6 ++-- .../Models/Transaction/ShowController.php | 2 +- .../TransactionCurrency/ListController.php | 21 +++++++----- .../TransactionCurrency/ShowController.php | 2 +- .../Models/TransactionLink/ShowController.php | 2 +- .../TransactionLinkType/ListController.php | 9 +++-- .../TransactionLinkType/ShowController.php | 2 +- .../Search/TransactionController.php | 3 +- .../V1/Controllers/System/UserController.php | 2 +- .../User/PreferencesController.php | 2 +- .../Controllers/Webhook/AttemptController.php | 2 +- .../Controllers/Webhook/MessageController.php | 2 +- .../V1/Controllers/Webhook/ShowController.php | 2 +- app/Api/V2/Controllers/Controller.php | 10 +++--- .../Controllers/Model/Bill/ShowController.php | 2 +- .../Model/Budget/ListController.php | 4 +-- .../Model/BudgetLimit/ListController.php | 5 +-- .../Model/PiggyBank/ShowController.php | 2 +- .../Transaction/List/AccountController.php | 14 +++----- .../List/TransactionController.php | 15 ++++---- .../Controllers/UserGroup/ShowController.php | 5 +-- .../Request/Model/Transaction/ListRequest.php | 16 ++------- 46 files changed, 136 insertions(+), 138 deletions(-) diff --git a/app/Api/V1/Controllers/Controller.php b/app/Api/V1/Controllers/Controller.php index 8740fb7c08..f77ee76f89 100644 --- a/app/Api/V1/Controllers/Controller.php +++ b/app/Api/V1/Controllers/Controller.php @@ -137,6 +137,11 @@ abstract class Controller extends BaseController if (null !== $value) { $bag->set($integer, (int)$value); } + if (null === $value && 'limit' === $integer) { + // set default for user: + $pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; + $bag->set($integer, $pageSize); + } } // sort fields: diff --git a/app/Api/V1/Controllers/Models/Account/ListController.php b/app/Api/V1/Controllers/Models/Account/ListController.php index 562b9c8d95..6e3660121c 100644 --- a/app/Api/V1/Controllers/Models/Account/ListController.php +++ b/app/Api/V1/Controllers/Models/Account/ListController.php @@ -81,7 +81,7 @@ class ListController extends Controller public function attachments(Account $account): JsonResponse { $manager = $this->getManager(); - $pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; + $pageSize = $this->parameters->get('limit'); $collection = $this->repository->getAttachments($account); $count = $collection->count(); @@ -116,7 +116,7 @@ class ListController extends Controller $manager = $this->getManager(); // types to get, page size: - $pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; + $pageSize = $this->parameters->get('limit'); // get list of budgets. Count it and split it. $collection = $this->repository->getPiggyBanks($account); @@ -152,15 +152,9 @@ class ListController extends Controller */ public function transactions(Request $request, Account $account): JsonResponse { - $pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; + $pageSize = $this->parameters->get('limit'); $type = $request->get('type') ?? 'default'; $this->parameters->set('type', $type); - - // user can overrule page size with limit parameter. - $limit = $this->parameters->get('limit'); - if (null !== $limit && $limit > 0) { - $pageSize = $limit; - } $types = $this->mapTransactionTypes($this->parameters->get('type')); $manager = $this->getManager(); /** @var User $admin */ @@ -172,8 +166,11 @@ class ListController extends Controller $collector->setUser($admin)->setAccounts(new Collection([$account])) ->withAPIInformation()->setLimit($pageSize)->setPage($this->parameters->get('page'))->setTypes($types); - if (null !== $this->parameters->get('start') && null !== $this->parameters->get('end')) { - $collector->setRange($this->parameters->get('start'), $this->parameters->get('end')); + if (null !== $this->parameters->get('start')) { + $collector->setStart($this->parameters->get('start')); + } + if (null !== $this->parameters->get('end')) { + $collector->setEnd($this->parameters->get('end')); } $paginator = $collector->getPaginatedGroups(); diff --git a/app/Api/V1/Controllers/Models/Account/ShowController.php b/app/Api/V1/Controllers/Models/Account/ShowController.php index b3e7d75942..8decc0a0dd 100644 --- a/app/Api/V1/Controllers/Models/Account/ShowController.php +++ b/app/Api/V1/Controllers/Models/Account/ShowController.php @@ -84,7 +84,7 @@ class ShowController extends Controller // types to get, page size: $types = $this->mapAccountTypes($this->parameters->get('type')); - $pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; + $pageSize = $this->parameters->get('limit'); // get list of accounts. Count it and split it. $this->repository->resetAccountOrder(); diff --git a/app/Api/V1/Controllers/Models/Attachment/ShowController.php b/app/Api/V1/Controllers/Models/Attachment/ShowController.php index 31dc2bfd93..12e53d298c 100644 --- a/app/Api/V1/Controllers/Models/Attachment/ShowController.php +++ b/app/Api/V1/Controllers/Models/Attachment/ShowController.php @@ -123,7 +123,7 @@ class ShowController extends Controller $manager = $this->getManager(); // types to get, page size: - $pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; + $pageSize = $this->parameters->get('limit'); // get list of attachments. Count it and split it. $collection = $this->repository->get(); diff --git a/app/Api/V1/Controllers/Models/AvailableBudget/ShowController.php b/app/Api/V1/Controllers/Models/AvailableBudget/ShowController.php index d122321e71..268fa4a317 100644 --- a/app/Api/V1/Controllers/Models/AvailableBudget/ShowController.php +++ b/app/Api/V1/Controllers/Models/AvailableBudget/ShowController.php @@ -76,7 +76,7 @@ class ShowController extends Controller $manager = $this->getManager(); // types to get, page size: - $pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; + $pageSize = $this->parameters->get('limit'); $start = $this->parameters->get('start'); $end = $this->parameters->get('end'); diff --git a/app/Api/V1/Controllers/Models/Bill/ListController.php b/app/Api/V1/Controllers/Models/Bill/ListController.php index 1000ec433e..df2535bb49 100644 --- a/app/Api/V1/Controllers/Models/Bill/ListController.php +++ b/app/Api/V1/Controllers/Models/Bill/ListController.php @@ -80,7 +80,7 @@ class ListController extends Controller public function attachments(Bill $bill): JsonResponse { $manager = $this->getManager(); - $pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; + $pageSize = $this->parameters->get('limit'); $collection = $this->repository->getAttachments($bill); $count = $collection->count(); @@ -116,7 +116,7 @@ class ListController extends Controller $manager = $this->getManager(); // types to get, page size: - $pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; + $pageSize = $this->parameters->get('limit'); // get list of budgets. Count it and split it. $collection = $this->repository->getRulesForBill($bill); @@ -151,7 +151,7 @@ class ListController extends Controller */ public function transactions(Request $request, Bill $bill): JsonResponse { - $pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; + $pageSize = $this->parameters->get('limit'); $type = $request->get('type') ?? 'default'; $this->parameters->set('type', $type); @@ -177,9 +177,11 @@ class ListController extends Controller // set types of transactions to return. ->setTypes($types); - // do parameter stuff on new group collector. - if (null !== $this->parameters->get('start') && null !== $this->parameters->get('end')) { - $collector->setRange($this->parameters->get('start'), $this->parameters->get('end')); + if (null !== $this->parameters->get('start')) { + $collector->setStart($this->parameters->get('start')); + } + if (null !== $this->parameters->get('end')) { + $collector->setEnd($this->parameters->get('end')); } // get paginator. diff --git a/app/Api/V1/Controllers/Models/Bill/ShowController.php b/app/Api/V1/Controllers/Models/Bill/ShowController.php index a5bc503eed..7848ce9cc9 100644 --- a/app/Api/V1/Controllers/Models/Bill/ShowController.php +++ b/app/Api/V1/Controllers/Models/Bill/ShowController.php @@ -73,7 +73,7 @@ class ShowController extends Controller $this->repository->correctOrder(); $bills = $this->repository->getBills(); $manager = $this->getManager(); - $pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; + $pageSize = $this->parameters->get('limit'); $count = $bills->count(); $bills = $bills->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize); $paginator = new LengthAwarePaginator($bills, $count, $pageSize, $this->parameters->get('page')); diff --git a/app/Api/V1/Controllers/Models/Budget/ListController.php b/app/Api/V1/Controllers/Models/Budget/ListController.php index 6f5ba252a8..88bf49569c 100644 --- a/app/Api/V1/Controllers/Models/Budget/ListController.php +++ b/app/Api/V1/Controllers/Models/Budget/ListController.php @@ -82,7 +82,7 @@ class ListController extends Controller public function attachments(Budget $budget): JsonResponse { $manager = $this->getManager(); - $pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; + $pageSize = $this->parameters->get('limit'); $collection = $this->repository->getAttachments($budget); $count = $collection->count(); @@ -116,7 +116,7 @@ class ListController extends Controller public function budgetLimits(Budget $budget): JsonResponse { $manager = $this->getManager(); - $pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; + $pageSize = $this->parameters->get('limit'); $this->parameters->set('budget_id', $budget->id); $collection = $this->blRepository->getBudgetLimits($budget, $this->parameters->get('start'), $this->parameters->get('end')); $count = $collection->count(); @@ -148,13 +148,7 @@ class ListController extends Controller */ public function transactions(Request $request, Budget $budget): JsonResponse { - $pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; - - // user can overrule page size with limit parameter. - $limit = $this->parameters->get('limit'); - if (null !== $limit && $limit > 0) { - $pageSize = $limit; - } + $pageSize = $this->parameters->get('limit'); $type = $request->get('type') ?? 'default'; $this->parameters->set('type', $type); @@ -181,8 +175,11 @@ class ListController extends Controller // set types of transactions to return. ->setTypes($types); - if (null !== $this->parameters->get('start') && null !== $this->parameters->get('end')) { - $collector->setRange($this->parameters->get('start'), $this->parameters->get('end')); + if (null !== $this->parameters->get('start')) { + $collector->setStart($this->parameters->get('start')); + } + if (null !== $this->parameters->get('end')) { + $collector->setEnd($this->parameters->get('end')); } $paginator = $collector->getPaginatedGroups(); @@ -211,13 +208,7 @@ class ListController extends Controller */ public function withoutBudget(Request $request): JsonResponse { - $pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; - - // user can overrule page size with limit parameter. - $limit = $this->parameters->get('limit'); - if (null !== $limit && $limit > 0) { - $pageSize = $limit; - } + $pageSize = $this->parameters->get('limit'); $type = $request->get('type') ?? 'default'; $this->parameters->set('type', $type); @@ -244,8 +235,11 @@ class ListController extends Controller // set types of transactions to return. ->setTypes($types); - if (null !== $this->parameters->get('start') && null !== $this->parameters->get('end')) { - $collector->setRange($this->parameters->get('start'), $this->parameters->get('end')); + if (null !== $this->parameters->get('start')) { + $collector->setStart($this->parameters->get('start')); + } + if (null !== $this->parameters->get('end')) { + $collector->setEnd($this->parameters->get('end')); } $paginator = $collector->getPaginatedGroups(); diff --git a/app/Api/V1/Controllers/Models/Budget/ShowController.php b/app/Api/V1/Controllers/Models/Budget/ShowController.php index 02252caf35..8f36f0fbfb 100644 --- a/app/Api/V1/Controllers/Models/Budget/ShowController.php +++ b/app/Api/V1/Controllers/Models/Budget/ShowController.php @@ -77,7 +77,7 @@ class ShowController extends Controller $manager = $this->getManager(); // types to get, page size: - $pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; + $pageSize = $this->parameters->get('limit'); // get list of budgets. Count it and split it. $collection = $this->repository->getBudgets(); diff --git a/app/Api/V1/Controllers/Models/BudgetLimit/ListController.php b/app/Api/V1/Controllers/Models/BudgetLimit/ListController.php index e006c95d7b..adc69dc9a0 100644 --- a/app/Api/V1/Controllers/Models/BudgetLimit/ListController.php +++ b/app/Api/V1/Controllers/Models/BudgetLimit/ListController.php @@ -80,7 +80,7 @@ class ListController extends Controller */ public function transactions(Request $request, Budget $budget, BudgetLimit $budgetLimit): JsonResponse { - $pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; + $pageSize = $this->parameters->get('limit'); $type = $request->get('type') ?? 'default'; $this->parameters->set('type', $type); diff --git a/app/Api/V1/Controllers/Models/BudgetLimit/ShowController.php b/app/Api/V1/Controllers/Models/BudgetLimit/ShowController.php index 365bc19dcd..1a4c4e6302 100644 --- a/app/Api/V1/Controllers/Models/BudgetLimit/ShowController.php +++ b/app/Api/V1/Controllers/Models/BudgetLimit/ShowController.php @@ -85,7 +85,7 @@ class ShowController extends Controller { $manager = $this->getManager(); $manager->parseIncludes('budget'); - $pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; + $pageSize = $this->parameters->get('limit'); $collection = $this->blRepository->getBudgetLimits($budget, $this->parameters->get('start'), $this->parameters->get('end')); $count = $collection->count(); $budgetLimits = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize); @@ -117,7 +117,7 @@ class ShowController extends Controller { $manager = $this->getManager(); $manager->parseIncludes('budget'); - $pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; + $pageSize = $this->parameters->get('limit'); $collection = $this->blRepository->getAllBudgetLimits($this->parameters->get('start'), $this->parameters->get('end')); $count = $collection->count(); $budgetLimits = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize); diff --git a/app/Api/V1/Controllers/Models/Category/ListController.php b/app/Api/V1/Controllers/Models/Category/ListController.php index 16c2bfd4d2..ffc37839e1 100644 --- a/app/Api/V1/Controllers/Models/Category/ListController.php +++ b/app/Api/V1/Controllers/Models/Category/ListController.php @@ -77,7 +77,7 @@ class ListController extends Controller public function attachments(Category $category): JsonResponse { $manager = $this->getManager(); - $pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; + $pageSize = $this->parameters->get('limit'); $collection = $this->repository->getAttachments($category); $count = $collection->count(); @@ -112,7 +112,7 @@ class ListController extends Controller */ public function transactions(Request $request, Category $category): JsonResponse { - $pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; + $pageSize = $this->parameters->get('limit'); $type = $request->get('type') ?? 'default'; $this->parameters->set('type', $type); @@ -138,8 +138,11 @@ class ListController extends Controller // set types of transactions to return. ->setTypes($types); - if (null !== $this->parameters->get('start') && null !== $this->parameters->get('end')) { - $collector->setRange($this->parameters->get('start'), $this->parameters->get('end')); + if (null !== $this->parameters->get('start')) { + $collector->setStart($this->parameters->get('start')); + } + if (null !== $this->parameters->get('end')) { + $collector->setEnd($this->parameters->get('end')); } $paginator = $collector->getPaginatedGroups(); diff --git a/app/Api/V1/Controllers/Models/Category/ShowController.php b/app/Api/V1/Controllers/Models/Category/ShowController.php index 01f328eff1..5a772647a1 100644 --- a/app/Api/V1/Controllers/Models/Category/ShowController.php +++ b/app/Api/V1/Controllers/Models/Category/ShowController.php @@ -73,7 +73,7 @@ class ShowController extends Controller $manager = $this->getManager(); // types to get, page size: - $pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; + $pageSize = $this->parameters->get('limit'); // get list of budgets. Count it and split it. $collection = $this->repository->getCategories(); diff --git a/app/Api/V1/Controllers/Models/ObjectGroup/ListController.php b/app/Api/V1/Controllers/Models/ObjectGroup/ListController.php index 10b96a4e93..33dc0d4e5b 100644 --- a/app/Api/V1/Controllers/Models/ObjectGroup/ListController.php +++ b/app/Api/V1/Controllers/Models/ObjectGroup/ListController.php @@ -77,7 +77,7 @@ class ListController extends Controller { $manager = $this->getManager(); - $pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; + $pageSize = $this->parameters->get('limit'); // get list of piggy banks. Count it and split it. $collection = $this->repository->getBills($objectGroup); $count = $collection->count(); @@ -114,7 +114,7 @@ class ListController extends Controller $manager = $this->getManager(); // types to get, page size: - $pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; + $pageSize = $this->parameters->get('limit'); // get list of piggy banks. Count it and split it. $collection = $this->repository->getPiggyBanks($objectGroup); diff --git a/app/Api/V1/Controllers/Models/ObjectGroup/ShowController.php b/app/Api/V1/Controllers/Models/ObjectGroup/ShowController.php index 911f803b08..ae8e202aa3 100644 --- a/app/Api/V1/Controllers/Models/ObjectGroup/ShowController.php +++ b/app/Api/V1/Controllers/Models/ObjectGroup/ShowController.php @@ -79,7 +79,7 @@ class ShowController extends Controller $manager = $this->getManager(); // types to get, page size: - $pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; + $pageSize = $this->parameters->get('limit'); $this->repository->resetOrder(); $collection = $this->repository->get(); diff --git a/app/Api/V1/Controllers/Models/PiggyBank/ListController.php b/app/Api/V1/Controllers/Models/PiggyBank/ListController.php index 8943791638..96a62a4940 100644 --- a/app/Api/V1/Controllers/Models/PiggyBank/ListController.php +++ b/app/Api/V1/Controllers/Models/PiggyBank/ListController.php @@ -71,7 +71,7 @@ class ListController extends Controller public function attachments(PiggyBank $piggyBank): JsonResponse { $manager = $this->getManager(); - $pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; + $pageSize = $this->parameters->get('limit'); $collection = $this->repository->getAttachments($piggyBank); $count = $collection->count(); @@ -105,7 +105,7 @@ class ListController extends Controller public function piggyBankEvents(PiggyBank $piggyBank): JsonResponse { // types to get, page size: - $pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; + $pageSize = $this->parameters->get('limit'); $manager = $this->getManager(); $collection = $this->repository->getEvents($piggyBank); diff --git a/app/Api/V1/Controllers/Models/PiggyBank/ShowController.php b/app/Api/V1/Controllers/Models/PiggyBank/ShowController.php index 0c8e01e968..22bb4f3624 100644 --- a/app/Api/V1/Controllers/Models/PiggyBank/ShowController.php +++ b/app/Api/V1/Controllers/Models/PiggyBank/ShowController.php @@ -72,7 +72,7 @@ class ShowController extends Controller { $manager = $this->getManager(); // types to get, page size: - $pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; + $pageSize = $this->parameters->get('limit'); // get list of budgets. Count it and split it. $collection = $this->repository->getPiggyBanks(); diff --git a/app/Api/V1/Controllers/Models/Recurrence/ListController.php b/app/Api/V1/Controllers/Models/Recurrence/ListController.php index 9e017818db..9d81586362 100644 --- a/app/Api/V1/Controllers/Models/Recurrence/ListController.php +++ b/app/Api/V1/Controllers/Models/Recurrence/ListController.php @@ -77,7 +77,7 @@ class ListController extends Controller */ public function transactions(Request $request, Recurrence $recurrence): JsonResponse { - $pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; + $pageSize = $this->parameters->get('limit'); $type = $request->get('type') ?? 'default'; $this->parameters->set('type', $type); @@ -105,9 +105,13 @@ class ListController extends Controller // set types of transactions to return. ->setTypes($types); - if (null !== $this->parameters->get('start') && null !== $this->parameters->get('end')) { - $collector->setRange($this->parameters->get('start'), $this->parameters->get('end')); + if (null !== $this->parameters->get('start')) { + $collector->setStart($this->parameters->get('start')); } + if (null !== $this->parameters->get('end')) { + $collector->setEnd($this->parameters->get('end')); + } + $paginator = $collector->getPaginatedGroups(); $paginator->setPath(route('api.v1.transactions.index') . $this->buildParams()); $transactions = $paginator->getCollection(); diff --git a/app/Api/V1/Controllers/Models/Recurrence/ShowController.php b/app/Api/V1/Controllers/Models/Recurrence/ShowController.php index 99ed67b074..54d1f86c30 100644 --- a/app/Api/V1/Controllers/Models/Recurrence/ShowController.php +++ b/app/Api/V1/Controllers/Models/Recurrence/ShowController.php @@ -73,7 +73,7 @@ class ShowController extends Controller $manager = $this->getManager(); // types to get, page size: - $pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; + $pageSize = $this->parameters->get('limit'); // get list of budgets. Count it and split it. $collection = $this->repository->get(); diff --git a/app/Api/V1/Controllers/Models/Rule/ShowController.php b/app/Api/V1/Controllers/Models/Rule/ShowController.php index ff8ed98044..b4b93c7767 100644 --- a/app/Api/V1/Controllers/Models/Rule/ShowController.php +++ b/app/Api/V1/Controllers/Models/Rule/ShowController.php @@ -77,7 +77,7 @@ class ShowController extends Controller $manager = $this->getManager(); // types to get, page size: - $pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; + $pageSize = $this->parameters->get('limit'); // get list of budgets. Count it and split it. $collection = $this->ruleRepository->getAll(); diff --git a/app/Api/V1/Controllers/Models/RuleGroup/ListController.php b/app/Api/V1/Controllers/Models/RuleGroup/ListController.php index 0e3f7cbab4..5c197da60d 100644 --- a/app/Api/V1/Controllers/Models/RuleGroup/ListController.php +++ b/app/Api/V1/Controllers/Models/RuleGroup/ListController.php @@ -75,7 +75,7 @@ class ListController extends Controller { $manager = $this->getManager(); // types to get, page size: - $pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; + $pageSize = $this->parameters->get('limit'); // get list of budgets. Count it and split it. $collection = $this->ruleGroupRepository->getRules($group); diff --git a/app/Api/V1/Controllers/Models/RuleGroup/ShowController.php b/app/Api/V1/Controllers/Models/RuleGroup/ShowController.php index 465ac40a5d..cfe41894c4 100644 --- a/app/Api/V1/Controllers/Models/RuleGroup/ShowController.php +++ b/app/Api/V1/Controllers/Models/RuleGroup/ShowController.php @@ -75,7 +75,7 @@ class ShowController extends Controller { $manager = $this->getManager(); // types to get, page size: - $pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; + $pageSize = $this->parameters->get('limit'); // get list of rule groups. Count it and split it. $collection = $this->ruleGroupRepository->get(); diff --git a/app/Api/V1/Controllers/Models/Tag/ListController.php b/app/Api/V1/Controllers/Models/Tag/ListController.php index 89bc31dee8..864c01385c 100644 --- a/app/Api/V1/Controllers/Models/Tag/ListController.php +++ b/app/Api/V1/Controllers/Models/Tag/ListController.php @@ -80,7 +80,7 @@ class ListController extends Controller public function attachments(Tag $tag): JsonResponse { $manager = $this->getManager(); - $pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; + $pageSize = $this->parameters->get('limit'); $collection = $this->repository->getAttachments($tag); $count = $collection->count(); @@ -114,7 +114,7 @@ class ListController extends Controller */ public function transactions(Request $request, Tag $tag): JsonResponse { - $pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; + $pageSize = $this->parameters->get('limit'); $type = $request->get('type') ?? 'default'; $this->parameters->set('type', $type); @@ -139,8 +139,11 @@ class ListController extends Controller // set types of transactions to return. ->setTypes($types); - if (null !== $this->parameters->get('start') && null !== $this->parameters->get('end')) { - $collector->setRange($this->parameters->get('start'), $this->parameters->get('end')); + if (null !== $this->parameters->get('start')) { + $collector->setStart($this->parameters->get('start')); + } + if (null !== $this->parameters->get('end')) { + $collector->setEnd($this->parameters->get('end')); } $paginator = $collector->getPaginatedGroups(); $paginator->setPath(route('api.v1.tags.transactions', [$tag->id]) . $this->buildParams()); diff --git a/app/Api/V1/Controllers/Models/Tag/ShowController.php b/app/Api/V1/Controllers/Models/Tag/ShowController.php index 068c266f95..9c50ddf6c1 100644 --- a/app/Api/V1/Controllers/Models/Tag/ShowController.php +++ b/app/Api/V1/Controllers/Models/Tag/ShowController.php @@ -76,7 +76,7 @@ class ShowController extends Controller { $manager = $this->getManager(); // types to get, page size: - $pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; + $pageSize = $this->parameters->get('limit'); // get list of budgets. Count it and split it. $collection = $this->repository->get(); diff --git a/app/Api/V1/Controllers/Models/Transaction/ListController.php b/app/Api/V1/Controllers/Models/Transaction/ListController.php index 2a0266b798..25d9d098d0 100644 --- a/app/Api/V1/Controllers/Models/Transaction/ListController.php +++ b/app/Api/V1/Controllers/Models/Transaction/ListController.php @@ -78,7 +78,7 @@ class ListController extends Controller public function attachments(TransactionGroup $transactionGroup): JsonResponse { $manager = $this->getManager(); - $pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; + $pageSize = $this->parameters->get('limit'); $collection = new Collection(); foreach ($transactionGroup->transactionJournals as $transactionJournal) { $collection = $this->journalAPIRepository->getAttachments($transactionJournal)->merge($collection); @@ -114,7 +114,7 @@ class ListController extends Controller { $manager = $this->getManager(); $collection = new Collection(); - $pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; + $pageSize = $this->parameters->get('limit'); foreach ($transactionGroup->transactionJournals as $transactionJournal) { $collection = $this->journalAPIRepository->getPiggyBankEvents($transactionJournal)->merge($collection); } @@ -152,7 +152,7 @@ class ListController extends Controller { $manager = $this->getManager(); $collection = $this->journalAPIRepository->getJournalLinks($transactionJournal); - $pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; + $pageSize = $this->parameters->get('limit'); $count = $collection->count(); $journalLinks = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize); diff --git a/app/Api/V1/Controllers/Models/Transaction/ShowController.php b/app/Api/V1/Controllers/Models/Transaction/ShowController.php index b7c63b9520..2819c50fb2 100644 --- a/app/Api/V1/Controllers/Models/Transaction/ShowController.php +++ b/app/Api/V1/Controllers/Models/Transaction/ShowController.php @@ -58,7 +58,7 @@ class ShowController extends Controller */ public function index(Request $request): JsonResponse { - $pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; + $pageSize = $this->parameters->get('limit'); $type = $request->get('type') ?? 'default'; $this->parameters->set('type', $type); diff --git a/app/Api/V1/Controllers/Models/TransactionCurrency/ListController.php b/app/Api/V1/Controllers/Models/TransactionCurrency/ListController.php index 2404b9b54e..cd52b0060b 100644 --- a/app/Api/V1/Controllers/Models/TransactionCurrency/ListController.php +++ b/app/Api/V1/Controllers/Models/TransactionCurrency/ListController.php @@ -106,7 +106,7 @@ class ListController extends Controller // types to get, page size: $types = $this->mapAccountTypes($this->parameters->get('type')); - $pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; + $pageSize = $this->parameters->get('limit'); // get list of accounts. Count it and split it. /** @var AccountRepositoryInterface $accountRepository */ @@ -153,7 +153,7 @@ class ListController extends Controller { $manager = $this->getManager(); // types to get, page size: - $pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; + $pageSize = $this->parameters->get('limit'); // get list of available budgets. Count it and split it. /** @var AvailableBudgetRepositoryInterface $abRepository */ @@ -193,7 +193,7 @@ class ListController extends Controller /** @var BillRepositoryInterface $billRepos */ $billRepos = app(BillRepositoryInterface::class); - $pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; + $pageSize = $this->parameters->get('limit'); $unfiltered = $billRepos->getBills(); // filter and paginate list: @@ -236,7 +236,7 @@ class ListController extends Controller $blRepository = app(BudgetLimitRepositoryInterface::class); $manager = $this->getManager(); - $pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; + $pageSize = $this->parameters->get('limit'); $collection = $blRepository->getAllBudgetLimitsByCurrency($currency, $this->parameters->get('start'), $this->parameters->get('end')); $count = $collection->count(); $budgetLimits = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize); @@ -268,7 +268,7 @@ class ListController extends Controller { $manager = $this->getManager(); // types to get, page size: - $pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; + $pageSize = $this->parameters->get('limit'); // get list of budgets. Count it and split it. /** @var RecurringRepositoryInterface $recurringRepos */ @@ -319,7 +319,7 @@ class ListController extends Controller public function rules(TransactionCurrency $currency): JsonResponse { $manager = $this->getManager(); - $pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; + $pageSize = $this->parameters->get('limit'); // get list of budgets. Count it and split it. /** @var RuleRepositoryInterface $ruleRepos */ @@ -371,7 +371,7 @@ class ListController extends Controller */ public function transactions(Request $request, TransactionCurrency $currency): JsonResponse { - $pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; + $pageSize = $this->parameters->get('limit'); $type = $request->get('type') ?? 'default'; $this->parameters->set('type', $type); @@ -396,8 +396,11 @@ class ListController extends Controller ->setPage($this->parameters->get('page')) // set types of transactions to return. ->setTypes($types); - if (null !== $this->parameters->get('start') && null !== $this->parameters->get('end')) { - $collector->setRange($this->parameters->get('start'), $this->parameters->get('end')); + if (null !== $this->parameters->get('start')) { + $collector->setStart($this->parameters->get('start')); + } + if (null !== $this->parameters->get('end')) { + $collector->setEnd($this->parameters->get('end')); } $paginator = $collector->getPaginatedGroups(); $paginator->setPath(route('api.v1.currencies.transactions', [$currency->code]) . $this->buildParams()); diff --git a/app/Api/V1/Controllers/Models/TransactionCurrency/ShowController.php b/app/Api/V1/Controllers/Models/TransactionCurrency/ShowController.php index e9e21d722a..3c5b7c65c0 100644 --- a/app/Api/V1/Controllers/Models/TransactionCurrency/ShowController.php +++ b/app/Api/V1/Controllers/Models/TransactionCurrency/ShowController.php @@ -78,7 +78,7 @@ class ShowController extends Controller */ public function index(): JsonResponse { - $pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; + $pageSize = $this->parameters->get('limit'); $collection = $this->repository->getAll(); $count = $collection->count(); // slice them: diff --git a/app/Api/V1/Controllers/Models/TransactionLink/ShowController.php b/app/Api/V1/Controllers/Models/TransactionLink/ShowController.php index bdf7af1407..485cbd51b2 100644 --- a/app/Api/V1/Controllers/Models/TransactionLink/ShowController.php +++ b/app/Api/V1/Controllers/Models/TransactionLink/ShowController.php @@ -85,7 +85,7 @@ class ShowController extends Controller $name = $request->get('name'); // types to get, page size: - $pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; + $pageSize = $this->parameters->get('limit'); $linkType = $this->repository->findByName($name); // get list of transaction links. Count it and split it. diff --git a/app/Api/V1/Controllers/Models/TransactionLinkType/ListController.php b/app/Api/V1/Controllers/Models/TransactionLinkType/ListController.php index b34e702b77..3e18860ccb 100644 --- a/app/Api/V1/Controllers/Models/TransactionLinkType/ListController.php +++ b/app/Api/V1/Controllers/Models/TransactionLinkType/ListController.php @@ -78,7 +78,7 @@ class ListController extends Controller */ public function transactions(Request $request, LinkType $linkType): JsonResponse { - $pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; + $pageSize = $this->parameters->get('limit'); $type = $request->get('type') ?? 'default'; $this->parameters->set('type', $type); @@ -106,8 +106,11 @@ class ListController extends Controller ->setPage($this->parameters->get('page')) // set types of transactions to return. ->setTypes($types); - if (null !== $this->parameters->get('start') && null !== $this->parameters->get('end')) { - $collector->setRange($this->parameters->get('start'), $this->parameters->get('end')); + if (null !== $this->parameters->get('start')) { + $collector->setStart($this->parameters->get('start')); + } + if (null !== $this->parameters->get('end')) { + $collector->setEnd($this->parameters->get('end')); } $paginator = $collector->getPaginatedGroups(); $paginator->setPath(route('api.v1.transactions.index') . $this->buildParams()); diff --git a/app/Api/V1/Controllers/Models/TransactionLinkType/ShowController.php b/app/Api/V1/Controllers/Models/TransactionLinkType/ShowController.php index 49f19afd4e..cc63966521 100644 --- a/app/Api/V1/Controllers/Models/TransactionLinkType/ShowController.php +++ b/app/Api/V1/Controllers/Models/TransactionLinkType/ShowController.php @@ -78,7 +78,7 @@ class ShowController extends Controller { // create some objects: $manager = $this->getManager(); - $pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; + $pageSize = $this->parameters->get('limit'); // get list of accounts. Count it and split it. $collection = $this->repository->get(); diff --git a/app/Api/V1/Controllers/Search/TransactionController.php b/app/Api/V1/Controllers/Search/TransactionController.php index 7fc503d201..2588d0520a 100644 --- a/app/Api/V1/Controllers/Search/TransactionController.php +++ b/app/Api/V1/Controllers/Search/TransactionController.php @@ -53,8 +53,7 @@ class TransactionController extends Controller $manager = $this->getManager(); $fullQuery = (string)$request->get('query'); $page = 0 === (int)$request->get('page') ? 1 : (int)$request->get('page'); - $pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; - $pageSize = 0 === (int)$request->get('limit') ? $pageSize : (int)$request->get('limit'); + $pageSize = $this->parameters->get('limit'); $searcher->parseQuery($fullQuery); $searcher->setPage($page); $searcher->setLimit($pageSize); diff --git a/app/Api/V1/Controllers/System/UserController.php b/app/Api/V1/Controllers/System/UserController.php index 413bf3a037..b0c6e519bc 100644 --- a/app/Api/V1/Controllers/System/UserController.php +++ b/app/Api/V1/Controllers/System/UserController.php @@ -101,7 +101,7 @@ class UserController extends Controller public function index(): JsonResponse { // user preferences - $pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; + $pageSize = $this->parameters->get('limit'); $manager = $this->getManager(); // build collection diff --git a/app/Api/V1/Controllers/User/PreferencesController.php b/app/Api/V1/Controllers/User/PreferencesController.php index 6d618fc86c..325e567814 100644 --- a/app/Api/V1/Controllers/User/PreferencesController.php +++ b/app/Api/V1/Controllers/User/PreferencesController.php @@ -58,7 +58,7 @@ class PreferencesController extends Controller $collection = app('preferences')->all(); $manager = $this->getManager(); $count = $collection->count(); - $pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; + $pageSize = $this->parameters->get('limit'); $preferences = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize); // make paginator: diff --git a/app/Api/V1/Controllers/Webhook/AttemptController.php b/app/Api/V1/Controllers/Webhook/AttemptController.php index a64066da1f..901e22519e 100644 --- a/app/Api/V1/Controllers/Webhook/AttemptController.php +++ b/app/Api/V1/Controllers/Webhook/AttemptController.php @@ -76,7 +76,7 @@ class AttemptController extends Controller } $manager = $this->getManager(); - $pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; + $pageSize = $this->parameters->get('limit'); $collection = $this->repository->getAttempts($message); $count = $collection->count(); $attempts = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize); diff --git a/app/Api/V1/Controllers/Webhook/MessageController.php b/app/Api/V1/Controllers/Webhook/MessageController.php index cdcefd9885..53b427af0e 100644 --- a/app/Api/V1/Controllers/Webhook/MessageController.php +++ b/app/Api/V1/Controllers/Webhook/MessageController.php @@ -70,7 +70,7 @@ class MessageController extends Controller public function index(Webhook $webhook): JsonResponse { $manager = $this->getManager(); - $pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; + $pageSize = $this->parameters->get('limit'); $collection = $this->repository->getMessages($webhook); $count = $collection->count(); diff --git a/app/Api/V1/Controllers/Webhook/ShowController.php b/app/Api/V1/Controllers/Webhook/ShowController.php index e675e62b27..4ad46fdacc 100644 --- a/app/Api/V1/Controllers/Webhook/ShowController.php +++ b/app/Api/V1/Controllers/Webhook/ShowController.php @@ -74,7 +74,7 @@ class ShowController extends Controller { $manager = $this->getManager(); $collection = $this->repository->all(); - $pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; + $pageSize = $this->parameters->get('limit'); $count = $collection->count(); $webhooks = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize); diff --git a/app/Api/V2/Controllers/Controller.php b/app/Api/V2/Controllers/Controller.php index 2dfd00b8aa..93eccb8aff 100644 --- a/app/Api/V2/Controllers/Controller.php +++ b/app/Api/V2/Controllers/Controller.php @@ -49,7 +49,6 @@ use Symfony\Component\HttpFoundation\ParameterBag; class Controller extends BaseController { protected const CONTENT_TYPE = 'application/vnd.api+json'; - protected int $pageSize; protected ParameterBag $parameters; /** @@ -58,10 +57,6 @@ class Controller extends BaseController public function __construct() { $this->parameters = $this->getParameters(); - $this->pageSize = 50; - if (auth()->check()) { - $this->pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; - } } /** @@ -129,6 +124,11 @@ class Controller extends BaseController if (null !== $value) { $bag->set($integer, (int)$value); } + if (null === $value && 'limit' === $integer) { + // set default for user: + $pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; + $bag->set($integer, $pageSize); + } } // sort fields: diff --git a/app/Api/V2/Controllers/Model/Bill/ShowController.php b/app/Api/V2/Controllers/Model/Bill/ShowController.php index 33fece0c92..6c2793fa1c 100644 --- a/app/Api/V2/Controllers/Model/Bill/ShowController.php +++ b/app/Api/V2/Controllers/Model/Bill/ShowController.php @@ -74,7 +74,7 @@ class ShowController extends Controller { $this->repository->correctOrder(); $bills = $this->repository->getBills(); - $pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; + $pageSize = $this->parameters->get('limit'); $count = $bills->count(); $bills = $bills->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize); $paginator = new LengthAwarePaginator($bills, $count, $pageSize, $this->parameters->get('page')); diff --git a/app/Api/V2/Controllers/Model/Budget/ListController.php b/app/Api/V2/Controllers/Model/Budget/ListController.php index 3a3cca394d..b7bbaff1c7 100644 --- a/app/Api/V2/Controllers/Model/Budget/ListController.php +++ b/app/Api/V2/Controllers/Model/Budget/ListController.php @@ -64,9 +64,9 @@ class ListController extends Controller exit; $collection = $this->repository->getActiveBudgets(); $total = $collection->count(); - $collection->slice($this->pageSize * $this->parameters->get('page'), $this->pageSize); + $collection->slice($this->pageXSize * $this->parameters->get('page'), $this->pXageSize); - $paginator = new LengthAwarePaginator($collection, $total, $this->pageSize, $this->parameters->get('page')); + $paginator = new LengthAwarePaginator($collection, $total, $this->pagXeSize, $this->parameters->get('page')); $transformer = new BudgetTransformer(); return response() diff --git a/app/Api/V2/Controllers/Model/BudgetLimit/ListController.php b/app/Api/V2/Controllers/Model/BudgetLimit/ListController.php index 701f064b6d..cf7ef4f9d7 100644 --- a/app/Api/V2/Controllers/Model/BudgetLimit/ListController.php +++ b/app/Api/V2/Controllers/Model/BudgetLimit/ListController.php @@ -57,12 +57,13 @@ class ListController extends Controller */ public function index(DateRequest $request, Budget $budget): JsonResponse { + $pageSize = $this->parameters->get('limit'); $dates = $request->getAll(); $collection = $this->repository->getBudgetLimits($budget, $dates['start'], $dates['end']); $total = $collection->count(); - $collection->slice($this->pageSize * $this->parameters->get('page'), $this->pageSize); + $collection->slice($pageSize * $this->parameters->get('page'), $pageSize); - $paginator = new LengthAwarePaginator($collection, $total, $this->pageSize, $this->parameters->get('page')); + $paginator = new LengthAwarePaginator($collection, $total, $pageSize, $this->parameters->get('page')); $transformer = new BudgetLimitTransformer(); return response() diff --git a/app/Api/V2/Controllers/Model/PiggyBank/ShowController.php b/app/Api/V2/Controllers/Model/PiggyBank/ShowController.php index 57eac1739a..e75e8b8866 100644 --- a/app/Api/V2/Controllers/Model/PiggyBank/ShowController.php +++ b/app/Api/V2/Controllers/Model/PiggyBank/ShowController.php @@ -70,7 +70,7 @@ class ShowController extends Controller public function index(Request $request): JsonResponse { $piggies = $this->repository->getPiggyBanks(); - $pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; + $pageSize = $this->parameters->get('limit'); $count = $piggies->count(); $piggies = $piggies->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize); $paginator = new LengthAwarePaginator($piggies, $count, $pageSize, $this->parameters->get('page')); diff --git a/app/Api/V2/Controllers/Transaction/List/AccountController.php b/app/Api/V2/Controllers/Transaction/List/AccountController.php index 625675bb54..ceb6f7802d 100644 --- a/app/Api/V2/Controllers/Transaction/List/AccountController.php +++ b/app/Api/V2/Controllers/Transaction/List/AccountController.php @@ -52,20 +52,16 @@ class AccountController extends Controller public function list(ListRequest $request, Account $account): JsonResponse { // collect transactions: - $limit = $request->getLimit(); - $page = $request->getPage(); - $page = max($page, 1); - - if ($limit > 0 && $limit <= $this->pageSize) { - $this->pageSize = $limit; - } + $page = $request->getPage(); + $page = max($page, 1); + $pageSize = $this->parameters->get('limit'); /** @var GroupCollectorInterface $collector */ $collector = app(GroupCollectorInterface::class); $collector->setAccounts(new Collection([$account])) ->withAPIInformation() - ->setLimit($this->pageSize) + ->setLimit($pageSize) ->setPage($page) ->setTypes($request->getTransactionTypes()); @@ -85,7 +81,7 @@ class AccountController extends Controller sprintf( '%s?%s', route('api.v2.accounts.transactions', [$account->id]), - $request->buildParams() + $request->buildParams($pageSize) ) ); diff --git a/app/Api/V2/Controllers/Transaction/List/TransactionController.php b/app/Api/V2/Controllers/Transaction/List/TransactionController.php index 9bcfcbf3de..9bcc831a16 100644 --- a/app/Api/V2/Controllers/Transaction/List/TransactionController.php +++ b/app/Api/V2/Controllers/Transaction/List/TransactionController.php @@ -42,20 +42,16 @@ class TransactionController extends Controller public function list(ListRequest $request): JsonResponse { // collect transactions: - $limit = $request->getLimit(); - $page = $request->getPage(); - $page = max($page, 1); - - if ($limit > 0 && $limit <= $this->pageSize) { - $this->pageSize = $limit; - } + $pageSize = $this->parameters->get('limit'); + $page = $request->getPage(); + $page = max($page, 1); /** @var GroupCollectorInterface $collector */ $collector = app(GroupCollectorInterface::class); $collector->setUserGroup(auth()->user()->userGroup) ->withAPIInformation() - ->setLimit($this->pageSize) + ->setLimit($pageSize) ->setPage($page) ->setTypes($request->getTransactionTypes()); @@ -72,11 +68,12 @@ class TransactionController extends Controller // exit; $paginator = $collector->getPaginatedGroups(); + $params = $request->buildParams($pageSize); $paginator->setPath( sprintf( '%s?%s', route('api.v2.transactions.list'), - $request->buildParams() + $params ) ); diff --git a/app/Api/V2/Controllers/UserGroup/ShowController.php b/app/Api/V2/Controllers/UserGroup/ShowController.php index afd87d4706..fbc441427e 100644 --- a/app/Api/V2/Controllers/UserGroup/ShowController.php +++ b/app/Api/V2/Controllers/UserGroup/ShowController.php @@ -64,6 +64,7 @@ class ShowController extends Controller public function index(Request $request): JsonResponse { $collection = new Collection(); + $pageSize = $this->parameters->get('limit'); // if the user has the system owner role, get all. Otherwise, get only the users' groups. if (!auth()->user()->hasRole('owner')) { $collection = $this->repository->get(); @@ -72,9 +73,9 @@ class ShowController extends Controller $collection = $this->repository->getAll(); } $count = $collection->count(); - $userGroups = $collection->slice(($this->parameters->get('page') - 1) * $this->pageSize, $this->pageSize); + $userGroups = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize); - $paginator = new LengthAwarePaginator($userGroups, $count, $this->pageSize, $this->parameters->get('page')); + $paginator = new LengthAwarePaginator($userGroups, $count, $pageSize, $this->parameters->get('page')); $transformer = new UserGroupTransformer(); $transformer->setParameters($this->parameters); // give params to transformer diff --git a/app/Api/V2/Request/Model/Transaction/ListRequest.php b/app/Api/V2/Request/Model/Transaction/ListRequest.php index 4a0dbc2a61..8913feea10 100644 --- a/app/Api/V2/Request/Model/Transaction/ListRequest.php +++ b/app/Api/V2/Request/Model/Transaction/ListRequest.php @@ -43,10 +43,11 @@ class ListRequest extends FormRequest /** * @return string */ - public function buildParams(): string + public function buildParams(int $pageSize): string { $array = [ - 'page' => $this->getPage(), + 'page' => $this->getPage(), + 'limit' => $pageSize, ]; $start = $this->getStartDate(); @@ -55,9 +56,6 @@ class ListRequest extends FormRequest $array['start'] = $start->format('Y-m-d'); $array['end'] = $end->format('Y-m-d'); } - if (0 !== $this->getLimit()) { - $array['limit'] = $this->getLimit(); - } return http_build_query($array); } @@ -86,14 +84,6 @@ class ListRequest extends FormRequest return $this->getCarbonDate('end'); } - /** - * @return int - */ - public function getLimit(): int - { - return $this->convertInteger('limit'); - } - /** * @return array */