Skip to content

Commit 41416fb

Browse files
kbshyam31pooranjoyb
authored andcommitted
Convert JSON to string in createIndexes
1 parent d09baf0 commit 41416fb

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

src/services/Databases.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -760,15 +760,17 @@ std::string Databases::createIndexes(const std::string& databaseId, const std::s
760760

761761
std::string url = Config::API_BASE_URL + "/databases/" + databaseId + "/collections/" + collectionId + "/indexes";
762762

763-
json payloadJson = {
764-
{"databaseId", databaseId},
765-
{"collectionId", collectionId},
766-
{"key", key},
767-
{"type", type},
768-
{"attributes", attributes}
769-
};
770-
771-
std::string payload = payloadJson.dump();
763+
std::string attributesStr = "[";
764+
for(auto attribute : attributes) {
765+
attributesStr += "\"" + attribute + "\",";
766+
}
767+
attributesStr.pop_back();
768+
attributesStr += "]";
769+
std::string payload = R"({"databaseId":")" + databaseId
770+
+ R"(","collectionId":")" + collectionId
771+
+ R"(","key":")" + key
772+
+ R"(","type":")" + type
773+
+ R"(","attributes":)" + attributesStr + R"(})";
772774
std::vector<std::string> headers = Config::getHeaders(projectId);
773775
headers.push_back("X-Appwrite-Key: " + apiKey);
774776

src/services/Storage.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "classes/Storage.hpp"
33
#include "Validator.hpp"
44
#include <json.hpp>
5+
#include <sstream>
56
#include "Utils.hpp"
67
#include "config/Config.hpp"
78
#include "enums/HttpStatus.hpp"

0 commit comments

Comments
 (0)