1
0
Fork 0
mirror of synced 2024-06-26 18:20:43 +12:00

feat(projects): add after pagination

This commit is contained in:
Torsten Dittmann 2021-08-06 14:36:17 +02:00
parent a49b12c542
commit ca9dafddae

View file

@ -166,16 +166,25 @@ App::get('/v1/projects')
->param('search', '', new Text(256), 'Search term to filter your list results. Max length: 256 chars.', true)
->param('limit', 25, new Range(0, 100), 'Results limit value. By default will return maximum 25 results. Maximum of 100 results allowed per request.', true)
->param('offset', 0, new Range(0, 2000), 'Results offset. The default value is 0. Use this param to manage pagination.', true)
->param('after', '', new UID(), 'ID of the project used to return projects listed after. Should be used for efficient pagination working with many projects.', true)
->param('orderType', 'ASC', new WhiteList(['ASC', 'DESC'], true), 'Order result by ASC or DESC order.', true)
->inject('response')
->inject('dbForConsole')
->action(function ($search, $limit, $offset, $orderType, $response, $dbForConsole) {
->action(function ($search, $limit, $offset, $after, $orderType, $response, $dbForConsole) {
/** @var Appwrite\Utopia\Response $response */
/** @var Utopia\Database\Database $dbForConsole */
$queries = ($search) ? [new Query('name', Query::TYPE_SEARCH, [$search])] : [];
$results = $dbForConsole->find('projects', $queries, $limit, $offset, ['_id'], [$orderType]);
if (!empty($after)) {
$afterProject = $dbForConsole->getDocument('projects', $after);
if ($afterProject->isEmpty()) {
throw new Exception('Project for after not found', 400);
}
}
$results = $dbForConsole->find('projects', $queries, $limit, $offset, [], [$orderType], $afterProject ?? null);
$sum = $dbForConsole->count('projects', $queries, APP_LIMIT_COUNT);
$response->dynamic(new Document([