From 1b922f7319f821fe3daf302a8c68131aaa94f586 Mon Sep 17 00:00:00 2001 From: neodarz Date: Fri, 6 Sep 2019 18:04:40 +0200 Subject: Change code to use Restbed --- db/uobject.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'db/uobject.cpp') diff --git a/db/uobject.cpp b/db/uobject.cpp index 6401307..25b13e6 100644 --- a/db/uobject.cpp +++ b/db/uobject.cpp @@ -103,8 +103,10 @@ std::string uobject::remove(std::string collection, std::string oid, struct json json_object_object_add(json_id, "$oid", json_oid); json_object_object_add(jsonObject, "_id", json_id); json_object_object_add(jsonObject, "datas", {}); + return json_object_to_json_string_ext(jsonObject, JSON_C_TO_STRING_SPACED | JSON_C_TO_STRING_PRETTY); + } else { + return "0"; } - return json_object_to_json_string_ext(jsonObject, JSON_C_TO_STRING_SPACED | JSON_C_TO_STRING_PRETTY); } std::string uobject::searchKeyValue(std::string collection, std::string key, std::string value, struct json_object* jsonArray) { -- cgit v1.2.1 From bc6aeaa834d666221171d302d4f101ce65608898 Mon Sep 17 00:00:00 2001 From: neodarz Date: Mon, 9 Sep 2019 17:17:44 +0200 Subject: Refactoring some code to be more readable --- db/uobject.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'db/uobject.cpp') diff --git a/db/uobject.cpp b/db/uobject.cpp index 25b13e6..38b472f 100644 --- a/db/uobject.cpp +++ b/db/uobject.cpp @@ -3,7 +3,9 @@ using bsoncxx::builder::basic::kvp; using bsoncxx::builder::basic::make_document; -std::string uobject::retrieveAll(std::string collection, struct json_object* jsonObjects) { +UmosapiService::uobject::uobject() {} + +std::string UmosapiService::uobject::retrieveAll(std::string collection, struct json_object* jsonObjects) { auto conn = mongo.get_connection(); @@ -18,7 +20,7 @@ std::string uobject::retrieveAll(std::string collection, struct json_object* jso return json_object_to_json_string_ext(jsonObjects, JSON_C_TO_STRING_SPACED | JSON_C_TO_STRING_PRETTY); } -std::string uobject::add(std::string collection, struct json_object* jsonObject, const char * body) { +std::string UmosapiService::uobject::add(std::string collection, struct json_object* jsonObject, const char * body) { auto conn = mongo.get_connection(); auto coll = (*conn)[config["mongo_db"]][collection]; @@ -77,7 +79,7 @@ std::string uobject::add(std::string collection, struct json_object* jsonObject, return json_object_to_json_string_ext(jsonObject, JSON_C_TO_STRING_SPACED | JSON_C_TO_STRING_PRETTY); } -std::string uobject::remove(std::string collection, std::string oid, struct json_object* jsonObject) { +std::string UmosapiService::uobject::remove(std::string collection, std::string oid, struct json_object* jsonObject) { auto conn = mongo.get_connection(); auto coll = (*conn)[config["mongo_db"]][collection]; @@ -109,7 +111,7 @@ std::string uobject::remove(std::string collection, std::string oid, struct json } } -std::string uobject::searchKeyValue(std::string collection, std::string key, std::string value, struct json_object* jsonArray) { +std::string UmosapiService::uobject::searchKeyValue(std::string collection, std::string key, std::string value, struct json_object* jsonArray) { auto conn = mongo.get_connection(); auto coll = (*conn)[config["mongo_db"]][collection]; -- cgit v1.2.1 From cc8c1ad450667c8f6f983ba4f0d640accdcb49cf Mon Sep 17 00:00:00 2001 From: neodarz Date: Tue, 10 Sep 2019 10:26:16 +0200 Subject: Little refactorisation --- db/uobject.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'db/uobject.cpp') diff --git a/db/uobject.cpp b/db/uobject.cpp index 38b472f..bb911bb 100644 --- a/db/uobject.cpp +++ b/db/uobject.cpp @@ -13,7 +13,7 @@ std::string UmosapiService::uobject::retrieveAll(std::string collection, struct auto cursor = coll.find({}); - for (auto&& doc : cursor) { + for (const auto& doc : cursor) { json_object_array_add(jsonObjects, json_tokener_parse(bsoncxx::to_json(doc).c_str())); } @@ -126,7 +126,7 @@ std::string UmosapiService::uobject::searchKeyValue(std::string collection, std: auto cursor = coll.find(bsoncxx::from_json(json_string)); - for (auto&& doc : cursor) { + for (const auto& doc : cursor) { json_object_array_add(jsonArray, json_tokener_parse(bsoncxx::to_json(doc).c_str())); } -- cgit v1.2.1