Commit badf49e2 authored by Pavel Vainerman's avatar Pavel Vainerman

(LogDB): REST: исправил ошибки в работе с from и to.

parent c87861f3
...@@ -846,9 +846,9 @@ Poco::JSON::Object::Ptr LogDB::httpGetLogs( const Poco::URI::QueryParameters& pa ...@@ -846,9 +846,9 @@ Poco::JSON::Object::Ptr LogDB::httpGetLogs( const Poco::URI::QueryParameters& pa
else if( p.first == "limit" ) else if( p.first == "limit" )
limit = uni_atoi(p.second); limit = uni_atoi(p.second);
else if( p.first == "from" ) else if( p.first == "from" )
q_where.push_back("tms>='" + p.second + "'"); q_where.push_back("tms>=CAST(strftime('%s','" + qDate(p.second) + "') AS INT)");
else if( p.first == "to" ) else if( p.first == "to" ) // <-- нужно добавить + 1 день, что диапазон вошёл
q_where.push_back("tms<='" + p.second + "'"); q_where.push_back("tms<=CAST(strftime('%s','" + qDate(p.second) + "') AS INT) + 24*60*60");
else if( p.first == "last" ) else if( p.first == "last" )
q_where.push_back(qLast(p.second)); q_where.push_back(qLast(p.second));
} }
...@@ -894,14 +894,10 @@ Poco::JSON::Object::Ptr LogDB::httpGetCount( const Poco::URI::QueryParameters& p ...@@ -894,14 +894,10 @@ Poco::JSON::Object::Ptr LogDB::httpGetCount( const Poco::URI::QueryParameters& p
{ {
Poco::JSON::Object::Ptr jdata = new Poco::JSON::Object(); Poco::JSON::Object::Ptr jdata = new Poco::JSON::Object();
std::string logname = params[0].first; std::string logname;
if( logname.empty() ) if( !params.empty() )
{ logname = params[0].first;
ostringstream err;
err << "BAD REQUEST: unknown logname";
throw uniset::SystemError(err.str());
}
size_t count = getCountOfRecords(logname); size_t count = getCountOfRecords(logname);
jdata->set("name", logname); jdata->set("name", logname);
...@@ -949,6 +945,25 @@ string LogDB::qLast( const string& p ) ...@@ -949,6 +945,25 @@ string LogDB::qLast( const string& p )
return ""; return "";
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
string LogDB::qDate( const string& p, const char sep )
{
if( p.size() < 8 || p.size() > 10 )
return ""; // bad format
// преобразование в дату 'YYYY-MM-DD' из строки 'YYYYMMDD' или 'YYYY/MM/DD'
if( p.size() == 10 ) // <-- значит у нас длинная строка
{
std::string ret(p);
// независимо от того, правильная она или нет
// расставляем разделитель
ret[4] = sep;
ret[8] = sep;
return ret;
}
return p.substr(0, 4) + "-" + p.substr(4, 2) + "-" + p.substr(6, 2);
}
// -----------------------------------------------------------------------------
void LogDB::onWebSocketSession(Poco::Net::HTTPServerRequest& req, Poco::Net::HTTPServerResponse& resp) void LogDB::onWebSocketSession(Poco::Net::HTTPServerRequest& req, Poco::Net::HTTPServerResponse& resp)
{ {
using Poco::Net::WebSocket; using Poco::Net::WebSocket;
......
...@@ -192,6 +192,9 @@ namespace uniset ...@@ -192,6 +192,9 @@ namespace uniset
// XX m - минут, h-часов, d-дней, M - месяцев // XX m - минут, h-часов, d-дней, M - месяцев
static std::string qLast( const std::string& p ); static std::string qLast( const std::string& p );
// преобразование в дату 'YYYY-MM-DD' из строки 'YYYYMMDD' или 'YYYY/MM/DD'
static std::string qDate(const std::string& p , const char sep = '-');
std::shared_ptr<LogWebSocket> newWebSocket(Poco::Net::HTTPServerRequest* req, Poco::Net::HTTPServerResponse* resp, const std::string& logname ); std::shared_ptr<LogWebSocket> newWebSocket(Poco::Net::HTTPServerRequest* req, Poco::Net::HTTPServerResponse* resp, const std::string& logname );
void delWebSocket( std::shared_ptr<LogWebSocket>& ws ); void delWebSocket( std::shared_ptr<LogWebSocket>& ws );
#endif #endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment