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/mongo_access.cpp | 10 +++++----- db/mongo_access.h | 3 ++- db/uobject.cpp | 10 ++++++---- db/uobject.h | 12 ++++++++++-- 4 files changed, 23 insertions(+), 12 deletions(-) (limited to 'db') diff --git a/db/mongo_access.cpp b/db/mongo_access.cpp index 56936f3..a19488e 100644 --- a/db/mongo_access.cpp +++ b/db/mongo_access.cpp @@ -1,9 +1,9 @@ #include "mongo_access.h" -mongo_access::mongo_access(void) {}; -mongo_access::~mongo_access(void) {}; +UmosapiService::mongo_access::mongo_access(void) {}; +UmosapiService::mongo_access::~mongo_access(void) {}; -void mongo_access::configure(mongocxx::uri uri) { +void UmosapiService::mongo_access::configure(mongocxx::uri uri) { class noop_logger : public mongocxx::logger { public: virtual void operator()(mongocxx::log_level, @@ -11,6 +11,6 @@ void mongo_access::configure(mongocxx::uri uri) { bsoncxx::stdx::string_view) noexcept {} }; - _pool = bsoncxx::stdx::make_unique(std::move(uri)); - _instance = bsoncxx::stdx::make_unique(bsoncxx::stdx::make_unique()); + UmosapiService::mongo_access::_pool = bsoncxx::stdx::make_unique(std::move(uri)); + UmosapiService::mongo_access::_instance = bsoncxx::stdx::make_unique(bsoncxx::stdx::make_unique()); } diff --git a/db/mongo_access.h b/db/mongo_access.h index f03cece..a37bc1b 100644 --- a/db/mongo_access.h +++ b/db/mongo_access.h @@ -15,7 +15,7 @@ #include - +namespace UmosapiService { class mongo_access { public: @@ -39,5 +39,6 @@ class mongo_access { std::unique_ptr _pool = nullptr; }; +} #endif 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]; diff --git a/db/uobject.h b/db/uobject.h index 0533661..2abf7dd 100644 --- a/db/uobject.h +++ b/db/uobject.h @@ -19,11 +19,19 @@ #include "../shared.h" #include "../db/mongo_access.h" -namespace uobject { +namespace UmosapiService { + +class uobject { + public: + + uobject(); + virtual ~uobject() {}; + std::string retrieveAll(std::string collection, struct json_object* jsonObjects); std::string add(std::string collection, struct json_object* jsonObjects, const char * body); std::string remove(std::string collection, std::string oid, struct json_object* jsonObjects); std::string searchKeyValue(std::string collection, std::string key, std::string value, struct json_object* jsonArray); -} +}; +} #endif -- cgit v1.2.1