Older/WebApplication/Restful.cpp
amass 03c7a564a1
All checks were successful
Deploy / Build (push) Successful in 6m56s
add app path config.
2024-12-01 20:01:13 +08:00

42 lines
1.2 KiB
C++

#include "Restful.h"
#include "Database/Session.h"
#include <Wt/Dbo/Impl.h>
#include <Wt/Dbo/Json.h>
#include <Wt/Dbo/backend/Sqlite3.h>
#include <Wt/Http/Response.h>
DBO_INSTANTIATE_TEMPLATES(MyMessage)
DbStruct *m_dbStruct;
void AuthenticationResource::handleRequest(const Wt::Http::Request &request, Wt::Http::Response &response) {
auto session = Database::session();
response.setMimeType("application/json");
response.addHeader("Server", "Wt");
MyMessage message;
message.message = "Hello, World!";
Wt::Dbo::JsonSerializer writer(response.out());
writer.serialize(message);
}
void PlaintextResource::handleRequest(const Wt::Http::Request &request, Wt::Http::Response &response) {
response.setMimeType("text/plain");
response.addHeader("Server", "Wt");
response.out() << "Hello, World!";
}
int DbStruct::rand() {
return distribution(rng);
}
AuthenticationResource::AuthenticationResource() {
}
DbStruct::DbStruct(const std::string &db) : rng(clock()), distribution(1, 10000) {
session.setConnection(std::make_unique<Wt::Dbo::backend::Sqlite3>(db));
session.mapClass<World>("world");
session.mapClass<Fortune>("fortune");
}