1
0
Fork 0
mirror of synced 2024-06-02 19:04:49 +12:00

feat(database): add after pagination

This commit is contained in:
Torsten Dittmann 2021-08-06 14:35:57 +02:00
parent 99442bdfc3
commit dac093c645

View file

@ -180,17 +180,26 @@ App::get('/v1/database/collections')
->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, 40000), 'Results offset. The default value is 0. Use this param to manage pagination.', true)
->param('after', '', new UID(), 'ID of the collection used to return collection listed after. Should be used for efficient pagination working with many collections.', true)
->param('orderType', 'ASC', new WhiteList(['ASC', 'DESC'], true), 'Order result by ASC or DESC order.', true)
->inject('response')
->inject('dbForExternal')
->action(function ($search, $limit, $offset, $orderType, $response, $dbForExternal) {
->action(function ($search, $limit, $offset, $after, $orderType, $response, $dbForExternal) {
/** @var Appwrite\Utopia\Response $response */
/** @var Utopia\Database\Database $dbForExternal */
$queries = ($search) ? [new Query('name', Query::TYPE_SEARCH, [$search])] : [];
if (!empty($after)) {
$afterCollection = $dbForExternal->getDocument('collections', $after);
if ($afterCollection->isEmpty()) {
throw new Exception('Collection for after not found', 400);
}
}
$response->dynamic(new Document([
'collections' => $dbForExternal->find(Database::COLLECTIONS, $queries, $limit, $offset, ['_id'], [$orderType]),
'collections' => $dbForExternal->find(Database::COLLECTIONS, $queries, $limit, $offset, [], [$orderType], $afterCollection ?? null),
'sum' => $dbForExternal->count(Database::COLLECTIONS, $queries, APP_LIMIT_COUNT),
]), Response::MODEL_COLLECTION_LIST);
});