Consolidate List Users API params

Replace search, limit, offset, cursor, cursorDirection, and orderType
params with a single queries param since the Queries V2 change now
allows for different types of queries.
This commit is contained in:
Steven
2022-08-18 19:30:39 +00:00
parent 753aebccab
commit f0d66985f7
5 changed files with 263 additions and 39 deletions
@@ -0,0 +1,58 @@
<?php
namespace Appwrite\Utopia\Database\Validator\Queries;
use Utopia\Config\Config;
use Utopia\Database\Database;
use Utopia\Database\Document;
use Utopia\Database\Validator\Queries as QueriesValidator;
use Utopia\Database\Validator\Query as QueryValidator;
class Collection extends QueriesValidator
{
/**
* Expression constructor
*
* @param string $collection
* @param string[] $allowedAttributes
*/
public function __construct(string $collection, array $allowedAttributes)
{
$collection = Config::getParam('collections', [])[$collection];
// array for constant lookup time
$allowedAttributesLookup = [];
foreach ($allowedAttributes as $attribute) {
$allowedAttributesLookup[$attribute] = true;
}
$attributes = [];
foreach ($collection['attributes'] as $attribute) {
$key = $attribute['$id'];
if (!isset($allowedAttributesLookup[$key])) {
continue;
}
$attributes[] = new Document([
'key' => $key,
'type' => $attribute['type'],
'array' => $attribute['array'],
]);
}
$indexes = [];
foreach ($allowedAttributes as $attribute) {
$indexes[] = new Document([
'status' => 'available',
'type' => Database::INDEX_KEY,
'attributes' => [$attribute]
]);
}
$indexes[] = new Document([
'status' => 'available',
'type' => Database::INDEX_FULLTEXT,
'attributes' => ['search']
]);
parent::__construct(new QueryValidator($attributes), $attributes, $indexes, true);
}
}
@@ -0,0 +1,28 @@
<?php
namespace Appwrite\Utopia\Database\Validator\Queries;
use Appwrite\Utopia\Database\Validator\Queries\Collection;
class Users extends Collection
{
public const ALLOWED_ATTRIBUTES = [
'name',
'email',
'phone',
'status',
'passwordUpdate',
'registration',
'emailVerification',
'phoneVerification',
];
/**
* Expression constructor
*
*/
public function __construct()
{
parent::__construct('users', self::ALLOWED_ATTRIBUTES);
}
}