Removed first and last params

This commit is contained in:
Eldad Fux
2020-06-21 15:12:13 +03:00
parent 0abfa5e5fc
commit a3aeecfd0d
2 changed files with 22 additions and 27 deletions
+3
View File
@@ -32,6 +32,9 @@
- Fixed missing custom scopes param for OAuth2 session create API route
- Fixed wrong JSON validation when creating and updating database documnets
## Breaking Changes
- **Deprecated** `first` and `last` query params for documents list route in the database API
## Security
- Access to Health API now requires authentication with an API Key with access to `health.read` scope allowed
+19 -27
View File
@@ -477,10 +477,8 @@ $utopia->get('/v1/database/collections/:collectionId/documents')
->param('orderType', 'ASC', function () { return new WhiteList(array('DESC', 'ASC')); }, 'Order direction. Possible values are DESC for descending order, or ASC for ascending order.', true)
->param('orderCast', 'string', function () { return new WhiteList(array('int', 'string', 'date', 'time', 'datetime')); }, 'Order field type casting. Possible values are int, string, date, time or datetime. The database will attempt to cast the order field to the value you pass here. The default value is a string.', true)
->param('search', '', function () { return new Text(256); }, 'Search query. Enter any free text search. The database will try to find a match against all document attributes and children.', true)
->param('first', 0, function () { return new Range(0, 1); }, 'Return only the first document. Pass 1 for true or 0 for false. The default value is 0.', true)
->param('last', 0, function () { return new Range(0, 1); }, 'Return only the last document. Pass 1 for true or 0 for false. The default value is 0.', true)
->action(
function ($collectionId, $filters, $offset, $limit, $orderField, $orderType, $orderCast, $search, $first, $last) use ($response, $projectDB, $isDev) {
function ($collectionId, $filters, $offset, $limit, $orderField, $orderType, $orderCast, $search) use ($response, $projectDB, $isDev) {
$collection = $projectDB->getDocument($collectionId, $isDev);
if (\is_null($collection->getId()) || Database::SYSTEM_COLLECTION_COLLECTIONS != $collection->getCollection()) {
@@ -494,38 +492,32 @@ $utopia->get('/v1/database/collections/:collectionId/documents')
'orderType' => $orderType,
'orderCast' => $orderCast,
'search' => $search,
'first' => (bool) $first,
'last' => (bool) $last,
'filters' => \array_merge($filters, [
'$collection='.$collectionId,
]),
]);
if ($first || $last) {
$response->json((!empty($list) ? $list->getArrayCopy() : []));
} else {
if ($isDev) {
$collection
->setAttribute('debug', $projectDB->getDebug())
->setAttribute('limit', $limit)
->setAttribute('offset', $offset)
->setAttribute('orderField', $orderField)
->setAttribute('orderType', $orderType)
->setAttribute('orderCast', $orderCast)
->setAttribute('filters', $filters)
;
}
if ($isDev) {
$collection
->setAttribute('sum', $projectDB->getSum())
->setAttribute('documents', $list)
->setAttribute('debug', $projectDB->getDebug())
->setAttribute('limit', $limit)
->setAttribute('offset', $offset)
->setAttribute('orderField', $orderField)
->setAttribute('orderType', $orderType)
->setAttribute('orderCast', $orderCast)
->setAttribute('filters', $filters)
;
/*
* View
*/
$response->json($collection->getArrayCopy(/*['$id', '$collection', 'name', 'documents']*/[], ['rules']));
}
$collection
->setAttribute('sum', $projectDB->getSum())
->setAttribute('documents', $list)
;
/*
* View
*/
$response->json($collection->getArrayCopy(/*['$id', '$collection', 'name', 'documents']*/[], ['rules']));
}
);