Add limit param to all endpoints

This commit is contained in:
James Cole 2023-10-05 18:52:01 +02:00
parent a29d056a9b
commit 664a08d42f
No known key found for this signature in database
GPG Key ID: B49A324B7EAD6D80
46 changed files with 136 additions and 138 deletions

View File

@ -137,6 +137,11 @@ abstract class Controller extends BaseController
if (null !== $value) { if (null !== $value) {
$bag->set($integer, (int)$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: // sort fields:

View File

@ -81,7 +81,7 @@ class ListController extends Controller
public function attachments(Account $account): JsonResponse public function attachments(Account $account): JsonResponse
{ {
$manager = $this->getManager(); $manager = $this->getManager();
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; $pageSize = $this->parameters->get('limit');
$collection = $this->repository->getAttachments($account); $collection = $this->repository->getAttachments($account);
$count = $collection->count(); $count = $collection->count();
@ -116,7 +116,7 @@ class ListController extends Controller
$manager = $this->getManager(); $manager = $this->getManager();
// types to get, page size: // 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. // get list of budgets. Count it and split it.
$collection = $this->repository->getPiggyBanks($account); $collection = $this->repository->getPiggyBanks($account);
@ -152,15 +152,9 @@ class ListController extends Controller
*/ */
public function transactions(Request $request, Account $account): JsonResponse 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'; $type = $request->get('type') ?? 'default';
$this->parameters->set('type', $type); $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')); $types = $this->mapTransactionTypes($this->parameters->get('type'));
$manager = $this->getManager(); $manager = $this->getManager();
/** @var User $admin */ /** @var User $admin */
@ -172,8 +166,11 @@ class ListController extends Controller
$collector->setUser($admin)->setAccounts(new Collection([$account])) $collector->setUser($admin)->setAccounts(new Collection([$account]))
->withAPIInformation()->setLimit($pageSize)->setPage($this->parameters->get('page'))->setTypes($types); ->withAPIInformation()->setLimit($pageSize)->setPage($this->parameters->get('page'))->setTypes($types);
if (null !== $this->parameters->get('start') && null !== $this->parameters->get('end')) { if (null !== $this->parameters->get('start')) {
$collector->setRange($this->parameters->get('start'), $this->parameters->get('end')); $collector->setStart($this->parameters->get('start'));
}
if (null !== $this->parameters->get('end')) {
$collector->setEnd($this->parameters->get('end'));
} }
$paginator = $collector->getPaginatedGroups(); $paginator = $collector->getPaginatedGroups();

View File

@ -84,7 +84,7 @@ class ShowController extends Controller
// types to get, page size: // types to get, page size:
$types = $this->mapAccountTypes($this->parameters->get('type')); $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. // get list of accounts. Count it and split it.
$this->repository->resetAccountOrder(); $this->repository->resetAccountOrder();

View File

@ -123,7 +123,7 @@ class ShowController extends Controller
$manager = $this->getManager(); $manager = $this->getManager();
// types to get, page size: // 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. // get list of attachments. Count it and split it.
$collection = $this->repository->get(); $collection = $this->repository->get();

View File

@ -76,7 +76,7 @@ class ShowController extends Controller
$manager = $this->getManager(); $manager = $this->getManager();
// types to get, page size: // 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'); $start = $this->parameters->get('start');
$end = $this->parameters->get('end'); $end = $this->parameters->get('end');

View File

@ -80,7 +80,7 @@ class ListController extends Controller
public function attachments(Bill $bill): JsonResponse public function attachments(Bill $bill): JsonResponse
{ {
$manager = $this->getManager(); $manager = $this->getManager();
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; $pageSize = $this->parameters->get('limit');
$collection = $this->repository->getAttachments($bill); $collection = $this->repository->getAttachments($bill);
$count = $collection->count(); $count = $collection->count();
@ -116,7 +116,7 @@ class ListController extends Controller
$manager = $this->getManager(); $manager = $this->getManager();
// types to get, page size: // 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. // get list of budgets. Count it and split it.
$collection = $this->repository->getRulesForBill($bill); $collection = $this->repository->getRulesForBill($bill);
@ -151,7 +151,7 @@ class ListController extends Controller
*/ */
public function transactions(Request $request, Bill $bill): JsonResponse 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'; $type = $request->get('type') ?? 'default';
$this->parameters->set('type', $type); $this->parameters->set('type', $type);
@ -177,9 +177,11 @@ class ListController extends Controller
// set types of transactions to return. // set types of transactions to return.
->setTypes($types); ->setTypes($types);
// do parameter stuff on new group collector. if (null !== $this->parameters->get('start')) {
if (null !== $this->parameters->get('start') && null !== $this->parameters->get('end')) { $collector->setStart($this->parameters->get('start'));
$collector->setRange($this->parameters->get('start'), $this->parameters->get('end')); }
if (null !== $this->parameters->get('end')) {
$collector->setEnd($this->parameters->get('end'));
} }
// get paginator. // get paginator.

View File

@ -73,7 +73,7 @@ class ShowController extends Controller
$this->repository->correctOrder(); $this->repository->correctOrder();
$bills = $this->repository->getBills(); $bills = $this->repository->getBills();
$manager = $this->getManager(); $manager = $this->getManager();
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; $pageSize = $this->parameters->get('limit');
$count = $bills->count(); $count = $bills->count();
$bills = $bills->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize); $bills = $bills->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
$paginator = new LengthAwarePaginator($bills, $count, $pageSize, $this->parameters->get('page')); $paginator = new LengthAwarePaginator($bills, $count, $pageSize, $this->parameters->get('page'));

View File

@ -82,7 +82,7 @@ class ListController extends Controller
public function attachments(Budget $budget): JsonResponse public function attachments(Budget $budget): JsonResponse
{ {
$manager = $this->getManager(); $manager = $this->getManager();
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; $pageSize = $this->parameters->get('limit');
$collection = $this->repository->getAttachments($budget); $collection = $this->repository->getAttachments($budget);
$count = $collection->count(); $count = $collection->count();
@ -116,7 +116,7 @@ class ListController extends Controller
public function budgetLimits(Budget $budget): JsonResponse public function budgetLimits(Budget $budget): JsonResponse
{ {
$manager = $this->getManager(); $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); $this->parameters->set('budget_id', $budget->id);
$collection = $this->blRepository->getBudgetLimits($budget, $this->parameters->get('start'), $this->parameters->get('end')); $collection = $this->blRepository->getBudgetLimits($budget, $this->parameters->get('start'), $this->parameters->get('end'));
$count = $collection->count(); $count = $collection->count();
@ -148,13 +148,7 @@ class ListController extends Controller
*/ */
public function transactions(Request $request, Budget $budget): JsonResponse public function transactions(Request $request, Budget $budget): JsonResponse
{ {
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; $pageSize = $this->parameters->get('limit');
// user can overrule page size with limit parameter.
$limit = $this->parameters->get('limit');
if (null !== $limit && $limit > 0) {
$pageSize = $limit;
}
$type = $request->get('type') ?? 'default'; $type = $request->get('type') ?? 'default';
$this->parameters->set('type', $type); $this->parameters->set('type', $type);
@ -181,8 +175,11 @@ class ListController extends Controller
// set types of transactions to return. // set types of transactions to return.
->setTypes($types); ->setTypes($types);
if (null !== $this->parameters->get('start') && null !== $this->parameters->get('end')) { if (null !== $this->parameters->get('start')) {
$collector->setRange($this->parameters->get('start'), $this->parameters->get('end')); $collector->setStart($this->parameters->get('start'));
}
if (null !== $this->parameters->get('end')) {
$collector->setEnd($this->parameters->get('end'));
} }
$paginator = $collector->getPaginatedGroups(); $paginator = $collector->getPaginatedGroups();
@ -211,13 +208,7 @@ class ListController extends Controller
*/ */
public function withoutBudget(Request $request): JsonResponse public function withoutBudget(Request $request): JsonResponse
{ {
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; $pageSize = $this->parameters->get('limit');
// user can overrule page size with limit parameter.
$limit = $this->parameters->get('limit');
if (null !== $limit && $limit > 0) {
$pageSize = $limit;
}
$type = $request->get('type') ?? 'default'; $type = $request->get('type') ?? 'default';
$this->parameters->set('type', $type); $this->parameters->set('type', $type);
@ -244,8 +235,11 @@ class ListController extends Controller
// set types of transactions to return. // set types of transactions to return.
->setTypes($types); ->setTypes($types);
if (null !== $this->parameters->get('start') && null !== $this->parameters->get('end')) { if (null !== $this->parameters->get('start')) {
$collector->setRange($this->parameters->get('start'), $this->parameters->get('end')); $collector->setStart($this->parameters->get('start'));
}
if (null !== $this->parameters->get('end')) {
$collector->setEnd($this->parameters->get('end'));
} }
$paginator = $collector->getPaginatedGroups(); $paginator = $collector->getPaginatedGroups();

View File

@ -77,7 +77,7 @@ class ShowController extends Controller
$manager = $this->getManager(); $manager = $this->getManager();
// types to get, page size: // 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. // get list of budgets. Count it and split it.
$collection = $this->repository->getBudgets(); $collection = $this->repository->getBudgets();

View File

@ -80,7 +80,7 @@ class ListController extends Controller
*/ */
public function transactions(Request $request, Budget $budget, BudgetLimit $budgetLimit): JsonResponse 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'; $type = $request->get('type') ?? 'default';
$this->parameters->set('type', $type); $this->parameters->set('type', $type);

View File

@ -85,7 +85,7 @@ class ShowController extends Controller
{ {
$manager = $this->getManager(); $manager = $this->getManager();
$manager->parseIncludes('budget'); $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')); $collection = $this->blRepository->getBudgetLimits($budget, $this->parameters->get('start'), $this->parameters->get('end'));
$count = $collection->count(); $count = $collection->count();
$budgetLimits = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize); $budgetLimits = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
@ -117,7 +117,7 @@ class ShowController extends Controller
{ {
$manager = $this->getManager(); $manager = $this->getManager();
$manager->parseIncludes('budget'); $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')); $collection = $this->blRepository->getAllBudgetLimits($this->parameters->get('start'), $this->parameters->get('end'));
$count = $collection->count(); $count = $collection->count();
$budgetLimits = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize); $budgetLimits = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);

View File

@ -77,7 +77,7 @@ class ListController extends Controller
public function attachments(Category $category): JsonResponse public function attachments(Category $category): JsonResponse
{ {
$manager = $this->getManager(); $manager = $this->getManager();
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; $pageSize = $this->parameters->get('limit');
$collection = $this->repository->getAttachments($category); $collection = $this->repository->getAttachments($category);
$count = $collection->count(); $count = $collection->count();
@ -112,7 +112,7 @@ class ListController extends Controller
*/ */
public function transactions(Request $request, Category $category): JsonResponse 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'; $type = $request->get('type') ?? 'default';
$this->parameters->set('type', $type); $this->parameters->set('type', $type);
@ -138,8 +138,11 @@ class ListController extends Controller
// set types of transactions to return. // set types of transactions to return.
->setTypes($types); ->setTypes($types);
if (null !== $this->parameters->get('start') && null !== $this->parameters->get('end')) { if (null !== $this->parameters->get('start')) {
$collector->setRange($this->parameters->get('start'), $this->parameters->get('end')); $collector->setStart($this->parameters->get('start'));
}
if (null !== $this->parameters->get('end')) {
$collector->setEnd($this->parameters->get('end'));
} }
$paginator = $collector->getPaginatedGroups(); $paginator = $collector->getPaginatedGroups();

View File

@ -73,7 +73,7 @@ class ShowController extends Controller
$manager = $this->getManager(); $manager = $this->getManager();
// types to get, page size: // 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. // get list of budgets. Count it and split it.
$collection = $this->repository->getCategories(); $collection = $this->repository->getCategories();

View File

@ -77,7 +77,7 @@ class ListController extends Controller
{ {
$manager = $this->getManager(); $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. // get list of piggy banks. Count it and split it.
$collection = $this->repository->getBills($objectGroup); $collection = $this->repository->getBills($objectGroup);
$count = $collection->count(); $count = $collection->count();
@ -114,7 +114,7 @@ class ListController extends Controller
$manager = $this->getManager(); $manager = $this->getManager();
// types to get, page size: // 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. // get list of piggy banks. Count it and split it.
$collection = $this->repository->getPiggyBanks($objectGroup); $collection = $this->repository->getPiggyBanks($objectGroup);

View File

@ -79,7 +79,7 @@ class ShowController extends Controller
$manager = $this->getManager(); $manager = $this->getManager();
// types to get, page size: // types to get, page size:
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; $pageSize = $this->parameters->get('limit');
$this->repository->resetOrder(); $this->repository->resetOrder();
$collection = $this->repository->get(); $collection = $this->repository->get();

View File

@ -71,7 +71,7 @@ class ListController extends Controller
public function attachments(PiggyBank $piggyBank): JsonResponse public function attachments(PiggyBank $piggyBank): JsonResponse
{ {
$manager = $this->getManager(); $manager = $this->getManager();
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; $pageSize = $this->parameters->get('limit');
$collection = $this->repository->getAttachments($piggyBank); $collection = $this->repository->getAttachments($piggyBank);
$count = $collection->count(); $count = $collection->count();
@ -105,7 +105,7 @@ class ListController extends Controller
public function piggyBankEvents(PiggyBank $piggyBank): JsonResponse public function piggyBankEvents(PiggyBank $piggyBank): JsonResponse
{ {
// types to get, page size: // types to get, page size:
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; $pageSize = $this->parameters->get('limit');
$manager = $this->getManager(); $manager = $this->getManager();
$collection = $this->repository->getEvents($piggyBank); $collection = $this->repository->getEvents($piggyBank);

View File

@ -72,7 +72,7 @@ class ShowController extends Controller
{ {
$manager = $this->getManager(); $manager = $this->getManager();
// types to get, page size: // 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. // get list of budgets. Count it and split it.
$collection = $this->repository->getPiggyBanks(); $collection = $this->repository->getPiggyBanks();

View File

@ -77,7 +77,7 @@ class ListController extends Controller
*/ */
public function transactions(Request $request, Recurrence $recurrence): JsonResponse 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'; $type = $request->get('type') ?? 'default';
$this->parameters->set('type', $type); $this->parameters->set('type', $type);
@ -105,9 +105,13 @@ class ListController extends Controller
// set types of transactions to return. // set types of transactions to return.
->setTypes($types); ->setTypes($types);
if (null !== $this->parameters->get('start') && null !== $this->parameters->get('end')) { if (null !== $this->parameters->get('start')) {
$collector->setRange($this->parameters->get('start'), $this->parameters->get('end')); $collector->setStart($this->parameters->get('start'));
} }
if (null !== $this->parameters->get('end')) {
$collector->setEnd($this->parameters->get('end'));
}
$paginator = $collector->getPaginatedGroups(); $paginator = $collector->getPaginatedGroups();
$paginator->setPath(route('api.v1.transactions.index') . $this->buildParams()); $paginator->setPath(route('api.v1.transactions.index') . $this->buildParams());
$transactions = $paginator->getCollection(); $transactions = $paginator->getCollection();

View File

@ -73,7 +73,7 @@ class ShowController extends Controller
$manager = $this->getManager(); $manager = $this->getManager();
// types to get, page size: // 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. // get list of budgets. Count it and split it.
$collection = $this->repository->get(); $collection = $this->repository->get();

View File

@ -77,7 +77,7 @@ class ShowController extends Controller
$manager = $this->getManager(); $manager = $this->getManager();
// types to get, page size: // 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. // get list of budgets. Count it and split it.
$collection = $this->ruleRepository->getAll(); $collection = $this->ruleRepository->getAll();

View File

@ -75,7 +75,7 @@ class ListController extends Controller
{ {
$manager = $this->getManager(); $manager = $this->getManager();
// types to get, page size: // 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. // get list of budgets. Count it and split it.
$collection = $this->ruleGroupRepository->getRules($group); $collection = $this->ruleGroupRepository->getRules($group);

View File

@ -75,7 +75,7 @@ class ShowController extends Controller
{ {
$manager = $this->getManager(); $manager = $this->getManager();
// types to get, page size: // 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. // get list of rule groups. Count it and split it.
$collection = $this->ruleGroupRepository->get(); $collection = $this->ruleGroupRepository->get();

View File

@ -80,7 +80,7 @@ class ListController extends Controller
public function attachments(Tag $tag): JsonResponse public function attachments(Tag $tag): JsonResponse
{ {
$manager = $this->getManager(); $manager = $this->getManager();
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; $pageSize = $this->parameters->get('limit');
$collection = $this->repository->getAttachments($tag); $collection = $this->repository->getAttachments($tag);
$count = $collection->count(); $count = $collection->count();
@ -114,7 +114,7 @@ class ListController extends Controller
*/ */
public function transactions(Request $request, Tag $tag): JsonResponse 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'; $type = $request->get('type') ?? 'default';
$this->parameters->set('type', $type); $this->parameters->set('type', $type);
@ -139,8 +139,11 @@ class ListController extends Controller
// set types of transactions to return. // set types of transactions to return.
->setTypes($types); ->setTypes($types);
if (null !== $this->parameters->get('start') && null !== $this->parameters->get('end')) { if (null !== $this->parameters->get('start')) {
$collector->setRange($this->parameters->get('start'), $this->parameters->get('end')); $collector->setStart($this->parameters->get('start'));
}
if (null !== $this->parameters->get('end')) {
$collector->setEnd($this->parameters->get('end'));
} }
$paginator = $collector->getPaginatedGroups(); $paginator = $collector->getPaginatedGroups();
$paginator->setPath(route('api.v1.tags.transactions', [$tag->id]) . $this->buildParams()); $paginator->setPath(route('api.v1.tags.transactions', [$tag->id]) . $this->buildParams());

View File

@ -76,7 +76,7 @@ class ShowController extends Controller
{ {
$manager = $this->getManager(); $manager = $this->getManager();
// types to get, page size: // 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. // get list of budgets. Count it and split it.
$collection = $this->repository->get(); $collection = $this->repository->get();

View File

@ -78,7 +78,7 @@ class ListController extends Controller
public function attachments(TransactionGroup $transactionGroup): JsonResponse public function attachments(TransactionGroup $transactionGroup): JsonResponse
{ {
$manager = $this->getManager(); $manager = $this->getManager();
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; $pageSize = $this->parameters->get('limit');
$collection = new Collection(); $collection = new Collection();
foreach ($transactionGroup->transactionJournals as $transactionJournal) { foreach ($transactionGroup->transactionJournals as $transactionJournal) {
$collection = $this->journalAPIRepository->getAttachments($transactionJournal)->merge($collection); $collection = $this->journalAPIRepository->getAttachments($transactionJournal)->merge($collection);
@ -114,7 +114,7 @@ class ListController extends Controller
{ {
$manager = $this->getManager(); $manager = $this->getManager();
$collection = new Collection(); $collection = new Collection();
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; $pageSize = $this->parameters->get('limit');
foreach ($transactionGroup->transactionJournals as $transactionJournal) { foreach ($transactionGroup->transactionJournals as $transactionJournal) {
$collection = $this->journalAPIRepository->getPiggyBankEvents($transactionJournal)->merge($collection); $collection = $this->journalAPIRepository->getPiggyBankEvents($transactionJournal)->merge($collection);
} }
@ -152,7 +152,7 @@ class ListController extends Controller
{ {
$manager = $this->getManager(); $manager = $this->getManager();
$collection = $this->journalAPIRepository->getJournalLinks($transactionJournal); $collection = $this->journalAPIRepository->getJournalLinks($transactionJournal);
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; $pageSize = $this->parameters->get('limit');
$count = $collection->count(); $count = $collection->count();
$journalLinks = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize); $journalLinks = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);

View File

@ -58,7 +58,7 @@ class ShowController extends Controller
*/ */
public function index(Request $request): JsonResponse 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'; $type = $request->get('type') ?? 'default';
$this->parameters->set('type', $type); $this->parameters->set('type', $type);

View File

@ -106,7 +106,7 @@ class ListController extends Controller
// types to get, page size: // types to get, page size:
$types = $this->mapAccountTypes($this->parameters->get('type')); $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. // get list of accounts. Count it and split it.
/** @var AccountRepositoryInterface $accountRepository */ /** @var AccountRepositoryInterface $accountRepository */
@ -153,7 +153,7 @@ class ListController extends Controller
{ {
$manager = $this->getManager(); $manager = $this->getManager();
// types to get, page size: // 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. // get list of available budgets. Count it and split it.
/** @var AvailableBudgetRepositoryInterface $abRepository */ /** @var AvailableBudgetRepositoryInterface $abRepository */
@ -193,7 +193,7 @@ class ListController extends Controller
/** @var BillRepositoryInterface $billRepos */ /** @var BillRepositoryInterface $billRepos */
$billRepos = app(BillRepositoryInterface::class); $billRepos = app(BillRepositoryInterface::class);
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; $pageSize = $this->parameters->get('limit');
$unfiltered = $billRepos->getBills(); $unfiltered = $billRepos->getBills();
// filter and paginate list: // filter and paginate list:
@ -236,7 +236,7 @@ class ListController extends Controller
$blRepository = app(BudgetLimitRepositoryInterface::class); $blRepository = app(BudgetLimitRepositoryInterface::class);
$manager = $this->getManager(); $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')); $collection = $blRepository->getAllBudgetLimitsByCurrency($currency, $this->parameters->get('start'), $this->parameters->get('end'));
$count = $collection->count(); $count = $collection->count();
$budgetLimits = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize); $budgetLimits = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
@ -268,7 +268,7 @@ class ListController extends Controller
{ {
$manager = $this->getManager(); $manager = $this->getManager();
// types to get, page size: // 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. // get list of budgets. Count it and split it.
/** @var RecurringRepositoryInterface $recurringRepos */ /** @var RecurringRepositoryInterface $recurringRepos */
@ -319,7 +319,7 @@ class ListController extends Controller
public function rules(TransactionCurrency $currency): JsonResponse public function rules(TransactionCurrency $currency): JsonResponse
{ {
$manager = $this->getManager(); $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. // get list of budgets. Count it and split it.
/** @var RuleRepositoryInterface $ruleRepos */ /** @var RuleRepositoryInterface $ruleRepos */
@ -371,7 +371,7 @@ class ListController extends Controller
*/ */
public function transactions(Request $request, TransactionCurrency $currency): JsonResponse 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'; $type = $request->get('type') ?? 'default';
$this->parameters->set('type', $type); $this->parameters->set('type', $type);
@ -396,8 +396,11 @@ class ListController extends Controller
->setPage($this->parameters->get('page')) ->setPage($this->parameters->get('page'))
// set types of transactions to return. // set types of transactions to return.
->setTypes($types); ->setTypes($types);
if (null !== $this->parameters->get('start') && null !== $this->parameters->get('end')) { if (null !== $this->parameters->get('start')) {
$collector->setRange($this->parameters->get('start'), $this->parameters->get('end')); $collector->setStart($this->parameters->get('start'));
}
if (null !== $this->parameters->get('end')) {
$collector->setEnd($this->parameters->get('end'));
} }
$paginator = $collector->getPaginatedGroups(); $paginator = $collector->getPaginatedGroups();
$paginator->setPath(route('api.v1.currencies.transactions', [$currency->code]) . $this->buildParams()); $paginator->setPath(route('api.v1.currencies.transactions', [$currency->code]) . $this->buildParams());

View File

@ -78,7 +78,7 @@ class ShowController extends Controller
*/ */
public function index(): JsonResponse public function index(): JsonResponse
{ {
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; $pageSize = $this->parameters->get('limit');
$collection = $this->repository->getAll(); $collection = $this->repository->getAll();
$count = $collection->count(); $count = $collection->count();
// slice them: // slice them:

View File

@ -85,7 +85,7 @@ class ShowController extends Controller
$name = $request->get('name'); $name = $request->get('name');
// types to get, page size: // 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); $linkType = $this->repository->findByName($name);
// get list of transaction links. Count it and split it. // get list of transaction links. Count it and split it.

View File

@ -78,7 +78,7 @@ class ListController extends Controller
*/ */
public function transactions(Request $request, LinkType $linkType): JsonResponse 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'; $type = $request->get('type') ?? 'default';
$this->parameters->set('type', $type); $this->parameters->set('type', $type);
@ -106,8 +106,11 @@ class ListController extends Controller
->setPage($this->parameters->get('page')) ->setPage($this->parameters->get('page'))
// set types of transactions to return. // set types of transactions to return.
->setTypes($types); ->setTypes($types);
if (null !== $this->parameters->get('start') && null !== $this->parameters->get('end')) { if (null !== $this->parameters->get('start')) {
$collector->setRange($this->parameters->get('start'), $this->parameters->get('end')); $collector->setStart($this->parameters->get('start'));
}
if (null !== $this->parameters->get('end')) {
$collector->setEnd($this->parameters->get('end'));
} }
$paginator = $collector->getPaginatedGroups(); $paginator = $collector->getPaginatedGroups();
$paginator->setPath(route('api.v1.transactions.index') . $this->buildParams()); $paginator->setPath(route('api.v1.transactions.index') . $this->buildParams());

View File

@ -78,7 +78,7 @@ class ShowController extends Controller
{ {
// create some objects: // create some objects:
$manager = $this->getManager(); $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. // get list of accounts. Count it and split it.
$collection = $this->repository->get(); $collection = $this->repository->get();

View File

@ -53,8 +53,7 @@ class TransactionController extends Controller
$manager = $this->getManager(); $manager = $this->getManager();
$fullQuery = (string)$request->get('query'); $fullQuery = (string)$request->get('query');
$page = 0 === (int)$request->get('page') ? 1 : (int)$request->get('page'); $page = 0 === (int)$request->get('page') ? 1 : (int)$request->get('page');
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; $pageSize = $this->parameters->get('limit');
$pageSize = 0 === (int)$request->get('limit') ? $pageSize : (int)$request->get('limit');
$searcher->parseQuery($fullQuery); $searcher->parseQuery($fullQuery);
$searcher->setPage($page); $searcher->setPage($page);
$searcher->setLimit($pageSize); $searcher->setLimit($pageSize);

View File

@ -101,7 +101,7 @@ class UserController extends Controller
public function index(): JsonResponse public function index(): JsonResponse
{ {
// user preferences // user preferences
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; $pageSize = $this->parameters->get('limit');
$manager = $this->getManager(); $manager = $this->getManager();
// build collection // build collection

View File

@ -58,7 +58,7 @@ class PreferencesController extends Controller
$collection = app('preferences')->all(); $collection = app('preferences')->all();
$manager = $this->getManager(); $manager = $this->getManager();
$count = $collection->count(); $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); $preferences = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
// make paginator: // make paginator:

View File

@ -76,7 +76,7 @@ class AttemptController extends Controller
} }
$manager = $this->getManager(); $manager = $this->getManager();
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; $pageSize = $this->parameters->get('limit');
$collection = $this->repository->getAttempts($message); $collection = $this->repository->getAttempts($message);
$count = $collection->count(); $count = $collection->count();
$attempts = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize); $attempts = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);

View File

@ -70,7 +70,7 @@ class MessageController extends Controller
public function index(Webhook $webhook): JsonResponse public function index(Webhook $webhook): JsonResponse
{ {
$manager = $this->getManager(); $manager = $this->getManager();
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; $pageSize = $this->parameters->get('limit');
$collection = $this->repository->getMessages($webhook); $collection = $this->repository->getMessages($webhook);
$count = $collection->count(); $count = $collection->count();

View File

@ -74,7 +74,7 @@ class ShowController extends Controller
{ {
$manager = $this->getManager(); $manager = $this->getManager();
$collection = $this->repository->all(); $collection = $this->repository->all();
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; $pageSize = $this->parameters->get('limit');
$count = $collection->count(); $count = $collection->count();
$webhooks = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize); $webhooks = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);

View File

@ -49,7 +49,6 @@ use Symfony\Component\HttpFoundation\ParameterBag;
class Controller extends BaseController class Controller extends BaseController
{ {
protected const CONTENT_TYPE = 'application/vnd.api+json'; protected const CONTENT_TYPE = 'application/vnd.api+json';
protected int $pageSize;
protected ParameterBag $parameters; protected ParameterBag $parameters;
/** /**
@ -58,10 +57,6 @@ class Controller extends BaseController
public function __construct() public function __construct()
{ {
$this->parameters = $this->getParameters(); $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) { if (null !== $value) {
$bag->set($integer, (int)$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: // sort fields:

View File

@ -74,7 +74,7 @@ class ShowController extends Controller
{ {
$this->repository->correctOrder(); $this->repository->correctOrder();
$bills = $this->repository->getBills(); $bills = $this->repository->getBills();
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; $pageSize = $this->parameters->get('limit');
$count = $bills->count(); $count = $bills->count();
$bills = $bills->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize); $bills = $bills->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
$paginator = new LengthAwarePaginator($bills, $count, $pageSize, $this->parameters->get('page')); $paginator = new LengthAwarePaginator($bills, $count, $pageSize, $this->parameters->get('page'));

View File

@ -64,9 +64,9 @@ class ListController extends Controller
exit; exit;
$collection = $this->repository->getActiveBudgets(); $collection = $this->repository->getActiveBudgets();
$total = $collection->count(); $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(); $transformer = new BudgetTransformer();
return response() return response()

View File

@ -57,12 +57,13 @@ class ListController extends Controller
*/ */
public function index(DateRequest $request, Budget $budget): JsonResponse public function index(DateRequest $request, Budget $budget): JsonResponse
{ {
$pageSize = $this->parameters->get('limit');
$dates = $request->getAll(); $dates = $request->getAll();
$collection = $this->repository->getBudgetLimits($budget, $dates['start'], $dates['end']); $collection = $this->repository->getBudgetLimits($budget, $dates['start'], $dates['end']);
$total = $collection->count(); $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(); $transformer = new BudgetLimitTransformer();
return response() return response()

View File

@ -70,7 +70,7 @@ class ShowController extends Controller
public function index(Request $request): JsonResponse public function index(Request $request): JsonResponse
{ {
$piggies = $this->repository->getPiggyBanks(); $piggies = $this->repository->getPiggyBanks();
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; $pageSize = $this->parameters->get('limit');
$count = $piggies->count(); $count = $piggies->count();
$piggies = $piggies->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize); $piggies = $piggies->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
$paginator = new LengthAwarePaginator($piggies, $count, $pageSize, $this->parameters->get('page')); $paginator = new LengthAwarePaginator($piggies, $count, $pageSize, $this->parameters->get('page'));

View File

@ -52,20 +52,16 @@ class AccountController extends Controller
public function list(ListRequest $request, Account $account): JsonResponse public function list(ListRequest $request, Account $account): JsonResponse
{ {
// collect transactions: // collect transactions:
$limit = $request->getLimit();
$page = $request->getPage(); $page = $request->getPage();
$page = max($page, 1); $page = max($page, 1);
$pageSize = $this->parameters->get('limit');
if ($limit > 0 && $limit <= $this->pageSize) {
$this->pageSize = $limit;
}
/** @var GroupCollectorInterface $collector */ /** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class); $collector = app(GroupCollectorInterface::class);
$collector->setAccounts(new Collection([$account])) $collector->setAccounts(new Collection([$account]))
->withAPIInformation() ->withAPIInformation()
->setLimit($this->pageSize) ->setLimit($pageSize)
->setPage($page) ->setPage($page)
->setTypes($request->getTransactionTypes()); ->setTypes($request->getTransactionTypes());
@ -85,7 +81,7 @@ class AccountController extends Controller
sprintf( sprintf(
'%s?%s', '%s?%s',
route('api.v2.accounts.transactions', [$account->id]), route('api.v2.accounts.transactions', [$account->id]),
$request->buildParams() $request->buildParams($pageSize)
) )
); );

View File

@ -42,20 +42,16 @@ class TransactionController extends Controller
public function list(ListRequest $request): JsonResponse public function list(ListRequest $request): JsonResponse
{ {
// collect transactions: // collect transactions:
$limit = $request->getLimit(); $pageSize = $this->parameters->get('limit');
$page = $request->getPage(); $page = $request->getPage();
$page = max($page, 1); $page = max($page, 1);
if ($limit > 0 && $limit <= $this->pageSize) {
$this->pageSize = $limit;
}
/** @var GroupCollectorInterface $collector */ /** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class); $collector = app(GroupCollectorInterface::class);
$collector->setUserGroup(auth()->user()->userGroup) $collector->setUserGroup(auth()->user()->userGroup)
->withAPIInformation() ->withAPIInformation()
->setLimit($this->pageSize) ->setLimit($pageSize)
->setPage($page) ->setPage($page)
->setTypes($request->getTransactionTypes()); ->setTypes($request->getTransactionTypes());
@ -72,11 +68,12 @@ class TransactionController extends Controller
// exit; // exit;
$paginator = $collector->getPaginatedGroups(); $paginator = $collector->getPaginatedGroups();
$params = $request->buildParams($pageSize);
$paginator->setPath( $paginator->setPath(
sprintf( sprintf(
'%s?%s', '%s?%s',
route('api.v2.transactions.list'), route('api.v2.transactions.list'),
$request->buildParams() $params
) )
); );

View File

@ -64,6 +64,7 @@ class ShowController extends Controller
public function index(Request $request): JsonResponse public function index(Request $request): JsonResponse
{ {
$collection = new Collection(); $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 the user has the system owner role, get all. Otherwise, get only the users' groups.
if (!auth()->user()->hasRole('owner')) { if (!auth()->user()->hasRole('owner')) {
$collection = $this->repository->get(); $collection = $this->repository->get();
@ -72,9 +73,9 @@ class ShowController extends Controller
$collection = $this->repository->getAll(); $collection = $this->repository->getAll();
} }
$count = $collection->count(); $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 = new UserGroupTransformer();
$transformer->setParameters($this->parameters); // give params to transformer $transformer->setParameters($this->parameters); // give params to transformer

View File

@ -43,10 +43,11 @@ class ListRequest extends FormRequest
/** /**
* @return string * @return string
*/ */
public function buildParams(): string public function buildParams(int $pageSize): string
{ {
$array = [ $array = [
'page' => $this->getPage(), 'page' => $this->getPage(),
'limit' => $pageSize,
]; ];
$start = $this->getStartDate(); $start = $this->getStartDate();
@ -55,9 +56,6 @@ class ListRequest extends FormRequest
$array['start'] = $start->format('Y-m-d'); $array['start'] = $start->format('Y-m-d');
$array['end'] = $end->format('Y-m-d'); $array['end'] = $end->format('Y-m-d');
} }
if (0 !== $this->getLimit()) {
$array['limit'] = $this->getLimit();
}
return http_build_query($array); return http_build_query($array);
} }
@ -86,14 +84,6 @@ class ListRequest extends FormRequest
return $this->getCarbonDate('end'); return $this->getCarbonDate('end');
} }
/**
* @return int
*/
public function getLimit(): int
{
return $this->convertInteger('limit');
}
/** /**
* @return array * @return array
*/ */