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

Updated database controller

This commit is contained in:
Eldad Fux 2020-12-26 17:05:04 +02:00
parent 9775db98b1
commit acc9bd7a91

View file

@ -34,6 +34,9 @@ App::post('/v1/database/collections')
->param('read', [], new ArrayList(new Text(64)), 'An array of strings with read permissions. By default no user is granted with any read permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions.')
->param('write', [], new ArrayList(new Text(64)), 'An array of strings with write permissions. By default no user is granted with any write permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions.')
->param('rules', [], function ($projectDB) { return new ArrayList(new Collection($projectDB, [Database::SYSTEM_COLLECTION_RULES], ['$collection' => Database::SYSTEM_COLLECTION_RULES, '$permissions' => ['read' => [], 'write' => []]])); }, 'Array of [rule objects](/docs/rules). Each rule define a collection field name, data type and validation.', false, ['projectDB'])
->inject('response')
->inject('projectDB')
->inject('audits')
->action(function ($name, $read, $write, $rules, $response, $projectDB, $audits) {
/** @var Appwrite\Utopia\Response $response */
/** @var Appwrite\Database\Database $projectDB */
@ -86,7 +89,7 @@ App::post('/v1/database/collections')
->setStatusCode(Response::STATUS_CODE_CREATED)
->dynamic($data, Response::MODEL_COLLECTION)
;
}, ['response', 'projectDB', 'audits']);
});
App::get('/v1/database/collections')
->desc('List Collections')
@ -103,6 +106,8 @@ App::get('/v1/database/collections')
->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('orderType', 'ASC', new WhiteList(['ASC', 'DESC'], true), 'Order result by ASC or DESC order.', true)
->inject('response')
->inject('projectDB')
->action(function ($search, $limit, $offset, $orderType, $response, $projectDB) {
/** @var Appwrite\Utopia\Response $response */
/** @var Appwrite\Database\Database $projectDB */
@ -120,7 +125,7 @@ App::get('/v1/database/collections')
'sum' => $projectDB->getSum(),
'collections' => $results
]), Response::MODEL_COLLECTION_LIST);
}, ['response', 'projectDB']);
});
App::get('/v1/database/collections/:collectionId')
->desc('Get Collection')
@ -134,6 +139,8 @@ App::get('/v1/database/collections/:collectionId')
->label('sdk.response.type', Response::CONTENT_TYPE_JSON)
->label('sdk.response.model', Response::MODEL_COLLECTION)
->param('collectionId', '', new UID(), 'Collection unique ID.')
->inject('response')
->inject('projectDB')
->action(function ($collectionId, $response, $projectDB) {
/** @var Appwrite\Utopia\Response $response */
/** @var Appwrite\Database\Database $projectDB */
@ -145,7 +152,7 @@ App::get('/v1/database/collections/:collectionId')
}
$response->dynamic($collection, Response::MODEL_COLLECTION);
}, ['response', 'projectDB']);
});
App::put('/v1/database/collections/:collectionId')
->desc('Update Collection')
@ -164,6 +171,9 @@ App::put('/v1/database/collections/:collectionId')
->param('read', [], new ArrayList(new Text(64)), 'An array of strings with read permissions. By default no user is granted with any read permissions. [learn more about permissions(/docs/permissions) and get a full list of available permissions.')
->param('write', [], new ArrayList(new Text(64)), 'An array of strings with write permissions. By default no user is granted with any write permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions.')
->param('rules', [], function ($projectDB) { return new ArrayList(new Collection($projectDB, [Database::SYSTEM_COLLECTION_RULES], ['$collection' => Database::SYSTEM_COLLECTION_RULES, '$permissions' => ['read' => [], 'write' => []]])); }, 'Array of [rule objects](/docs/rules). Each rule define a collection field name, data type and validation.', true, ['projectDB'])
->inject('response')
->inject('projectDB')
->inject('audits')
->action(function ($collectionId, $name, $read, $write, $rules, $response, $projectDB, $audits) {
/** @var Appwrite\Utopia\Response $response */
/** @var Appwrite\Database\Database $projectDB */
@ -217,7 +227,7 @@ App::put('/v1/database/collections/:collectionId')
;
$response->dynamic($collection, Response::MODEL_COLLECTION);
}, ['response', 'projectDB', 'audits']);
});
App::delete('/v1/database/collections/:collectionId')
->desc('Delete Collection')
@ -232,6 +242,11 @@ App::delete('/v1/database/collections/:collectionId')
->label('sdk.response.type', Response::CONTENT_TYPE_JSON)
->label('sdk.response.model', Response::MODEL_NONE)
->param('collectionId', '', new UID(), 'Collection unique ID.')
->inject('response')
->inject('projectDB')
->inject('events')
->inject('audits')
->inject('deletes')
->action(function ($collectionId, $response, $projectDB, $events, $audits, $deletes) {
/** @var Appwrite\Utopia\Response $response */
/** @var Appwrite\Database\Database $projectDB */
@ -263,7 +278,7 @@ App::delete('/v1/database/collections/:collectionId')
;
$response->noContent();
}, ['response', 'projectDB', 'events', 'audits', 'deletes']);
});
App::post('/v1/database/collections/:collectionId/documents')
->desc('Create Document')
@ -284,6 +299,9 @@ App::post('/v1/database/collections/:collectionId/documents')
->param('parentDocument', '', new UID(), 'Parent document unique ID. Use when you want your new document to be a child of a parent document.', true)
->param('parentProperty', '', new Key(), 'Parent document property name. Use when you want your new document to be a child of a parent document.', true)
->param('parentPropertyType', Document::SET_TYPE_ASSIGN, new WhiteList([Document::SET_TYPE_ASSIGN, Document::SET_TYPE_APPEND, Document::SET_TYPE_PREPEND], true), 'Parent document property connection type. You can set this value to **assign**, **append** or **prepend**, default value is assign. Use when you want your new document to be a child of a parent document.', true)
->inject('response')
->inject('projectDB')
->inject('audits')
->action(function ($collectionId, $data, $read, $write, $parentDocument, $parentProperty, $parentPropertyType, $response, $projectDB, $audits) {
/** @var Appwrite\Utopia\Response $response */
/** @var Appwrite\Database\Database $projectDB */
@ -380,7 +398,7 @@ App::post('/v1/database/collections/:collectionId/documents')
->setStatusCode(Response::STATUS_CODE_CREATED)
->dynamic($data, Response::MODEL_ANY)
;
}, ['response', 'projectDB', 'audits']);
});
App::get('/v1/database/collections/:collectionId/documents')
->desc('List Documents')
@ -401,6 +419,8 @@ App::get('/v1/database/collections/:collectionId/documents')
->param('orderType', 'ASC', new WhiteList(['DESC', 'ASC'], true), 'Order direction. Possible values are DESC for descending order, or ASC for ascending order.', true)
->param('orderCast', 'string', new WhiteList(['int', 'string', 'date', 'time', 'datetime'], true), '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', '', new Text(256), 'Search query. Enter any free text search. The database will try to find a match against all document attributes and children. Max length: 256 chars.', true)
->inject('response')
->inject('projectDB')
->action(function ($collectionId, $filters, $limit, $offset, $orderField, $orderType, $orderCast, $search, $response, $projectDB) {
/** @var Appwrite\Utopia\Response $response */
/** @var Appwrite\Database\Database $projectDB */
@ -441,7 +461,7 @@ App::get('/v1/database/collections/:collectionId/documents')
;
$response->dynamic($collection, Response::MODEL_DOCUMENT_LIST);
}, ['response', 'projectDB']);
});
App::get('/v1/database/collections/:collectionId/documents/:documentId')
->desc('Get Document')
@ -456,8 +476,9 @@ App::get('/v1/database/collections/:collectionId/documents/:documentId')
->label('sdk.response.model', Response::MODEL_ANY)
->param('collectionId', null, new UID(), 'Collection unique ID. You can create a new collection with validation rules using the Database service [server integration](/docs/server/database#createCollection).')
->param('documentId', null, new UID(), 'Document unique ID.')
->action(function ($collectionId, $documentId, $request, $response, $projectDB) {
/** @var Utopia\Swoole\Request $request */
->inject('response')
->inject('projectDB')
->action(function ($collectionId, $documentId, $response, $projectDB) {
/** @var Appwrite\Utopia\Response $response */
/** @var Appwrite\Database\Database $projectDB */
@ -469,7 +490,7 @@ App::get('/v1/database/collections/:collectionId/documents/:documentId')
}
$response->dynamic($document, Response::MODEL_ANY);
}, ['request', 'response', 'projectDB']);
});
App::patch('/v1/database/collections/:collectionId/documents/:documentId')
->desc('Update Document')
@ -488,6 +509,9 @@ App::patch('/v1/database/collections/:collectionId/documents/:documentId')
->param('data', [], new JSON(), 'Document data as JSON object.')
->param('read', [], new ArrayList(new Text(64)), 'An array of strings with read permissions. By default no user is granted with any read permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions.')
->param('write', [], new ArrayList(new Text(64)), 'An array of strings with write permissions. By default no user is granted with any write permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions.')
->inject('response')
->inject('projectDB')
->inject('audits')
->action(function ($collectionId, $documentId, $data, $read, $write, $response, $projectDB, $audits) {
/** @var Appwrite\Utopia\Response $response */
/** @var Appwrite\Database\Database $projectDB */
@ -546,7 +570,7 @@ App::patch('/v1/database/collections/:collectionId/documents/:documentId')
;
$response->dynamic($data, Response::MODEL_ANY);
}, ['response', 'projectDB', 'audits']);
});
App::delete('/v1/database/collections/:collectionId/documents/:documentId')
->desc('Delete Document')
@ -562,6 +586,10 @@ App::delete('/v1/database/collections/:collectionId/documents/:documentId')
->label('sdk.response.model', Response::MODEL_NONE)
->param('collectionId', null, new UID(), 'Collection unique ID. You can create a new collection with validation rules using the Database service [server integration](/docs/server/database#createCollection).')
->param('documentId', null, new UID(), 'Document unique ID.')
->inject('response')
->inject('projectDB')
->inject('events')
->inject('audits')
->action(function ($collectionId, $documentId, $response, $projectDB, $events, $audits) {
/** @var Appwrite\Utopia\Response $response */
/** @var Appwrite\Database\Database $projectDB */
@ -600,4 +628,4 @@ App::delete('/v1/database/collections/:collectionId/documents/:documentId')
;
$response->noContent();
}, ['response', 'projectDB', 'events', 'audits']);
});