2020-12-01 17:01:59 +01:00
|
|
|
#include "message_page.h"
|
|
|
|
|
2022-02-05 15:57:40 +01:00
|
|
|
#include "database/database.h"
|
2020-12-01 18:29:41 +01:00
|
|
|
|
2022-02-05 15:57:40 +01:00
|
|
|
#include "database/query_builder.h"
|
|
|
|
#include "database/table_builder.h"
|
|
|
|
#include "database/query_result.h"
|
2022-02-10 16:17:31 +01:00
|
|
|
#include "web/http/web_permission.h"
|
2020-12-01 22:23:28 +01:00
|
|
|
|
2022-01-08 12:52:52 +01:00
|
|
|
void MessagePage::handle_request_main(Request *request) {
|
2022-02-10 16:17:31 +01:00
|
|
|
if (_web_permission.is_valid()) {
|
|
|
|
if (_web_permission->activate(request)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-01 16:57:22 +01:00
|
|
|
Ref<QueryBuilder> b = db->get_query_builder();
|
2020-12-01 22:23:28 +01:00
|
|
|
|
2021-08-19 14:12:02 +02:00
|
|
|
b->select("text")->from("message_page")->end_command();
|
2020-12-01 22:23:28 +01:00
|
|
|
|
2021-11-01 16:57:22 +01:00
|
|
|
Ref<QueryResult> res = db->query(b->query_result);
|
2020-12-01 22:23:28 +01:00
|
|
|
|
2021-11-01 19:53:35 +01:00
|
|
|
Vector<String> msgs;
|
2020-12-02 00:43:46 +01:00
|
|
|
|
2021-11-01 16:57:22 +01:00
|
|
|
while (res->next_row()) {
|
|
|
|
msgs.push_back(res->get_cell(0));
|
2020-12-02 00:43:46 +01:00
|
|
|
}
|
2020-12-01 22:24:23 +01:00
|
|
|
|
2021-11-01 19:53:35 +01:00
|
|
|
String r = "<html><body>";
|
2020-12-01 17:01:59 +01:00
|
|
|
|
2020-12-01 23:37:10 +01:00
|
|
|
for (uint32_t i = 0; i < messages.size(); ++i) {
|
|
|
|
r += "<p>" + messages[i] + "</p><br>";
|
|
|
|
}
|
2020-12-01 17:01:59 +01:00
|
|
|
|
2020-12-02 00:43:46 +01:00
|
|
|
for (uint32_t i = 0; i < msgs.size(); ++i) {
|
|
|
|
r += "<p>" + msgs[i] + "</p><br>";
|
|
|
|
}
|
|
|
|
|
2020-12-01 23:37:10 +01:00
|
|
|
r += "</html></body>";
|
2020-12-01 17:01:59 +01:00
|
|
|
|
2020-12-26 00:17:13 +01:00
|
|
|
request->body += r;
|
|
|
|
|
|
|
|
request->compile_and_send_body();
|
2020-12-01 17:01:59 +01:00
|
|
|
}
|
|
|
|
|
2022-01-13 23:45:38 +01:00
|
|
|
void MessagePage::_migrate(const bool clear, const bool seed_db) {
|
2021-11-01 16:57:22 +01:00
|
|
|
Ref<TableBuilder> t = db->get_table_builder();
|
2020-12-01 23:37:10 +01:00
|
|
|
|
2020-12-02 00:49:17 +01:00
|
|
|
t->drop_table("message_page");
|
|
|
|
db->query_run(t->result);
|
|
|
|
|
|
|
|
printf("%s\n", t->result.c_str());
|
|
|
|
|
|
|
|
t->result.clear();
|
|
|
|
|
2021-08-19 23:55:16 +02:00
|
|
|
t->create_table("message_page")->integer("id")->auto_increment()->primary_key()->next_row()->varchar("text", 30)->ccreate_table();
|
2020-12-02 00:43:46 +01:00
|
|
|
|
|
|
|
printf("%s\n", t->result.c_str());
|
2020-12-01 23:37:10 +01:00
|
|
|
|
|
|
|
db->query(t->result);
|
|
|
|
|
2021-11-01 16:57:22 +01:00
|
|
|
Ref<QueryBuilder> b = db->get_query_builder();
|
2020-12-02 00:43:46 +01:00
|
|
|
|
2021-08-19 14:12:02 +02:00
|
|
|
b->insert("message_page")->values("default, 'aaewdwd'");
|
2020-12-02 00:43:46 +01:00
|
|
|
|
|
|
|
printf("%s\n", b->query_result.c_str());
|
|
|
|
|
|
|
|
db->query_run(b->query_result);
|
|
|
|
|
|
|
|
b->query_result.clear();
|
2021-08-19 14:12:02 +02:00
|
|
|
b->insert("message_page")->values("default, 'qqqqq'");
|
2020-12-02 00:43:46 +01:00
|
|
|
|
|
|
|
printf("%s\n", b->query_result.c_str());
|
|
|
|
|
|
|
|
db->query_run(b->query_result);
|
2020-12-01 17:01:59 +01:00
|
|
|
}
|
|
|
|
|
2020-12-01 23:37:10 +01:00
|
|
|
MessagePage::MessagePage() :
|
2022-01-08 12:52:52 +01:00
|
|
|
WebNode() {
|
2020-12-01 23:37:10 +01:00
|
|
|
messages.push_back("T message 1");
|
|
|
|
messages.push_back("T message 2");
|
|
|
|
}
|
2020-12-01 17:01:59 +01:00
|
|
|
|
2020-12-01 23:37:10 +01:00
|
|
|
MessagePage::~MessagePage() {
|
2020-12-01 17:01:59 +01:00
|
|
|
}
|