@@ -102,21 +102,36 @@ std::string Databases::update(const std::string &databaseId, const std::string &
102
102
}
103
103
}
104
104
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 ;
108
108
109
109
std::vector<std::string> headers = Config::getHeaders (projectId);
110
110
headers.push_back (" X-Appwrite-Key: " + apiKey);
111
111
112
112
std::string response;
113
-
114
113
int statusCode = Utils::getRequest (url, headers, response);
115
114
116
115
if (statusCode == HttpStatus::OK) {
117
116
return response;
117
+ } else {
118
+ throw AppwriteException (" Error fetching database usage. Status code: " + std::to_string (statusCode) + " \n\n Response: " + response);
118
119
}
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 {
120
135
throw AppwriteException (" Error listing collections. Status code: " + std::to_string (statusCode) + " \n\n Response: " + response);
121
136
}
122
137
}
@@ -205,6 +220,22 @@ std::string Databases::deleteCollection(const std::string& databaseId, const std
205
220
}
206
221
}
207
222
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
+ }
208
239
// attribute
209
240
std::string Databases::createBooleanAttribute (const std::string& databaseId, const std::string& collectionId, const std::string& attributeId, bool defaultValue, bool required) {
210
241
@@ -794,37 +825,3 @@ std::string Databases::getIndexes(const std::string& databaseId, const std::stri
794
825
}
795
826
796
827
}
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