From 0ce9ff7103a8303cbf7bbefe22adbc2b9505ea17 Mon Sep 17 00:00:00 2001 From: neodarz Date: Thu, 8 Aug 2019 15:50:31 +0200 Subject: Split some codes --- api/umosapi.cpp | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) (limited to 'api') diff --git a/api/umosapi.cpp b/api/umosapi.cpp index de2a2c3..5473e5a 100644 --- a/api/umosapi.cpp +++ b/api/umosapi.cpp @@ -15,6 +15,7 @@ #include "umosapi.h" #include "../shared.h" #include "../db/mongo_access.h" +#include "../db/uobject.h" mongo_access mongo; @@ -106,20 +107,11 @@ void UmosapiService::createDescription() { } void UmosapiService::retrieveAll(const Rest::Request& request, Http::ResponseWriter response) { - auto conn = mongo.get_connection(); - - auto collection = (*conn)[config["mongo_db"]][request.param(":mcollection").as()]; - - auto cursor = collection.find({}); - auto jsonObjects = json_object_new_array(); - - for (auto&& doc : cursor) { - json_object_array_add(jsonObjects, json_tokener_parse(bsoncxx::to_json(doc).c_str())); - } - - response.send(Http::Code::Ok, json_object_to_json_string_ext(jsonObjects, JSON_C_TO_STRING_SPACED | JSON_C_TO_STRING_PRETTY), MIME(Application, Json)); + auto json_string = uobject::retrieveAll(request.param(":mcollection").as(), jsonObjects); json_object_put(jsonObjects); + + response.send(Http::Code::Ok, json_string, MIME(Application, Json)); } void UmosapiService::addUObject(const Rest::Request& request, Http::ResponseWriter response) { -- cgit v1.2.1