From cf86e3de524ff247f496c34cd9e8df61cd4e6845 Mon Sep 17 00:00:00 2001 From: neodarz Date: Fri, 9 Aug 2019 16:28:59 +0200 Subject: Add ability to search uobjects --- api/umosapi.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'api/umosapi.cpp') 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("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("mcollection", "Name of the collection where the uobjects are located") + .parameter("key", "Key of uobject to search, ex.: kil or total.kill") + .parameter("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(), request.param(":key").as(), request.param(":value").as(), jsonObject); + + response.send(Http::Code::Ok, json_string, MIME(Application, Json)); + json_object_put(jsonObject); +} -- cgit v1.2.1