@@ -102,21 +102,36 @@ std::string Databases::update(const std::string &databaseId, const std::string &
102102 }
103103}
104104
105- // collection
106- std::string Databases::listCollection (){
107- std::string url = Config::API_BASE_URL + " /databases " ;
105+ std::string Databases::getDatabaseUsage ( const std::string& databaseId, const std::string& range) {
106+ std::string url = Config::API_BASE_URL + " /databases/ " + databaseId + " /usage?range= " + range;
107+ std::cout << " Request URL: " << url << std::endl ;
108108
109109 std::vector<std::string> headers = Config::getHeaders (projectId);
110110 headers.push_back (" X-Appwrite-Key: " + apiKey);
111111
112112 std::string response;
113-
114113 int statusCode = Utils::getRequest (url, headers, response);
115114
116115 if (statusCode == HttpStatus::OK) {
117116 return response;
117+ } else {
118+ throw AppwriteException (" Error fetching database usage. Status code: " + std::to_string (statusCode) + " \n\n Response: " + response);
118119 }
119- else {
120+ }
121+
122+ // collection
123+ std::string Databases::listCollection (const std::string& databaseId) {
124+ std::string url = Config::API_BASE_URL + " /databases/" + databaseId + " /collections" ;
125+
126+ std::vector<std::string> headers = Config::getHeaders (projectId);
127+ headers.push_back (" X-Appwrite-Key: " + apiKey);
128+
129+ std::string response;
130+ int statusCode = Utils::getRequest (url, headers, response);
131+
132+ if (statusCode == HttpStatus::OK) {
133+ return response;
134+ } else {
120135 throw AppwriteException (" Error listing collections. Status code: " + std::to_string (statusCode) + " \n\n Response: " + response);
121136 }
122137}
@@ -205,6 +220,22 @@ std::string Databases::deleteCollection(const std::string& databaseId, const std
205220 }
206221}
207222
223+ std::string Databases::getCollectionUsage (const std::string& databaseId, const std::string& collectionId, const std::string& range) {
224+ std::string url = Config::API_BASE_URL + " /databases/" + databaseId + " /collections/" + collectionId + " /usage?range=" + range;
225+ std::cout << " Request URL: " << url << std::endl;
226+
227+ std::vector<std::string> headers = Config::getHeaders (projectId);
228+ headers.push_back (" X-Appwrite-Key: " + apiKey);
229+
230+ std::string response;
231+ int statusCode = Utils::getRequest (url, headers, response);
232+
233+ if (statusCode == HttpStatus::OK) {
234+ return response;
235+ } else {
236+ throw AppwriteException (" Error fetching collection usage. Status code: " + std::to_string (statusCode) + " \n\n Response: " + response);
237+ }
238+ }
208239// attribute
209240std::string Databases::createBooleanAttribute (const std::string& databaseId, const std::string& collectionId, const std::string& attributeId, bool defaultValue, bool required) {
210241
@@ -794,37 +825,3 @@ std::string Databases::getIndexes(const std::string& databaseId, const std::stri
794825 }
795826
796827}
797-
798- std::string Databases::getDatabaseUsage (const std::string& databaseId, const std::string& range) {
799- std::string url = Config::API_BASE_URL + " /databases/" + databaseId + " /usage?range=" + range;
800- std::cout << " Request URL: " << url << std::endl;
801-
802- std::vector<std::string> headers = Config::getHeaders (projectId);
803- headers.push_back (" X-Appwrite-Key: " + apiKey);
804-
805- std::string response;
806- int statusCode = Utils::getRequest (url, headers, response);
807-
808- if (statusCode == HttpStatus::OK) {
809- return response;
810- } else {
811- throw AppwriteException (" Error fetching database usage. Status code: " + std::to_string (statusCode) + " \n\n Response: " + response);
812- }
813- }
814-
815- std::string Databases::getCollectionUsage (const std::string& databaseId, const std::string& collectionId, const std::string& range) {
816- std::string url = Config::API_BASE_URL + " /databases/" + databaseId + " /collections/" + collectionId + " /usage?range=" + range;
817- std::cout << " Request URL: " << url << std::endl;
818-
819- std::vector<std::string> headers = Config::getHeaders (projectId);
820- headers.push_back (" X-Appwrite-Key: " + apiKey);
821-
822- std::string response;
823- int statusCode = Utils::getRequest (url, headers, response);
824-
825- if (statusCode == HttpStatus::OK) {
826- return response;
827- } else {
828- throw AppwriteException (" Error fetching collection usage. Status code: " + std::to_string (statusCode) + " \n\n Response: " + response);
829- }
830- }
0 commit comments