From 85e1431aa382f721e3b51804ca0b00ab063553ef Mon Sep 17 00:00:00 2001 From: neodarz Date: Thu, 8 Aug 2019 19:07:02 +0200 Subject: Add ability to delete an uobject --- api/umosapi.cpp | 18 ++++++++++++++++++ api/umosapi.h | 2 ++ 2 files changed, 20 insertions(+) (limited to 'api') diff --git a/api/umosapi.cpp b/api/umosapi.cpp index de2a693..6be8690 100644 --- a/api/umosapi.cpp +++ b/api/umosapi.cpp @@ -104,6 +104,15 @@ void UmosapiService::createDescription() { .parameter("mcollection", "Name of the collection where the uobjects are located") .response(Http::Code::Ok, "Uobject created") .response(backendErrorResponse); + + versionPath + .route(desc.del("/:mcollection/:oid")) + .bind(&UmosapiService::UmosapiService::deleteUObject, this) + .produces(MIME(Application, Json)) + .parameter("mcollection", "Name of the collection where the uobjects are located") + .parameter("oid", "MongoDB oid of the uobject") + .response(Http::Code::Ok, "Uobject deleted") + .response(backendErrorResponse); } void UmosapiService::retrieveAll(const Rest::Request& request, Http::ResponseWriter response) { @@ -122,3 +131,12 @@ void UmosapiService::addUObject(const Rest::Request& request, Http::ResponseWrit response.send(Http::Code::Ok, json_string, MIME(Application, Json)); json_object_put(jsonObject); } + +void UmosapiService::deleteUObject(const Rest::Request& request, Http::ResponseWriter response) { + + auto jsonObjet = json_object_new_object(); + + auto json_string = uobject::remove(request.param(":mcollection").as(), request.param(":oid").as(), jsonObjet); + + response.send(Http::Code::Ok, json_string, MIME(Application, Json)); +} diff --git a/api/umosapi.h b/api/umosapi.h index 684f9d5..2e5e343 100644 --- a/api/umosapi.h +++ b/api/umosapi.h @@ -26,6 +26,8 @@ class UmosapiService { void addUObject(const Rest::Request& request, Http::ResponseWriter response); + void deleteUObject(const Rest::Request& request, Http::ResponseWriter response); + std::shared_ptr httpEndpoint; Rest::Description desc; Rest::Router router; -- cgit v1.2.1