diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Attributes/Action.php b/src/Appwrite/Platform/Modules/Databases/Http/Attributes/Action.php index 3cad730b6d..0ac013fc4f 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Attributes/Action.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Attributes/Action.php @@ -30,9 +30,9 @@ abstract class Action extends UtopiaAction private ?string $context = DATABASE_ATTRIBUTES_CONTEXT; /** - * @var string|array|null The current response model for the attribute/column type. + * Get the correct response model. */ - private string|array|null $responseModel = null; + abstract protected function getResponseModel(): string|array; /** * Set the context to either `column` or `attribute`. @@ -92,26 +92,6 @@ abstract class Action extends UtopiaAction return $this->getContext() . 'Id'; } - /** - * Set the correct response model. - */ - final protected function setResponseModel(string|array $model): void - { - $this->responseModel = $model; - } - - /** - * Get the correct response model. - */ - final protected function getResponseModel(): string|array - { - if ($this->responseModel === null) { - throw new \LogicException("Missing response model: you must call setResponseModel() before using it."); - } - - return $this->responseModel; - } - /** * Get the appropriate parent level not found exception. */ diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Attributes/Boolean/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Attributes/Boolean/Create.php index 57cff8a75f..8fdbbefbcd 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Attributes/Boolean/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Attributes/Boolean/Create.php @@ -26,10 +26,13 @@ class Create extends Action return 'createBooleanColumn'; } + protected function getResponseModel(): string|array + { + return UtopiaResponse::MODEL_ATTRIBUTE_BOOLEAN; + } + public function __construct() { - $this->setResponseModel(UtopiaResponse::MODEL_ATTRIBUTE_BOOLEAN); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_POST) ->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/boolean') @@ -66,19 +69,8 @@ class Create extends Action ->callback([$this, 'action']); } - public function action( - string $databaseId, - string $collectionId, - string $key, - ?bool $required, - ?bool $default, - bool $array, - UtopiaResponse $response, - Database $dbForProject, - EventDatabase $queueForDatabase, - Event $queueForEvents - ): void { - + public function action(string $databaseId, string $collectionId, string $key, ?bool $required, ?bool $default, bool $array, UtopiaResponse $response, Database $dbForProject, EventDatabase $queueForDatabase, Event $queueForEvents): void + { $attribute = $this->createAttribute($databaseId, $collectionId, new Document([ 'key' => $key, 'type' => Database::VAR_BOOLEAN, diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Attributes/Boolean/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Attributes/Boolean/Update.php index 7a2db8e74f..b2fdc527b3 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Attributes/Boolean/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Attributes/Boolean/Update.php @@ -26,10 +26,13 @@ class Update extends Action return 'updateBooleanColumn'; } + protected function getResponseModel(): string|array + { + return UtopiaResponse::MODEL_ATTRIBUTE_BOOLEAN; + } + public function __construct() { - $this->setResponseModel(UtopiaResponse::MODEL_ATTRIBUTE_BOOLEAN); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) ->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/boolean/:key') @@ -66,17 +69,8 @@ class Update extends Action ->callback([$this, 'action']); } - public function action( - string $databaseId, - string $collectionId, - string $key, - ?bool $required, - ?bool $default, - ?string $newKey, - UtopiaResponse $response, - Database $dbForProject, - Event $queueForEvents - ): void { + public function action(string $databaseId, string $collectionId, string $key, ?bool $required, ?bool $default, ?string $newKey, UtopiaResponse $response, Database $dbForProject, Event $queueForEvents): void + { $attribute = $this->updateAttribute( databaseId: $databaseId, collectionId: $collectionId, diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Attributes/Datetime/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Attributes/Datetime/Create.php index 40d7aed1e9..07f7158475 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Attributes/Datetime/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Attributes/Datetime/Create.php @@ -27,10 +27,13 @@ class Create extends Action return 'createDatetimeAttribute'; } + protected function getResponseModel(): string|array + { + return UtopiaResponse::MODEL_ATTRIBUTE_DATETIME; + } + public function __construct() { - $this->setResponseModel(UtopiaResponse::MODEL_ATTRIBUTE_DATETIME); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_POST) ->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/datetime') @@ -67,18 +70,8 @@ class Create extends Action ->callback([$this, 'action']); } - public function action( - string $databaseId, - string $collectionId, - string $key, - ?bool $required, - ?string $default, - bool $array, - UtopiaResponse $response, - Database $dbForProject, - EventDatabase $queueForDatabase, - Event $queueForEvents - ): void { + public function action(string $databaseId, string $collectionId, string $key, ?bool $required, ?string $default, bool $array, UtopiaResponse $response, Database $dbForProject, EventDatabase $queueForDatabase, Event $queueForEvents): void + { $attribute = $this->createAttribute( $databaseId, $collectionId, diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Attributes/Datetime/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Attributes/Datetime/Update.php index 386d6682ad..0709415d81 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Attributes/Datetime/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Attributes/Datetime/Update.php @@ -27,10 +27,13 @@ class Update extends Action return 'updateDatetimeAttribute'; } + protected function getResponseModel(): string|array + { + return UtopiaResponse::MODEL_ATTRIBUTE_DATETIME; + } + public function __construct() { - $this->setResponseModel(UtopiaResponse::MODEL_ATTRIBUTE_DATETIME); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) ->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/datetime/:key') @@ -67,17 +70,8 @@ class Update extends Action ->callback([$this, 'action']); } - public function action( - string $databaseId, - string $collectionId, - string $key, - ?bool $required, - ?string $default, - ?string $newKey, - UtopiaResponse $response, - Database $dbForProject, - Event $queueForEvents - ): void { + public function action(string $databaseId, string $collectionId, string $key, ?bool $required, ?string $default, ?string $newKey, UtopiaResponse $response, Database $dbForProject, Event $queueForEvents): void + { $attribute = $this->updateAttribute( databaseId: $databaseId, collectionId: $collectionId, diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Attributes/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/Attributes/Delete.php index da29fd09ee..bcb4d1d406 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Attributes/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Attributes/Delete.php @@ -27,11 +27,14 @@ class Delete extends Action return 'deleteAttribute'; } - public function __construct() + protected function getResponseModel(): string|array { // we should correctly & carefully set the context later. - $this->setResponseModel(UtopiaResponse::MODEL_NONE); + return UtopiaResponse::MODEL_NONE; + } + public function __construct() + { $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_DELETE) ->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/:key') @@ -44,8 +47,8 @@ class Delete extends Action ->label('audits.resource', 'database/{request.databaseId}/collection/{request.collectionId}') ->label('sdk', new Method( namespace: 'databases', - group: 'attributes', - name: 'deleteAttribute', + group: $this->getSdkGroup(), + name: self::getName(), description: '/docs/references/databases/delete-attribute.md', auth: [AuthType::KEY], responses: [ @@ -66,15 +69,8 @@ class Delete extends Action ->callback([$this, 'action']); } - public function action( - string $databaseId, - string $collectionId, - string $key, - UtopiaResponse $response, - Database $dbForProject, - EventDatabase $queueForDatabase, - Event $queueForEvents - ): void { + public function action(string $databaseId, string $collectionId, string $key, UtopiaResponse $response, Database $dbForProject, EventDatabase $queueForDatabase, Event $queueForEvents): void + { $db = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId)); if ($db->isEmpty()) { throw new Exception(Exception::DATABASE_NOT_FOUND); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Attributes/Email/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Attributes/Email/Create.php index c33ce9daeb..bd8512a271 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Attributes/Email/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Attributes/Email/Create.php @@ -27,10 +27,13 @@ class Create extends Action return 'createEmailAttribute'; } + protected function getResponseModel(): string|array + { + return UtopiaResponse::MODEL_ATTRIBUTE_EMAIL; + } + public function __construct() { - $this->setResponseModel(UtopiaResponse::MODEL_ATTRIBUTE_EMAIL); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_POST) ->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/email') @@ -67,18 +70,8 @@ class Create extends Action ->callback([$this, 'action']); } - public function action( - string $databaseId, - string $collectionId, - string $key, - ?bool $required, - ?string $default, - bool $array, - UtopiaResponse $response, - Database $dbForProject, - EventDatabase $queueForDatabase, - Event $queueForEvents - ): void { + public function action(string $databaseId, string $collectionId, string $key, ?bool $required, ?string $default, bool $array, UtopiaResponse $response, Database $dbForProject, EventDatabase $queueForDatabase, Event $queueForEvents): void + { $attribute = $this->createAttribute( $databaseId, $collectionId, diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Attributes/Email/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Attributes/Email/Update.php index 0c41961099..2c39e37b19 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Attributes/Email/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Attributes/Email/Update.php @@ -27,10 +27,13 @@ class Update extends Action return 'updateEmailAttribute'; } + protected function getResponseModel(): string|array + { + return UtopiaResponse::MODEL_ATTRIBUTE_EMAIL; + } + public function __construct() { - $this->setResponseModel(UtopiaResponse::MODEL_ATTRIBUTE_EMAIL); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) ->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/email/:key') @@ -67,17 +70,8 @@ class Update extends Action ->callback([$this, 'action']); } - public function action( - string $databaseId, - string $collectionId, - string $key, - ?bool $required, - ?string $default, - ?string $newKey, - UtopiaResponse $response, - Database $dbForProject, - Event $queueForEvents - ): void { + public function action(string $databaseId, string $collectionId, string $key, ?bool $required, ?string $default, ?string $newKey, UtopiaResponse $response, Database $dbForProject, Event $queueForEvents): void + { $attribute = $this->updateAttribute( databaseId: $databaseId, collectionId: $collectionId, diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Attributes/Enum/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Attributes/Enum/Create.php index 61298cbe94..fa30639bd1 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Attributes/Enum/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Attributes/Enum/Create.php @@ -29,10 +29,13 @@ class Create extends Action return 'createEnumAttribute'; } + protected function getResponseModel(): string|array + { + return UtopiaResponse::MODEL_ATTRIBUTE_ENUM; + } + public function __construct() { - $this->setResponseModel(UtopiaResponse::MODEL_ATTRIBUTE_ENUM); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_POST) ->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/enum') @@ -70,19 +73,8 @@ class Create extends Action ->callback([$this, 'action']); } - public function action( - string $databaseId, - string $collectionId, - string $key, - array $elements, - ?bool $required, - ?string $default, - bool $array, - UtopiaResponse $response, - Database $dbForProject, - EventDatabase $queueForDatabase, - Event $queueForEvents - ): void { + public function action(string $databaseId, string $collectionId, string $key, array $elements, ?bool $required, ?string $default, bool $array, UtopiaResponse $response, Database $dbForProject, EventDatabase $queueForDatabase, Event $queueForEvents): void + { if (!is_null($default) && !\in_array($default, $elements, true)) { throw new Exception($this->getInvalidValueException(), 'Default value not found in elements'); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Attributes/Enum/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Attributes/Enum/Update.php index 37d8065608..089407ad01 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Attributes/Enum/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Attributes/Enum/Update.php @@ -28,10 +28,13 @@ class Update extends Action return 'updateEnumAttribute'; } + protected function getResponseModel(): string|array + { + return UtopiaResponse::MODEL_ATTRIBUTE_ENUM; + } + public function __construct() { - $this->setResponseModel(UtopiaResponse::MODEL_ATTRIBUTE_ENUM); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) ->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/enum/:key') @@ -69,18 +72,8 @@ class Update extends Action ->callback([$this, 'action']); } - public function action( - string $databaseId, - string $collectionId, - string $key, - ?array $elements, - ?bool $required, - ?string $default, - ?string $newKey, - UtopiaResponse $response, - Database $dbForProject, - Event $queueForEvents - ): void { + public function action(string $databaseId, string $collectionId, string $key, ?array $elements, ?bool $required, ?string $default, ?string $newKey, UtopiaResponse $response, Database $dbForProject, Event $queueForEvents): void + { $attribute = $this->updateAttribute( databaseId: $databaseId, collectionId: $collectionId, diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Attributes/Float/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Attributes/Float/Create.php index 9603cf4c9a..e1f22ffdd8 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Attributes/Float/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Attributes/Float/Create.php @@ -29,10 +29,13 @@ class Create extends Action return 'createFloatAttribute'; } + protected function getResponseModel(): string|array + { + return UtopiaResponse::MODEL_ATTRIBUTE_FLOAT; + } + public function __construct() { - $this->setResponseModel(UtopiaResponse::MODEL_ATTRIBUTE_FLOAT); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_POST) ->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/float') @@ -71,20 +74,8 @@ class Create extends Action ->callback([$this, 'action']); } - public function action( - string $databaseId, - string $collectionId, - string $key, - ?bool $required, - ?float $min, - ?float $max, - ?float $default, - bool $array, - UtopiaResponse $response, - Database $dbForProject, - EventDatabase $queueForDatabase, - Event $queueForEvents - ): void { + public function action(string $databaseId, string $collectionId, string $key, ?bool $required, ?float $min, ?float $max, ?float $default, bool $array, UtopiaResponse $response, Database $dbForProject, EventDatabase $queueForDatabase, Event $queueForEvents): void + { $min ??= -PHP_FLOAT_MAX; $max ??= PHP_FLOAT_MAX; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Attributes/Float/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Attributes/Float/Update.php index 012e8239c9..42cc5444d5 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Attributes/Float/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Attributes/Float/Update.php @@ -27,10 +27,13 @@ class Update extends Action return 'updateFloatAttribute'; } + protected function getResponseModel(): string|array + { + return UtopiaResponse::MODEL_ATTRIBUTE_FLOAT; + } + public function __construct() { - $this->setResponseModel(UtopiaResponse::MODEL_ATTRIBUTE_FLOAT); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) ->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/float/:key') @@ -69,19 +72,8 @@ class Update extends Action ->callback([$this, 'action']); } - public function action( - string $databaseId, - string $collectionId, - string $key, - ?bool $required, - ?float $min, - ?float $max, - ?float $default, - ?string $newKey, - UtopiaResponse $response, - Database $dbForProject, - Event $queueForEvents - ): void { + public function action(string $databaseId, string $collectionId, string $key, ?bool $required, ?float $min, ?float $max, ?float $default, ?string $newKey, UtopiaResponse $response, Database $dbForProject, Event $queueForEvents): void + { $attribute = $this->updateAttribute( databaseId: $databaseId, collectionId: $collectionId, diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Attributes/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Attributes/Get.php index e782897be2..95612b45ca 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Attributes/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Attributes/Get.php @@ -23,9 +23,9 @@ class Get extends Action return 'getColumn'; } - public function __construct() + protected function getResponseModel(): string|array { - $this->setResponseModel([ + return [ UtopiaResponse::MODEL_ATTRIBUTE_BOOLEAN, UtopiaResponse::MODEL_ATTRIBUTE_INTEGER, UtopiaResponse::MODEL_ATTRIBUTE_FLOAT, @@ -36,8 +36,11 @@ class Get extends Action UtopiaResponse::MODEL_ATTRIBUTE_DATETIME, UtopiaResponse::MODEL_ATTRIBUTE_RELATIONSHIP, UtopiaResponse::MODEL_ATTRIBUTE_STRING, - ]); + ]; + } + public function __construct() + { $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_GET) ->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/:key') @@ -47,8 +50,8 @@ class Get extends Action ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( namespace: 'databases', - group: 'columns', - name: 'getColumn', + group: $this->getSdkGroup(), + name: self::getName(), description: '/docs/references/databases/get-attribute.md', auth: [AuthType::KEY], responses: [ @@ -66,13 +69,8 @@ class Get extends Action ->callback([$this, 'action']); } - public function action( - string $databaseId, - string $tableId, - string $key, - UtopiaResponse $response, - Database $dbForProject - ): void { + public function action(string $databaseId, string $tableId, string $key, UtopiaResponse $response, Database $dbForProject): void + { $database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId)); if ($database->isEmpty()) { throw new Exception(Exception::DATABASE_NOT_FOUND); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Attributes/IP/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Attributes/IP/Create.php index 8176b03bba..927d55c9c0 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Attributes/IP/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Attributes/IP/Create.php @@ -27,10 +27,13 @@ class Create extends Action return 'createIpAttribute'; } + protected function getResponseModel(): string|array + { + return UtopiaResponse::MODEL_ATTRIBUTE_IP; + } + public function __construct() { - $this->setResponseModel(UtopiaResponse::MODEL_ATTRIBUTE_IP); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_POST) ->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/ip') @@ -67,18 +70,8 @@ class Create extends Action ->callback([$this, 'action']); } - public function action( - string $databaseId, - string $collectionId, - string $key, - ?bool $required, - ?string $default, - bool $array, - UtopiaResponse $response, - Database $dbForProject, - EventDatabase $queueForDatabase, - Event $queueForEvents - ): void { + public function action(string $databaseId, string $collectionId, string $key, ?bool $required, ?string $default, bool $array, UtopiaResponse $response, Database $dbForProject, EventDatabase $queueForDatabase, Event $queueForEvents): void + { $attribute = $this->createAttribute( $databaseId, $collectionId, diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Attributes/IP/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Attributes/IP/Update.php index 868b735bbb..a489675bd2 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Attributes/IP/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Attributes/IP/Update.php @@ -27,10 +27,13 @@ class Update extends Action return 'updateIpAttribute'; } + protected function getResponseModel(): string|array + { + return UtopiaResponse::MODEL_ATTRIBUTE_IP; + } + public function __construct() { - $this->setResponseModel(UtopiaResponse::MODEL_ATTRIBUTE_IP); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) ->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/ip/:key') @@ -67,17 +70,8 @@ class Update extends Action ->callback([$this, 'action']); } - public function action( - string $databaseId, - string $collectionId, - string $key, - ?bool $required, - ?string $default, - ?string $newKey, - UtopiaResponse $response, - Database $dbForProject, - Event $queueForEvents - ): void { + public function action(string $databaseId, string $collectionId, string $key, ?bool $required, ?string $default, ?string $newKey, UtopiaResponse $response, Database $dbForProject, Event $queueForEvents): void + { $attribute = $this->updateAttribute( databaseId: $databaseId, collectionId: $collectionId, diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Attributes/Integer/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Attributes/Integer/Create.php index 99371b26d9..9dd013362c 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Attributes/Integer/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Attributes/Integer/Create.php @@ -29,10 +29,13 @@ class Create extends Action return 'createIntegerAttribute'; } + protected function getResponseModel(): string|array + { + return UtopiaResponse::MODEL_ATTRIBUTE_INTEGER; + } + public function __construct() { - $this->setResponseModel(UtopiaResponse::MODEL_ATTRIBUTE_INTEGER); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_POST) ->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/integer') @@ -71,20 +74,8 @@ class Create extends Action ->callback([$this, 'action']); } - public function action( - string $databaseId, - string $collectionId, - string $key, - ?bool $required, - ?int $min, - ?int $max, - ?int $default, - bool $array, - UtopiaResponse $response, - Database $dbForProject, - EventDatabase $queueForDatabase, - Event $queueForEvents - ): void { + public function action(string $databaseId, string $collectionId, string $key, ?bool $required, ?int $min, ?int $max, ?int $default, bool $array, UtopiaResponse $response, Database $dbForProject, EventDatabase $queueForDatabase, Event $queueForEvents): void + { $min ??= \PHP_INT_MIN; $max ??= \PHP_INT_MAX; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Attributes/Integer/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Attributes/Integer/Update.php index 51c72af363..6e1379daff 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Attributes/Integer/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Attributes/Integer/Update.php @@ -27,10 +27,13 @@ class Update extends Action return 'updateIntegerAttribute'; } + protected function getResponseModel(): string|array + { + return UtopiaResponse::MODEL_ATTRIBUTE_INTEGER; + } + public function __construct() { - $this->setResponseModel(UtopiaResponse::MODEL_ATTRIBUTE_INTEGER); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) ->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/integer/:key') @@ -69,19 +72,8 @@ class Update extends Action ->callback([$this, 'action']); } - public function action( - string $databaseId, - string $collectionId, - string $key, - ?bool $required, - ?int $min, - ?int $max, - ?int $default, - ?string $newKey, - UtopiaResponse $response, - Database $dbForProject, - Event $queueForEvents - ): void { + public function action(string $databaseId, string $collectionId, string $key, ?bool $required, ?int $min, ?int $max, ?int $default, ?string $newKey, UtopiaResponse $response, Database $dbForProject, Event $queueForEvents): void + { $attribute = $this->updateAttribute( databaseId: $databaseId, collectionId: $collectionId, diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Attributes/Relationship/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Attributes/Relationship/Create.php index cdc1861c26..49d853bed6 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Attributes/Relationship/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Attributes/Relationship/Create.php @@ -29,10 +29,13 @@ class Create extends Action return 'createRelationshipAttribute'; } + protected function getResponseModel(): string|array + { + return UtopiaResponse::MODEL_ATTRIBUTE_RELATIONSHIP; + } + public function __construct() { - $this->setResponseModel(UtopiaResponse::MODEL_ATTRIBUTE_RELATIONSHIP); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_POST) ->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/relationship') @@ -80,20 +83,8 @@ class Create extends Action ->callback([$this, 'action']); } - public function action( - string $databaseId, - string $collectionId, - string $relatedCollectionId, - string $type, - bool $twoWay, - ?string $key, - ?string $twoWayKey, - string $onDelete, - UtopiaResponse $response, - Database $dbForProject, - EventDatabase $queueForDatabase, - Event $queueForEvents - ): void { + public function action(string $databaseId, string $collectionId, string $relatedCollectionId, string $type, bool $twoWay, ?string $key, ?string $twoWayKey, string $onDelete, UtopiaResponse $response, Database $dbForProject, EventDatabase $queueForDatabase, Event $queueForEvents): void + { $key ??= $relatedCollectionId; $twoWayKey ??= $collectionId; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Attributes/Relationship/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Attributes/Relationship/Update.php index 6416e7793e..9c95bd2a65 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Attributes/Relationship/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Attributes/Relationship/Update.php @@ -25,10 +25,13 @@ class Update extends Action return 'updateRelationshipAttribute'; } + protected function getResponseModel(): string|array + { + return UtopiaResponse::MODEL_ATTRIBUTE_RELATIONSHIP; + } + public function __construct() { - $this->setResponseModel(UtopiaResponse::MODEL_ATTRIBUTE_RELATIONSHIP); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) ->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/:key/relationship') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Attributes/String/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Attributes/String/Create.php index 29e3ce757d..47386f7530 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Attributes/String/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Attributes/String/Create.php @@ -30,10 +30,13 @@ class Create extends Action return 'createStringAttribute'; } + protected function getResponseModel(): string|array + { + return UtopiaResponse::MODEL_ATTRIBUTE_STRING; + } + public function __construct() { - $this->setResponseModel(UtopiaResponse::MODEL_ATTRIBUTE_STRING); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_POST) ->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/string') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Attributes/String/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Attributes/String/Update.php index b76a34951e..08c55e6021 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Attributes/String/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Attributes/String/Update.php @@ -29,10 +29,13 @@ class Update extends Action return 'updateStringAttribute'; } + protected function getResponseModel(): string|array + { + return UtopiaResponse::MODEL_ATTRIBUTE_STRING; + } + public function __construct() { - $this->setResponseModel(UtopiaResponse::MODEL_ATTRIBUTE_STRING); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) ->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/string/:key') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Attributes/URL/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Attributes/URL/Create.php index 5b1906ac2b..38f5a4773a 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Attributes/URL/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Attributes/URL/Create.php @@ -27,10 +27,13 @@ class Create extends Action return 'createUrlAttribute'; } + protected function getResponseModel(): string|array + { + return UtopiaResponse::MODEL_ATTRIBUTE_URL; + } + public function __construct() { - $this->setResponseModel(UtopiaResponse::MODEL_ATTRIBUTE_URL); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_POST) ->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/url') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Attributes/URL/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Attributes/URL/Update.php index 253649f15a..45309326aa 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Attributes/URL/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Attributes/URL/Update.php @@ -27,10 +27,13 @@ class Update extends Action return 'updateUrlAttribute'; } + protected function getResponseModel(): string|array + { + return UtopiaResponse::MODEL_ATTRIBUTE_URL; + } + public function __construct() { - $this->setResponseModel(UtopiaResponse::MODEL_ATTRIBUTE_URL); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) ->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes/url/:key') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Attributes/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Attributes/XList.php index 072f6987d2..5a190bd671 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Attributes/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Attributes/XList.php @@ -28,10 +28,13 @@ class XList extends Action return 'listAttributes'; } + protected function getResponseModel(): string|array + { + return UtopiaResponse::MODEL_ATTRIBUTE_LIST; + } + public function __construct() { - $this->setResponseModel(UtopiaResponse::MODEL_ATTRIBUTE_LIST); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_GET) ->setHttpPath('/v1/databases/:databaseId/collections/:collectionId/attributes') @@ -67,8 +70,8 @@ class XList extends Action throw new Exception(Exception::DATABASE_NOT_FOUND); } - $table = $dbForProject->getDocument('database_' . $database->getInternalId(), $tableId); - if ($table->isEmpty()) { + $collection = $dbForProject->getDocument('database_' . $database->getInternalId(), $tableId); + if ($collection->isEmpty()) { throw new Exception($this->getParentNotFoundException()); } @@ -77,7 +80,7 @@ class XList extends Action \array_push( $queries, Query::equal('databaseInternalId', [$database->getInternalId()]), - Query::equal('collectionInternalId', [$table->getInternalId()]) + Query::equal('collectionInternalId', [$collection->getInternalId()]) ); $cursor = \array_filter( @@ -96,7 +99,7 @@ class XList extends Action $cursorDocument = Authorization::skip( fn () => $dbForProject->find('attributes', [ Query::equal('databaseInternalId', [$database->getInternalId()]), - Query::equal('collectionInternalId', [$table->getInternalId()]), + Query::equal('collectionInternalId', [$collection->getInternalId()]), Query::equal('key', [$attributeId]), Query::limit(1), ]) @@ -104,7 +107,7 @@ class XList extends Action if (empty($cursorDocument) || $cursorDocument[0]->isEmpty()) { $type = ucfirst($this->getContext()); - throw new Exception(Exception::GENERAL_CURSOR_NOT_FOUND, "$type '{$attributeId}' for the 'cursor' value not found."); + throw new Exception(Exception::GENERAL_CURSOR_NOT_FOUND, "$type '$attributeId' for the 'cursor' value not found."); } $cursor->setValue($cursorDocument[0]); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Collections/Action.php b/src/Appwrite/Platform/Modules/Databases/Http/Collections/Action.php index 2ebcdb4c3f..83500fa964 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Collections/Action.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Collections/Action.php @@ -18,6 +18,11 @@ abstract class Action extends UtopiaAction */ private ?string $context = DATABASE_COLLECTIONS_CONTEXT; + /** + * Get the response model used in the SDK and HTTP responses. + */ + abstract protected function getResponseModel(): string; + /** * Set the current API context. * @@ -50,11 +55,6 @@ abstract class Action extends UtopiaAction return $this->getContext() . 'Id'; } - /** - * Get the response model used in the SDK and HTTP responses. - */ - abstract protected function getResponseModel(): string; - /** * Determine if the current action is for the Collections API. */ diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Columns/Boolean/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Columns/Boolean/Create.php index 385c631493..fafed3bf8d 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Columns/Boolean/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Columns/Boolean/Create.php @@ -25,10 +25,14 @@ class Create extends BooleanCreate return 'createBooleanColumn'; } + protected function getResponseModel(): string|array + { + return UtopiaResponse::MODEL_COLUMN_BOOLEAN; + } + public function __construct() { $this->setContext(DATABASE_COLUMNS_CONTEXT); - $this->setResponseModel(UtopiaResponse::MODEL_COLUMN_BOOLEAN); $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_POST) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Columns/Boolean/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Columns/Boolean/Update.php index 7b0754ccc7..7bb9e640ad 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Columns/Boolean/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Columns/Boolean/Update.php @@ -26,10 +26,14 @@ class Update extends BooleanUpdate return 'updateBooleanColumn'; } + protected function getResponseModel(): string|array + { + return UtopiaResponse::MODEL_COLUMN_BOOLEAN; + } + public function __construct() { $this->setContext(DATABASE_COLUMNS_CONTEXT); - $this->setResponseModel(UtopiaResponse::MODEL_COLUMN_BOOLEAN); $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Columns/Datetime/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Columns/Datetime/Create.php index 80031d61ab..7d9dc8dcce 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Columns/Datetime/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Columns/Datetime/Create.php @@ -26,10 +26,14 @@ class Create extends DatetimeCreate return 'createDatetimeColumn'; } + protected function getResponseModel(): string|array + { + return UtopiaResponse::MODEL_COLUMN_DATETIME; + } + public function __construct() { $this->setContext(DATABASE_COLUMNS_CONTEXT); - $this->setResponseModel(UtopiaResponse::MODEL_COLUMN_DATETIME); $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_POST) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Columns/Datetime/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Columns/Datetime/Update.php index d7124981d1..7e1b1e196d 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Columns/Datetime/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Columns/Datetime/Update.php @@ -27,10 +27,14 @@ class Update extends DatetimeUpdate return 'updateDatetimeColumn'; } + protected function getResponseModel(): string|array + { + return UtopiaResponse::MODEL_COLUMN_DATETIME; + } + public function __construct() { $this->setContext(DATABASE_COLUMNS_CONTEXT); - $this->setResponseModel(UtopiaResponse::MODEL_COLUMN_DATETIME); $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Columns/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/Columns/Delete.php index eb2c6a9ccf..e712f7cdde 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Columns/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Columns/Delete.php @@ -25,13 +25,16 @@ class Delete extends AttributesDelete return 'deleteColumn'; } + // parent handles multiple model types internally + protected function getResponseModel(): string|array + { + return UtopiaResponse::MODEL_NONE; + } + public function __construct() { $this->setContext(DATABASE_COLUMNS_CONTEXT); - // parent action handles multiple model types internally - $this->setResponseModel(UtopiaResponse::MODEL_NONE); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_DELETE) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/columns/:key') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Columns/Email/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Columns/Email/Create.php index 2fdb994251..a3dfc0d6a2 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Columns/Email/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Columns/Email/Create.php @@ -26,10 +26,14 @@ class Create extends EmailCreate return 'createEmailColumn'; } + protected function getResponseModel(): string|array + { + return UtopiaResponse::MODEL_COLUMN_EMAIL; + } + public function __construct() { $this->setContext(DATABASE_COLUMNS_CONTEXT); - $this->setResponseModel(UtopiaResponse::MODEL_COLUMN_EMAIL); $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_POST) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Columns/Email/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Columns/Email/Update.php index 255e636a39..2f8494250e 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Columns/Email/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Columns/Email/Update.php @@ -27,10 +27,14 @@ class Update extends EmailUpdate return 'updateEmailColumn'; } + protected function getResponseModel(): string|array + { + return UtopiaResponse::MODEL_COLUMN_EMAIL; + } + public function __construct() { $this->setContext(DATABASE_COLUMNS_CONTEXT); - $this->setResponseModel(UtopiaResponse::MODEL_COLUMN_EMAIL); $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Columns/Enum/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Columns/Enum/Create.php index 2408aeeae4..06fc55891e 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Columns/Enum/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Columns/Enum/Create.php @@ -27,10 +27,14 @@ class Create extends EnumCreate return 'createEnumColumn'; } + protected function getResponseModel(): string|array + { + return UtopiaResponse::MODEL_COLUMN_ENUM; + } + public function __construct() { $this->setContext(DATABASE_COLUMNS_CONTEXT); - $this->setResponseModel(UtopiaResponse::MODEL_COLUMN_ENUM); $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_POST) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Columns/Enum/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Columns/Enum/Update.php index c47766b4dd..28a4538b66 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Columns/Enum/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Columns/Enum/Update.php @@ -28,10 +28,14 @@ class Update extends EnumUpdate return 'updateEnumColumn'; } + protected function getResponseModel(): string|array + { + return UtopiaResponse::MODEL_COLUMN_ENUM; + } + public function __construct() { $this->setContext(DATABASE_COLUMNS_CONTEXT); - $this->setResponseModel(UtopiaResponse::MODEL_COLUMN_ENUM); $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Columns/Float/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Columns/Float/Create.php index c8b9a7ec7b..4f5db64d57 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Columns/Float/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Columns/Float/Create.php @@ -26,10 +26,14 @@ class Create extends FloatCreate return 'createFloatColumn'; } + protected function getResponseModel(): string|array + { + return UtopiaResponse::MODEL_COLUMN_FLOAT; + } + public function __construct() { $this->setContext(DATABASE_COLUMNS_CONTEXT); - $this->setResponseModel(UtopiaResponse::MODEL_COLUMN_FLOAT); $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_POST) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Columns/Float/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Columns/Float/Update.php index 1e008de2c0..c7ab1795db 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Columns/Float/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Columns/Float/Update.php @@ -27,10 +27,14 @@ class Update extends FloatUpdate return 'updateFloatColumn'; } + protected function getResponseModel(): string|array + { + return UtopiaResponse::MODEL_COLUMN_FLOAT; + } + public function __construct() { $this->setContext(DATABASE_COLUMNS_CONTEXT); - $this->setResponseModel(UtopiaResponse::MODEL_COLUMN_FLOAT); $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Columns/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Columns/Get.php index d8847f0122..ff69757b6d 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Columns/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Columns/Get.php @@ -22,11 +22,9 @@ class Get extends AttributesGet return 'getColumn'; } - public function __construct() + protected function getResponseModel(): string|array { - $this->setContext(DATABASE_COLUMNS_CONTEXT); - - $this->setResponseModel([ + return [ UtopiaResponse::MODEL_COLUMN_BOOLEAN, UtopiaResponse::MODEL_COLUMN_INTEGER, UtopiaResponse::MODEL_COLUMN_FLOAT, @@ -37,7 +35,12 @@ class Get extends AttributesGet UtopiaResponse::MODEL_COLUMN_DATETIME, UtopiaResponse::MODEL_COLUMN_RELATIONSHIP, UtopiaResponse::MODEL_COLUMN_STRING, - ]); + ]; + } + + public function __construct() + { + $this->setContext(DATABASE_COLUMNS_CONTEXT); $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_GET) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Columns/IP/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Columns/IP/Create.php index a69cc6ccfe..b42f9aaf6b 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Columns/IP/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Columns/IP/Create.php @@ -26,10 +26,14 @@ class Create extends IPCreate return 'createIpColumn'; } + protected function getResponseModel(): string|array + { + return UtopiaResponse::MODEL_COLUMN_IP; + } + public function __construct() { $this->setContext(DATABASE_COLUMNS_CONTEXT); - $this->setResponseModel(UtopiaResponse::MODEL_COLUMN_IP); $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_POST) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Columns/IP/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Columns/IP/Update.php index d4c6db12fe..101041a790 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Columns/IP/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Columns/IP/Update.php @@ -27,10 +27,14 @@ class Update extends IPUpdate return 'updateIpColumn'; } + protected function getResponseModel(): string|array + { + return UtopiaResponse::MODEL_COLUMN_IP; + } + public function __construct() { $this->setContext(DATABASE_COLUMNS_CONTEXT); - $this->setResponseModel(UtopiaResponse::MODEL_COLUMN_IP); $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Columns/Integer/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Columns/Integer/Create.php index 2c394dd042..b0b5eb59bb 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Columns/Integer/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Columns/Integer/Create.php @@ -26,10 +26,14 @@ class Create extends IntegerCreate return 'createIntegerColumn'; } + protected function getResponseModel(): string|array + { + return UtopiaResponse::MODEL_COLUMN_INTEGER; + } + public function __construct() { $this->setContext(DATABASE_COLUMNS_CONTEXT); - $this->setResponseModel(UtopiaResponse::MODEL_COLUMN_INTEGER); $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_POST) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Columns/Integer/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Columns/Integer/Update.php index 4eacb2b0df..faa42aa3ca 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Columns/Integer/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Columns/Integer/Update.php @@ -27,10 +27,14 @@ class Update extends IntegerUpdate return 'updateIntegerColumn'; } + protected function getResponseModel(): string|array + { + return UtopiaResponse::MODEL_COLUMN_INTEGER; + } + public function __construct() { $this->setContext(DATABASE_COLUMNS_CONTEXT); - $this->setResponseModel(UtopiaResponse::MODEL_COLUMN_INTEGER); $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Columns/Relationship/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Columns/Relationship/Create.php index d0b080b237..2807041377 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Columns/Relationship/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Columns/Relationship/Create.php @@ -26,10 +26,14 @@ class Create extends RelationshipCreate return 'createRelationshipColumn'; } + protected function getResponseModel(): string|array + { + return UtopiaResponse::MODEL_COLUMN_RELATIONSHIP; + } + public function __construct() { $this->setContext(DATABASE_COLUMNS_CONTEXT); - $this->setResponseModel(UtopiaResponse::MODEL_COLUMN_RELATIONSHIP); $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_POST) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Columns/Relationship/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Columns/Relationship/Update.php index 85e4e207a5..81040584b3 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Columns/Relationship/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Columns/Relationship/Update.php @@ -25,15 +25,18 @@ class Update extends RelationshipUpdate return 'updateRelationshipColumn'; } + protected function getResponseModel(): string|array + { + return UtopiaResponse::MODEL_COLUMN_RELATIONSHIP; + } + public function __construct() { $this->setContext(DATABASE_COLUMNS_CONTEXT); - $this->setResponseModel(UtopiaResponse::MODEL_COLUMN_RELATIONSHIP); $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/columns/:key/relationship') - ->httpAlias('/v1/databases/:databaseId/collections/:tableId/attributes/:key/relationship') ->desc('Update relationship column') ->groups(['api', 'database', 'schema']) ->label('scope', 'collections.write') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Columns/String/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Columns/String/Create.php index e00bdf679e..a75563a271 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Columns/String/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Columns/String/Create.php @@ -28,10 +28,14 @@ class Create extends StringCreate return 'createStringColumn'; } + protected function getResponseModel(): string|array + { + return UtopiaResponse::MODEL_COLUMN_STRING; + } + public function __construct() { $this->setContext(DATABASE_COLUMNS_CONTEXT); - $this->setResponseModel(UtopiaResponse::MODEL_COLUMN_STRING); $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_POST) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Columns/String/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Columns/String/Update.php index 9db47fba69..0b1f370696 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Columns/String/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Columns/String/Update.php @@ -29,10 +29,14 @@ class Update extends StringUpdate return 'updateStringColumn'; } + protected function getResponseModel(): string|array + { + return UtopiaResponse::MODEL_COLUMN_STRING; + } + public function __construct() { $this->setContext(DATABASE_COLUMNS_CONTEXT); - $this->setResponseModel(UtopiaResponse::MODEL_COLUMN_STRING); $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Columns/URL/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Columns/URL/Create.php index ee770e9e4d..5c575acb56 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Columns/URL/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Columns/URL/Create.php @@ -26,10 +26,14 @@ class Create extends URLCreate return 'createUrlColumn'; } + protected function getResponseModel(): string|array + { + return UtopiaResponse::MODEL_COLUMN_URL; + } + public function __construct() { $this->setContext(DATABASE_COLUMNS_CONTEXT); - $this->setResponseModel(UtopiaResponse::MODEL_COLUMN_URL); $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_POST) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Columns/URL/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Columns/URL/Update.php index 360445750b..c37a74198a 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Columns/URL/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Columns/URL/Update.php @@ -27,15 +27,18 @@ class Update extends URLUpdate return 'updateUrlColumn'; } + protected function getResponseModel(): string|array + { + return UtopiaResponse::MODEL_COLUMN_URL; + } + public function __construct() { $this->setContext(DATABASE_COLUMNS_CONTEXT); - $this->setResponseModel(UtopiaResponse::MODEL_COLUMN_URL); $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/columns/url/:key') - ->httpAlias('/v1/databases/:databaseId/collections/:tableId/attributes/url/:key') ->desc('Update URL column') ->groups(['api', 'database', 'schema']) ->label('scope', 'collections.write') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Columns/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Columns/XList.php index 06d7a57dcf..280e56fa48 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Columns/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Columns/XList.php @@ -22,10 +22,14 @@ class XList extends AttributesXList return 'listColumns'; } + protected function getResponseModel(): string|array + { + return UtopiaResponse::MODEL_COLUMN_LIST; + } + public function __construct() { $this->setContext(DATABASE_COLUMNS_CONTEXT); - $this->setResponseModel(UtopiaResponse::MODEL_COLUMN_LIST); $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_GET) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Indexes/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Indexes/Create.php index 537d8e27f0..e9dd4c7092 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Indexes/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Indexes/Create.php @@ -39,13 +39,13 @@ class Create extends Action $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_POST) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/indexes') - ->httpAlias('/v1/databases/:databaseId/collections/:tableId/indexes') ->desc('Create index') ->groups(['api', 'database']) ->label('event', 'databases.[databaseId].tables.[tableId].indexes.[indexId].create') ->label('scope', 'collections.write') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('audits.event', 'index.create') + // TODO: audits table or collections, check the context type if possible, move into another module. ->label('audits.resource', 'database/{request.databaseId}/table/{request.tableId}') ->label('sdk', new Method( namespace: 'databases', diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Indexes/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/Indexes/Delete.php index 78e1799164..dd7c4bd5e7 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Indexes/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Indexes/Delete.php @@ -32,13 +32,13 @@ class Delete extends Action $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_DELETE) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/indexes/:key') - ->httpAlias('/v1/databases/:databaseId/collections/:tableId/indexes/:key') ->desc('Delete index') ->groups(['api', 'database']) ->label('scope', 'collections.write') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('event', 'databases.[databaseId].tables.[tableId].indexes.[indexId].update') ->label('audits.event', 'index.delete') + // TODO: audits table or collections, check the context type if possible ->label('audits.resource', 'database/{request.databaseId}/table/{request.tableId}') ->label('sdk', new Method( namespace: 'databases', diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Indexes/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Indexes/Get.php index b1689481ed..a89819d844 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Indexes/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Indexes/Get.php @@ -30,7 +30,6 @@ class Get extends Action $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_GET) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/indexes/:key') - ->httpAlias('/v1/databases/:databaseId/collections/:tableId/indexes/:key') ->desc('Get index') ->groups(['api', 'database']) ->label('scope', 'collections.read') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Indexes/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Indexes/XList.php index 53c623f9f4..b11806cfd0 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Indexes/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Indexes/XList.php @@ -34,7 +34,6 @@ class XList extends Action $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_GET) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/indexes') - ->httpAlias('/v1/databases/:databaseId/collections/:tableId/indexes') ->desc('List indexes') ->groups(['api', 'database']) ->label('scope', 'collections.read') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Rows/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Rows/Get.php index 8eb07ef94e..3ec0ea6213 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Rows/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Rows/Get.php @@ -37,7 +37,6 @@ class Get extends DocumentGet $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_GET) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/rows/:rowId') - ->httpAlias('/v1/databases/:databaseId/collections/:tableId/documents/:rowId') ->desc('Get row') ->groups(['api', 'database']) ->label('scope', 'documents.read') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Rows/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Rows/Update.php index d29a8dcd12..34d947796e 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Rows/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Rows/Update.php @@ -38,7 +38,6 @@ class Update extends DocumentUpdate $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/rows/:rowId') - ->httpAlias('/v1/databases/:databaseId/collections/:tableId/documents/:rowId') ->desc('Update row') ->groups(['api', 'database']) ->label('event', 'databases.[databaseId].tables.[tableId].rows.[rowId].update') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Rows/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Rows/XList.php index a954312493..041f532840 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Rows/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Rows/XList.php @@ -37,7 +37,6 @@ class XList extends DocumentXList $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_GET) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/rows') - ->httpAlias('/v1/databases/:databaseId/collections/:tableId/documents') ->desc('List rows') ->groups(['api', 'database']) ->label('scope', 'documents.read')