From f28ef3f65bbd220b81cc8590640b408277fee165 Mon Sep 17 00:00:00 2001 From: stephb9959 Date: Thu, 21 Oct 2021 08:44:35 -0700 Subject: [PATCH] Fixing location/contact deletion. --- build | 2 +- src/RESTAPI/RESTAPI_contact_handler.cpp | 2 ++ src/RESTAPI/RESTAPI_contact_list_handler.cpp | 2 +- src/RESTAPI/RESTAPI_location_handler.cpp | 3 +++ src/RESTAPI/RESTAPI_location_list_handler.cpp | 2 +- src/framework/RESTAPI_errors.h | 2 +- 6 files changed, 9 insertions(+), 4 deletions(-) diff --git a/build b/build index 52f6c1a..db057cf 100644 --- a/build +++ b/build @@ -1 +1 @@ -352 \ No newline at end of file +354 \ No newline at end of file diff --git a/src/RESTAPI/RESTAPI_contact_handler.cpp b/src/RESTAPI/RESTAPI_contact_handler.cpp index 312c5c9..08a38e8 100644 --- a/src/RESTAPI/RESTAPI_contact_handler.cpp +++ b/src/RESTAPI/RESTAPI_contact_handler.cpp @@ -70,6 +70,8 @@ namespace OpenWifi{ } if(DB_.DeleteRecord("id",UUID)) { + if(!Existing.entity.empty()) + Storage()->EntityDB().DeleteLocation("id",Existing.entity,UUID); return OK(); } InternalError(RESTAPI::Errors::CouldNotBeDeleted); diff --git a/src/RESTAPI/RESTAPI_contact_list_handler.cpp b/src/RESTAPI/RESTAPI_contact_list_handler.cpp index d161893..6e2a53f 100644 --- a/src/RESTAPI/RESTAPI_contact_list_handler.cpp +++ b/src/RESTAPI/RESTAPI_contact_list_handler.cpp @@ -23,7 +23,7 @@ namespace OpenWifi{ AddContactExtendedInfo(E, Obj); ObjArr.add(Obj); } else { - return BadRequest(RESTAPI::Errors::UnknownId + " ("+i+")"); + return BadRequest(RESTAPI::Errors::ContactMustExist + " ("+i+")"); } } Poco::JSON::Object Answer; diff --git a/src/RESTAPI/RESTAPI_location_handler.cpp b/src/RESTAPI/RESTAPI_location_handler.cpp index 3ac0386..2bdf2be 100644 --- a/src/RESTAPI/RESTAPI_location_handler.cpp +++ b/src/RESTAPI/RESTAPI_location_handler.cpp @@ -68,6 +68,9 @@ namespace OpenWifi{ } if(DB_.DeleteRecord("id",UUID)) { + if(!Existing.entity.empty()) + Storage()->EntityDB().DeleteLocation("id",Existing.entity,UUID); + return OK(); } InternalError(RESTAPI::Errors::CouldNotBeDeleted); diff --git a/src/RESTAPI/RESTAPI_location_list_handler.cpp b/src/RESTAPI/RESTAPI_location_list_handler.cpp index 909874d..d36fa08 100644 --- a/src/RESTAPI/RESTAPI_location_list_handler.cpp +++ b/src/RESTAPI/RESTAPI_location_list_handler.cpp @@ -24,7 +24,7 @@ namespace OpenWifi{ AddLocationExtendedInfo(E, Obj); ObjArr.add(Obj); } else { - return BadRequest(RESTAPI::Errors::UnknownId + " ("+i+")"); + return BadRequest(RESTAPI::Errors::LocationMustExist + " ("+i+")"); } } Poco::JSON::Object Answer; diff --git a/src/framework/RESTAPI_errors.h b/src/framework/RESTAPI_errors.h index 3fa041e..d2e499f 100644 --- a/src/framework/RESTAPI_errors.h +++ b/src/framework/RESTAPI_errors.h @@ -15,7 +15,7 @@ namespace OpenWifi::RESTAPI::Errors { static const std::string CouldNotBeDeleted{"Element could not be deleted."}; static const std::string NameMustBeSet{"The name property must be set."}; static const std::string ConfigBlockInvalid{"Configuration block type invalid."}; - static const std::string UnknownId{"Unknown management policy."}; + static const std::string UnknownId{"Unknown UUID."}; static const std::string InvalidDeviceTypes{"Unknown or invalid device type(s)."}; static const std::string RecordNotCreated{"Record could not be created."}; static const std::string RecordNotUpdated{"Record could not be updated."};