mirror of
https://github.com/Telecominfraproject/wlan-cloud-analytics.git
synced 2026-01-27 02:22:21 +00:00
Framework update.
This commit is contained in:
@@ -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'
|
||||
|
||||
@@ -58,4 +58,12 @@ namespace OpenWifi {
|
||||
}
|
||||
}
|
||||
|
||||
template <typename DBType> 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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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_;
|
||||
|
||||
Reference in New Issue
Block a user