diff --git a/build b/build index d1cbcfa..8323328 100644 --- a/build +++ b/build @@ -1 +1 @@ -66 \ No newline at end of file +67 \ No newline at end of file diff --git a/openapi/owanalytics.yaml b/openapi/owanalytics.yaml index ba64618..b7ccb84 100644 --- a/openapi/owanalytics.yaml +++ b/openapi/owanalytics.yaml @@ -1272,6 +1272,20 @@ paths: type: string format: uuid required: true + - in: query + description: return extended information + name: orderBy + schema: + type: string + example: serialNumber:a,created:d + required: false + - in: query + description: return extended information + name: orderSpec + schema: + type: boolean + default: false + required: false responses: 200: $ref: '#/components/schemas/WifiClientHistoryList' diff --git a/src/RESTAPI/RESTAPI_analytics_db_helpers.h b/src/RESTAPI/RESTAPI_analytics_db_helpers.h index cdf3fd4..dbda2dc 100644 --- a/src/RESTAPI/RESTAPI_analytics_db_helpers.h +++ b/src/RESTAPI/RESTAPI_analytics_db_helpers.h @@ -58,4 +58,12 @@ namespace OpenWifi { } } + template void ReturnFieldList(DBType & DB, RESTAPIHandler &H) { + Types::StringVec Fields; + DB.GetFieldNames(Fields); + Poco::JSON::Object Answer; + RESTAPI_utils::field_to_json(Answer,"list",Fields); + return H.ReturnObject(Answer); + } + } \ No newline at end of file diff --git a/src/RESTAPI/RESTAPI_wificlienthistory_handler.cpp b/src/RESTAPI/RESTAPI_wificlienthistory_handler.cpp index dfe5b64..236487d 100644 --- a/src/RESTAPI/RESTAPI_wificlienthistory_handler.cpp +++ b/src/RESTAPI/RESTAPI_wificlienthistory_handler.cpp @@ -4,11 +4,16 @@ #include "RESTAPI_wificlienthistory_handler.h" #include "WifiClientCache.h" +#include "RESTAPI_analytics_db_helpers.h" namespace OpenWifi { void RESTAPI_wificlienthistory_handler::DoGet() { + if(GetBoolParameter("orderSpec")) { + return ReturnFieldList(DB_,*this); + } + auto venue = GetParameter("venue",""); if(venue.empty()) { return BadRequest(RESTAPI::Errors::VenueMustExist); @@ -32,21 +37,13 @@ namespace OpenWifi { return BadRequest(RESTAPI::Errors::InvalidSerialNumber); } - auto orderBy = GetParameter("orderBy"); - if(orderBy.empty()) { - orderBy = " order by timestamp DESC"; - } else { - auto tokens = Poco::StringTokenizer(orderBy,":",Poco::StringTokenizer::TOK_TRIM); - if(tokens.count()!=2 || (tokens[1]!="a" && tokens[1]!="d")) { - return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters); + std::string OrderBy{" ORDER BY timestamp DESC "}, Arg; + if(HasParameter("orderBy",Arg)) { + if(!DB_.PrepareOrderBy(Arg,OrderBy)) { + return BadRequest(RESTAPI::Errors::InvalidLOrderBy); } - if(!StorageService()->WifiClientHistoryDB().ValidFieldName(tokens[0])) { - return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters); - } - orderBy = fmt::format(" order by {} {}",tokens[0] , tokens[1]=="a" ? "asc" : "desc"); } - auto fromDate = GetParameter("fromDate",0); auto endDate = GetParameter("endDate",0); @@ -66,7 +63,7 @@ namespace OpenWifi { return ReturnCountOnly(Count); } - if(StorageService()->WifiClientHistoryDB().GetRecords(QB_.Offset,QB_.Limit, Results, Where, orderBy)) { + if(StorageService()->WifiClientHistoryDB().GetRecords(QB_.Offset,QB_.Limit, Results, Where, OrderBy)) { return ReturnObject("entries",Results); } diff --git a/src/framework/orm.h b/src/framework/orm.h index 3b78430..7b358a9 100644 --- a/src/framework/orm.h +++ b/src/framework/orm.h @@ -688,7 +688,7 @@ namespace ORM { } if(!ItemList.empty()) ItemList += " , "; - auto hint = FieldNames_.find(T[0]); + auto hint = FieldNames_.find(Poco::toLower(T[0])); if(hint==FieldNames_.end()) { return false; } @@ -898,12 +898,17 @@ namespace ORM { Poco::Logger & Logger() { return Logger_; } - bool DeleteRecordsFromCache(const char *FieldName, const std::string &Value ) { + inline bool DeleteRecordsFromCache(const char *FieldName, const std::string &Value ) { if(Cache_) Cache_->Delete(FieldName, Value); return true; } + inline void GetFieldNames( OpenWifi::Types::StringVec & F) { + for(const auto &[field,_]:FieldNames_) + F.push_back(field); + } + protected: std::string TableName_; OpenWifi::DBType Type_;