From b055711993d70bd2f7652e8f1043a56b9c7137f0 Mon Sep 17 00:00:00 2001 From: Bhavesh Patel Date: Wed, 6 Mar 2024 17:05:29 -0500 Subject: [PATCH] adding includeProvisioned parameter to GET devices REST call to get non provisioned APs easily Signed-off-by: Bhavesh Patel --- openapi/owgw.yaml | 5 +++++ src/RESTAPI/RESTAPI_devices_handler.cpp | 6 +++--- src/StorageService.h | 4 ++-- src/storage/storage_device.cpp | 12 ++++++------ 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/openapi/owgw.yaml b/openapi/owgw.yaml index 74f6859c..c7a3a2d0 100644 --- a/openapi/owgw.yaml +++ b/openapi/owgw.yaml @@ -1698,6 +1698,11 @@ paths: - AP - SWITCH required: false + - in: query + description: only devices which are not provisioned + name: includeProvisioned + schema: + type: boolean responses: 200: description: List devices diff --git a/src/RESTAPI/RESTAPI_devices_handler.cpp b/src/RESTAPI/RESTAPI_devices_handler.cpp index 1879da47..401986eb 100644 --- a/src/RESTAPI/RESTAPI_devices_handler.cpp +++ b/src/RESTAPI/RESTAPI_devices_handler.cpp @@ -86,7 +86,7 @@ namespace OpenWifi { auto serialOnly = GetBoolParameter(RESTAPI::Protocol::SERIALONLY, false); auto deviceWithStatus = GetBoolParameter(RESTAPI::Protocol::DEVICEWITHSTATUS, false); auto completeInfo = GetBoolParameter("completeInfo", false); - auto nonProvisioned = HasParameter("nonProvisioned", Arg); + auto includeProvisioned = GetBoolParameter("includeProvisioned", true); if(!platform.empty() && (platform!="ap" && platform!="switch" && platform!="all")) { return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters); @@ -132,7 +132,7 @@ namespace OpenWifi { } } else if (serialOnly) { std::vector SerialNumbers; - StorageService()->GetDeviceSerialNumbers(QB_.Offset, QB_.Limit, SerialNumbers, OrderBy, platform, nonProvisioned); + StorageService()->GetDeviceSerialNumbers(QB_.Offset, QB_.Limit, SerialNumbers, OrderBy, platform, includeProvisioned); Poco::JSON::Array Objects; for (const auto &i : SerialNumbers) { Objects.add(i); @@ -150,7 +150,7 @@ namespace OpenWifi { RetObj.set("serialNumbers", Objects); } else { std::vector Devices; - StorageService()->GetDevices(QB_.Offset, QB_.Limit, Devices, OrderBy, platform, nonProvisioned); + StorageService()->GetDevices(QB_.Offset, QB_.Limit, Devices, OrderBy, platform, includeProvisioned); Poco::JSON::Array Objects; for (const auto &i : Devices) { Poco::JSON::Object Obj; diff --git a/src/StorageService.h b/src/StorageService.h index e2d70089..be71645a 100644 --- a/src/StorageService.h +++ b/src/StorageService.h @@ -149,7 +149,7 @@ namespace OpenWifi { bool GetDevices(uint64_t From, uint64_t HowMany, std::vector &Devices, const std::string &orderBy = "", const std::string &platform = "", - bool nonProvisioned = false); + bool includeProvisioned = true); // bool GetDevices(uint64_t From, uint64_t HowMany, const std::string & Select, // std::vector &Devices, const std::string & orderBy=""); bool DeleteDevice(std::string &SerialNumber); @@ -166,7 +166,7 @@ namespace OpenWifi { std::vector &SerialNumbers, const std::string &orderBy = "", const std::string &platform = "", - bool nonProvisioned = false); + bool includeProvisioned = true); bool GetDeviceFWUpdatePolicy(std::string &SerialNumber, std::string &Policy); bool SetDevicePassword(LockedDbSession &Session, std::string &SerialNumber, std::string &Password); bool UpdateSerialNumberCache(); diff --git a/src/storage/storage_device.cpp b/src/storage/storage_device.cpp index 3bbfeca4..ebc2c2d6 100644 --- a/src/storage/storage_device.cpp +++ b/src/storage/storage_device.cpp @@ -195,7 +195,7 @@ namespace OpenWifi { bool Storage::GetDeviceSerialNumbers(uint64_t From, uint64_t HowMany, std::vector &SerialNumbers, const std::string &orderBy, - const std::string &platform, bool nonProvisioned) { + const std::string &platform, bool includeProvisioned) { try { Poco::Data::Session Sess = Pool_->get(); Poco::Data::Statement Select(Sess); @@ -203,7 +203,7 @@ namespace OpenWifi { std::string st; std::string whereClause = ""; if(!platform.empty()) { - if (nonProvisioned) { + if (includeProvisioned == false) { whereClause = fmt::format("WHERE entity='' and venue='' and DeviceType='" + platform + "'"); } else { @@ -213,7 +213,7 @@ namespace OpenWifi { //st = "SELECT SerialNumber From Devices WHERE DeviceType='" + platform + "' "; } else { - if (nonProvisioned) { + if (includeProvisioned == false) { whereClause = fmt::format("WHERE entity='' and venue=''"); } //st = "SELECT SerialNumber From Devices "; @@ -851,7 +851,7 @@ namespace OpenWifi { bool Storage::GetDevices(uint64_t From, uint64_t HowMany, std::vector &Devices, const std::string &orderBy, const std::string &platform, - bool nonProvisioned) { + bool includeProvisioned) { DeviceRecordList Records; try { Poco::Data::Session Sess = Pool_->get(); @@ -861,13 +861,13 @@ namespace OpenWifi { std::string whereClause = ""; if(platform.empty()) { - if (nonProvisioned) { + if (includeProvisioned == false) { whereClause = fmt::format("WHERE entity='' and venue=''"); } } else { - if (nonProvisioned) { + if (includeProvisioned == false) { whereClause = fmt::format("WHERE DeviceType='{}' and entity='' and venue=''",platform); } else { whereClause = fmt::format("WHERE DeviceType='{}'", platform);