diff options
author | neodarz <neodarz@neodarz.net> | 2019-08-09 16:28:59 +0200 |
---|---|---|
committer | neodarz <neodarz@neodarz.net> | 2019-08-09 16:28:59 +0200 |
commit | cf86e3de524ff247f496c34cd9e8df61cd4e6845 (patch) | |
tree | c7070f754e7d2d7f238bcc776161628f18998c21 /api | |
parent | a6408962010c1880a54d2f0f3a1e35b0ca65531d (diff) | |
download | umosapicpp-cf86e3de524ff247f496c34cd9e8df61cd4e6845.tar.xz umosapicpp-cf86e3de524ff247f496c34cd9e8df61cd4e6845.zip |
Add ability to search uobjects
Diffstat (limited to 'api')
-rw-r--r-- | api/umosapi.cpp | 19 | ||||
-rw-r--r-- | api/umosapi.h | 2 |
2 files changed, 21 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); +} diff --git a/api/umosapi.h b/api/umosapi.h index 2e5e343..20c6d7b 100644 --- a/api/umosapi.h +++ b/api/umosapi.h @@ -28,6 +28,8 @@ class UmosapiService { void deleteUObject(const Rest::Request& request, Http::ResponseWriter response); + void searchUObjectByKeyValue(const Rest::Request& request, Http::ResponseWriter response); + std::shared_ptr<Http::Endpoint> httpEndpoint; Rest::Description desc; Rest::Router router; |