From c86b35fbb335f7518e1ed72628ab83670458ee61 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Mon, 18 Aug 2025 22:29:43 +1200 Subject: [PATCH] Add usage routes --- .../Http/TablesDB/Databases/Usage/Get.php | 53 +++++++++++++++++++ .../Http/TablesDB/Databases/Usage/XList.php | 51 ++++++++++++++++++ .../Databases/Services/Registry/Tables.php | 4 ++ 3 files changed, 108 insertions(+) create mode 100644 src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Databases/Usage/Get.php create mode 100644 src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Databases/Usage/XList.php diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Databases/Usage/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Databases/Usage/Get.php new file mode 100644 index 0000000000..abb6b7a501 --- /dev/null +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Databases/Usage/Get.php @@ -0,0 +1,53 @@ +setHttpMethod(self::HTTP_REQUEST_METHOD_GET) + ->setHttpPath('/v1/tablesdb/:databaseId/usage') + ->desc('Get database usage stats') + ->groups(['api', 'database', 'usage']) + ->label('scope', 'collections.read') + ->label('resourceType', RESOURCE_TYPE_DATABASES) + ->label('sdk', [ + new Method( + namespace: 'tablesdb', + group: null, + name: 'getDatabaseUsage', + description: '/docs/references/tablesdb/get-database-usage.md', + auth: [AuthType::ADMIN], + responses: [ + new SDKResponse( + code: SwooleResponse::STATUS_CODE_OK, + model: UtopiaResponse::MODEL_USAGE_DATABASE, + ) + ], + contentType: ContentType::JSON, + ), + ]) + ->param('databaseId', '', new UID(), 'Database ID.') + ->param('range', '30d', new WhiteList(['24h', '30d', '90d'], true), 'Date range.', true) + ->inject('response') + ->inject('dbForProject') + ->callback($this->action(...)); + } +} \ No newline at end of file diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Databases/Usage/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Databases/Usage/XList.php new file mode 100644 index 0000000000..95189011c1 --- /dev/null +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Databases/Usage/XList.php @@ -0,0 +1,51 @@ +setHttpMethod(self::HTTP_REQUEST_METHOD_GET) + ->setHttpPath('/v1/tablesdb/usage') + ->desc('Get databases usage stats') + ->groups(['api', 'database', 'usage']) + ->label('scope', 'collections.read') + ->label('resourceType', RESOURCE_TYPE_DATABASES) + ->label('sdk', [ + new Method( + namespace: 'tablesdb', + group: null, + name: 'listDatabaseUsage', + description: '/docs/references/tablesdb/list-database-usage.md', + auth: [AuthType::ADMIN], + responses: [ + new SDKResponse( + code: SwooleResponse::STATUS_CODE_OK, + model: UtopiaResponse::MODEL_USAGE_DATABASES, + ) + ], + contentType: ContentType::JSON + ), + ]) + ->param('range', '30d', new WhiteList(['24h', '30d', '90d'], true), 'Date range.', true) + ->inject('response') + ->inject('dbForProject') + ->callback($this->action(...)); + } +} \ No newline at end of file diff --git a/src/Appwrite/Platform/Modules/Databases/Services/Registry/Tables.php b/src/Appwrite/Platform/Modules/Databases/Services/Registry/Tables.php index 3702d39600..7613a8ad5d 100644 --- a/src/Appwrite/Platform/Modules/Databases/Services/Registry/Tables.php +++ b/src/Appwrite/Platform/Modules/Databases/Services/Registry/Tables.php @@ -53,6 +53,8 @@ use Appwrite\Platform\Modules\Databases\Http\TablesDB\Tables\Rows\XList as ListR use Appwrite\Platform\Modules\Databases\Http\TablesDB\Tables\Update as UpdateTable; use Appwrite\Platform\Modules\Databases\Http\TablesDB\Tables\Usage\Get as GetTableUsage; use Appwrite\Platform\Modules\Databases\Http\TablesDB\Tables\XList as ListTables; +use Appwrite\Platform\Modules\Databases\Http\TablesDB\Databases\Usage\Get as GetTablesDatabaseUsage; +use Appwrite\Platform\Modules\Databases\Http\TablesDB\Databases\Usage\XList as ListTablesDatabaseUsage; use Utopia\Platform\Service; /** @@ -82,6 +84,8 @@ class Tables extends Base $service->addAction(UpdateTablesDatabase::getName(), new UpdateTablesDatabase()); $service->addAction(DeleteTablesDatabase::getName(), new DeleteTablesDatabase()); $service->addAction(ListTablesDatabase::getName(), new ListTablesDatabase()); + $service->addAction(GetTablesDatabaseUsage::getName(), new GetTablesDatabaseUsage()); + $service->addAction(ListTablesDatabaseUsage::getName(), new ListTablesDatabaseUsage()); } private function registerTableActions(Service $service): void