diff --git a/src/Appwrite/Utopia/Response.php b/src/Appwrite/Utopia/Response.php index 67d47eea44..a653ddbb0f 100644 --- a/src/Appwrite/Utopia/Response.php +++ b/src/Appwrite/Utopia/Response.php @@ -11,6 +11,7 @@ use Appwrite\Utopia\Response\Model; use Appwrite\Utopia\Response\Model\None; use Appwrite\Utopia\Response\Model\Any; use Appwrite\Utopia\Response\Model\Attribute; +use Appwrite\Utopia\Response\Model\AttributeList; use Appwrite\Utopia\Response\Model\AttributeString; use Appwrite\Utopia\Response\Model\AttributeInteger; use Appwrite\Utopia\Response\Model\AttributeFloat; @@ -170,7 +171,6 @@ class Response extends SwooleResponse ->setModel(new ErrorDev()) // Lists ->setModel(new BaseList('Collections List', self::MODEL_COLLECTION_LIST, 'collections', self::MODEL_COLLECTION)) - ->setModel(new BaseList('Attributes List', self::MODEL_ATTRIBUTE_LIST, 'attributes', self::MODEL_ATTRIBUTE)) ->setModel(new BaseList('Indexes List', self::MODEL_INDEX_LIST, 'indexes', self::MODEL_INDEX)) ->setModel(new BaseList('Documents List', self::MODEL_DOCUMENT_LIST, 'documents', self::MODEL_DOCUMENT)) ->setModel(new BaseList('Users List', self::MODEL_USER_LIST, 'users', self::MODEL_USER)) @@ -195,6 +195,7 @@ class Response extends SwooleResponse // Entities ->setModel(new Collection()) ->setModel(new Attribute()) + ->setModel(new AttributeList()) ->setModel(new AttributeString()) ->setModel(new AttributeInteger()) ->setModel(new AttributeFloat()) diff --git a/src/Appwrite/Utopia/Response/Model/AttributeList.php b/src/Appwrite/Utopia/Response/Model/AttributeList.php new file mode 100644 index 0000000000..5484db61f1 --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/AttributeList.php @@ -0,0 +1,62 @@ +addRule('sum', [ + 'type' => self::TYPE_INTEGER, + 'description' => 'Total sum of items in the list.', + 'default' => 0, + 'example' => 5, + ]) + ->addRule('attributes', [ + 'type' => Response::MODEL_ATTRIBUTE, + 'description' => 'List of attributes.', + 'default' => [], + 'array' => true, + 'getNestedType' => function(Document $attribute) { + return match($attribute->getAttribute('type')) { + self::TYPE_BOOLEAN => Response::MODEL_ATTRIBUTE_BOOLEAN, + self::TYPE_INTEGER=> Response::MODEL_ATTRIBUTE_INTEGER, + self::TYPE_FLOAT => Response::MODEL_ATTRIBUTE_FLOAT, + self::TYPE_STRING => match($attribute->getAttribute('format')) { + APP_DATABASE_ATTRIBUTE_EMAIL => Response::MODEL_ATTRIBUTE_EMAIL, + APP_DATABASE_ATTRIBUTE_IP => Response::MODEL_ATTRIBUTE_IP, + APP_DATABASE_ATTRIBUTE_URL => Response::MODEL_ATTRIBUTE_URL, + default => Response::MODEL_ATTRIBUTE_STRING, + }, + default => Response::MODEL_ATTRIBUTE, + }; + }, + ]) + ; + } + + /** + * Get Name + * + * @return string + */ + public function getName():string + { + return 'Attributes List'; + } + + /** + * Get Collection + * + * @return string + */ + public function getType():string + { + return Response::MODEL_ATTRIBUTE_LIST; + } +} \ No newline at end of file