aboutsummaryrefslogtreecommitdiff
path: root/api/umosapi.cpp
diff options
context:
space:
mode:
authorneodarz <neodarz@neodarz.net>2019-08-09 16:28:59 +0200
committerneodarz <neodarz@neodarz.net>2019-08-09 16:28:59 +0200
commitcf86e3de524ff247f496c34cd9e8df61cd4e6845 (patch)
treec7070f754e7d2d7f238bcc776161628f18998c21 /api/umosapi.cpp
parenta6408962010c1880a54d2f0f3a1e35b0ca65531d (diff)
downloadumosapicpp-cf86e3de524ff247f496c34cd9e8df61cd4e6845.tar.xz
umosapicpp-cf86e3de524ff247f496c34cd9e8df61cd4e6845.zip
Add ability to search uobjects
Diffstat (limited to '')
-rw-r--r--api/umosapi.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/api/umosapi.cpp b/api/umosapi.cpp
index 6be8690..9db650f 100644
--- a/api/umosapi.cpp
+++ b/api/umosapi.cpp
@@ -113,6 +113,16 @@ void UmosapiService::createDescription() {
.parameter<Rest::Type::String>("oid", "MongoDB oid of the uobject")
.response(Http::Code::Ok, "Uobject deleted")
.response(backendErrorResponse);
+
+ versionPath
+ .route(desc.get("/:mcollection/:key/:value"))
+ .bind(&UmosapiService::UmosapiService::searchUObjectByKeyValue, this)
+ .produces(MIME(Application, Json))
+ .parameter<Rest::Type::String>("mcollection", "Name of the collection where the uobjects are located")
+ .parameter<Rest::Type::String>("key", "Key of uobject to search, ex.: kil or total.kill")
+ .parameter<Rest::Type::String>("value", "Value of uobject to search, ex.: 12")
+ .response(Http::Code::Ok, "Uobject found")
+ .response(backendErrorResponse);
}
void UmosapiService::retrieveAll(const Rest::Request& request, Http::ResponseWriter response) {
@@ -140,3 +150,12 @@ void UmosapiService::deleteUObject(const Rest::Request& request, Http::ResponseW
response.send(Http::Code::Ok, json_string, MIME(Application, Json));
}
+
+void UmosapiService::searchUObjectByKeyValue(const Rest::Request& request, Http::ResponseWriter response) {
+ auto jsonObject = json_object_new_array();
+
+ auto json_string = uobject::searchKeyValue(request.param(":mcollection").as<string>(), request.param(":key").as<string>(), request.param(":value").as<string>(), jsonObject);
+
+ response.send(Http::Code::Ok, json_string, MIME(Application, Json));
+ json_object_put(jsonObject);
+}