This commit is contained in:
parent
059d6d3879
commit
1df434efba
@ -1,11 +1,13 @@
|
||||
#include "Session.h"
|
||||
#include <Wt/Auth/Dbo/UserDatabase.h>
|
||||
#include <Wt/Dbo/WtJsonSqlTraits.h>
|
||||
|
||||
Session::Session(Wt::Dbo::SqlConnectionPool &connectionPool) {
|
||||
setConnectionPool(connectionPool);
|
||||
|
||||
mapClass<Task>("task");
|
||||
mapClass<HomeBox::Item>("homebox_item");
|
||||
mapClass<VisitorRecord>("visitor_record");
|
||||
|
||||
mapClass<User>("user");
|
||||
mapClass<AuthInfo>("auth_info");
|
||||
@ -34,6 +36,18 @@ Wt::Auth::Login &Session::login() {
|
||||
return m_login;
|
||||
}
|
||||
|
||||
namespace Wt {
|
||||
namespace Dbo {
|
||||
template <>
|
||||
void JsonSerializer::act(FieldRef<std::chrono::system_clock::time_point> field) {
|
||||
using namespace std::chrono;
|
||||
writeFieldName(field.name());
|
||||
fastJsStringLiteral(std::to_string(duration_cast<seconds>(field.value().time_since_epoch()).count()));
|
||||
}
|
||||
} // namespace Dbo
|
||||
} // namespace Wt
|
||||
|
||||
DBO_INSTANTIATE_TEMPLATES(User)
|
||||
DBO_INSTANTIATE_TEMPLATES(Task)
|
||||
DBO_INSTANTIATE_TEMPLATES(HomeBox::Item)
|
||||
DBO_INSTANTIATE_TEMPLATES(HomeBox::Item)
|
||||
DBO_INSTANTIATE_TEMPLATES(VisitorRecord)
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include "User.h"
|
||||
#include <Wt/Auth/Login.h>
|
||||
#include <Wt/Dbo/Session.h>
|
||||
#include "VisitorRecord.h"
|
||||
|
||||
using UserDatabase = Wt::Auth::Dbo::UserDatabase<AuthInfo>;
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
#define __TASK_H__
|
||||
|
||||
#include <Wt/Dbo/Dbo.h>
|
||||
#include <Wt/Dbo/StdSqlTraits.h>
|
||||
#include <string>
|
||||
|
||||
class Task;
|
||||
@ -10,7 +11,7 @@ using Tasks = Wt::Dbo::collection<Wt::Dbo::ptr<Task>>;
|
||||
class Task {
|
||||
public:
|
||||
bool finished = false;
|
||||
int32_t createTime = 0;
|
||||
std::chrono::system_clock::time_point createTime;
|
||||
std::string content;
|
||||
std::string comment;
|
||||
|
||||
@ -29,5 +30,4 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif // __TASK_H__
|
22
Database/VisitorRecord.h
Normal file
22
Database/VisitorRecord.h
Normal file
@ -0,0 +1,22 @@
|
||||
#ifndef __VISITORRECORD_H__
|
||||
#define __VISITORRECORD_H__
|
||||
|
||||
#include <Wt/Dbo/Dbo.h>
|
||||
|
||||
class VisitorRecord {
|
||||
public:
|
||||
std::string url;
|
||||
std::string userAgent;
|
||||
std::string visitorUuid;
|
||||
std::chrono::system_clock::time_point time;
|
||||
|
||||
template <class Action>
|
||||
void persist(Action &a) {
|
||||
Wt::Dbo::field(a, url, "url");
|
||||
Wt::Dbo::field(a, userAgent, "user_agent");
|
||||
Wt::Dbo::field(a, visitorUuid, "visitor_uuid");
|
||||
Wt::Dbo::field(a, time, "time");
|
||||
}
|
||||
};
|
||||
|
||||
#endif // __VISITORRECORD_H__
|
@ -78,6 +78,7 @@ Application::Application(const std::string &path)
|
||||
|
||||
m_router->insert("/api/v1/task/add", [this](HttpSession &session, const Request &request, const boost::urls::matches &matches) mutable {
|
||||
using namespace boost::beast;
|
||||
using namespace std::chrono;
|
||||
LOG(info) << "add task: " << request.body();
|
||||
auto rootJson = boost::json::parse(request.body());
|
||||
auto &root = rootJson.as_object();
|
||||
@ -88,7 +89,7 @@ Application::Application(const std::string &path)
|
||||
}
|
||||
auto database = Amass::Singleton<Database>::instance()->session();
|
||||
auto task = std::make_unique<Task>();
|
||||
task->createTime = root.at("createTime").as_int64();
|
||||
task->createTime = system_clock::time_point(seconds(root.at("createTime").as_int64()));
|
||||
task->content = content;
|
||||
task->comment = std::string(root.at("comment").as_string());
|
||||
auto t = database->add(std::move(task));
|
||||
|
Loading…
Reference in New Issue
Block a user