mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
added length param, response model, e2e test
This commit is contained in:
@@ -2812,12 +2812,13 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/indexes')
|
||||
->param('key', null, new Key(), 'Index Key.')
|
||||
->param('type', null, new WhiteList([Database::INDEX_KEY, Database::INDEX_FULLTEXT, Database::INDEX_UNIQUE]), 'Index type.')
|
||||
->param('attributes', null, new ArrayList(new Key(true), APP_LIMIT_ARRAY_PARAMS_SIZE), 'Array of attributes to index. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' attributes are allowed, each 32 characters long.')
|
||||
->param('lengths', [], new ArrayList(new Integer(), APP_LIMIT_ARRAY_PARAMS_SIZE), 'Length of index. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE, optional:true)
|
||||
->param('orders', [], new ArrayList(new WhiteList(['ASC', 'DESC'], false, Database::VAR_STRING), APP_LIMIT_ARRAY_PARAMS_SIZE), 'Array of index orders. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' orders are allowed.', true)
|
||||
->inject('response')
|
||||
->inject('dbForProject')
|
||||
->inject('queueForDatabase')
|
||||
->inject('queueForEvents')
|
||||
->action(function (string $databaseId, string $collectionId, string $key, string $type, array $attributes, array $orders, Response $response, Database $dbForProject, EventDatabase $queueForDatabase, Event $queueForEvents) {
|
||||
->action(function (string $databaseId, string $collectionId, string $key, string $type, array $attributes, array $lengths, array $orders, Response $response, Database $dbForProject, EventDatabase $queueForDatabase, Event $queueForEvents) {
|
||||
|
||||
$db = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId));
|
||||
|
||||
@@ -2877,9 +2878,6 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/indexes')
|
||||
'size' => 0
|
||||
];
|
||||
|
||||
// lengths hidden by default
|
||||
$lengths = [];
|
||||
|
||||
foreach ($attributes as $i => $attribute) {
|
||||
// find attribute metadata in collection document
|
||||
$attributeIndex = \array_search($attribute, array_column($oldAttributes, 'key'));
|
||||
@@ -2901,10 +2899,11 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/indexes')
|
||||
throw new Exception(Exception::ATTRIBUTE_NOT_AVAILABLE, 'Attribute not available: ' . $oldAttributes[$attributeIndex]['key']);
|
||||
}
|
||||
|
||||
$lengths[$i] = null;
|
||||
|
||||
$lengths[$i] = array_key_exists($i, $lengths) ? $lengths[$i] : null;
|
||||
if ($attributeArray === true) {
|
||||
$lengths[$i] = Database::ARRAY_INDEX_LENGTH;
|
||||
if ($lengths[$i] === null) {
|
||||
$lengths[$i] = Database::ARRAY_INDEX_LENGTH;
|
||||
}
|
||||
$orders[$i] = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,6 +41,13 @@ class Index extends Model
|
||||
'example' => [],
|
||||
'array' => true,
|
||||
])
|
||||
->addRule('lengths', [
|
||||
'type' => self::TYPE_INTEGER,
|
||||
'description' => 'Index attributes length.',
|
||||
'default' => [],
|
||||
'example' => [],
|
||||
'array' => true,
|
||||
])
|
||||
->addRule('orders', [
|
||||
'type' => self::TYPE_STRING,
|
||||
'description' => 'Index orders.',
|
||||
|
||||
@@ -1422,9 +1422,40 @@ trait DatabasesBase
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @depends testCreateIndexes
|
||||
* @depends testCreateAttributes
|
||||
*/
|
||||
public function testGetIndexByKeyWithLengths(array $data): void
|
||||
{
|
||||
$databaseId = $data['databaseId'];
|
||||
$collectionId = $data['moviesId'];
|
||||
|
||||
$create = $this->client->call(Client::METHOD_POST, "/databases/{$databaseId}/collections/{$collectionId}/indexes", [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||
], [
|
||||
'key' => 'lengthTestIndex',
|
||||
'type' => 'key',
|
||||
'attributes' => ['title','description'],
|
||||
'lengths' => [128,200]
|
||||
]);
|
||||
|
||||
$this->assertEquals(202, $create['headers']['status-code']);
|
||||
|
||||
$index = $this->client->call(Client::METHOD_GET, "/databases/{$databaseId}/collections/{$collectionId}/indexes/lengthTestIndex", [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||
]);
|
||||
$this->assertEquals(200, $index['headers']['status-code']);
|
||||
$this->assertEquals('lengthTestIndex', $index['body']['key']);
|
||||
$this->assertEquals([128,200], $index['body']['lengths']);
|
||||
}
|
||||
/**
|
||||
* @depends testCreateIndexes
|
||||
*/
|
||||
public function testListIndexes(array $data): void
|
||||
{
|
||||
$databaseId = $data['databaseId'];
|
||||
|
||||
Reference in New Issue
Block a user