61 lines
1.2 KiB
C
61 lines
1.2 KiB
C
|
|
#include <mach.h>
|
||
|
|
#include <sqlite.h>
|
||
|
|
#include <session_auth.h>
|
||
|
|
|
||
|
|
void mach(){
|
||
|
|
middleware(session());
|
||
|
|
|
||
|
|
resource("home", "/",
|
||
|
|
.get = {mustache("home")}
|
||
|
|
);
|
||
|
|
|
||
|
|
resource("about", "/about",
|
||
|
|
.get = {mustache("about")}
|
||
|
|
);
|
||
|
|
|
||
|
|
resource("contact", "/contact",
|
||
|
|
.get = {mustache("contact")}
|
||
|
|
);
|
||
|
|
|
||
|
|
resource("todos", "/todos",
|
||
|
|
.all = {logged_in()},
|
||
|
|
.get = {
|
||
|
|
sqlite_query({"todos_db", "get_todos", "todos_data"}),
|
||
|
|
mustache("todos")
|
||
|
|
},
|
||
|
|
.post = {
|
||
|
|
input({"title", m_not_empty}),
|
||
|
|
sqlite_query({"todos_db", "create_todo"}),
|
||
|
|
redirect("todos")
|
||
|
|
}
|
||
|
|
);
|
||
|
|
|
||
|
|
resource("todo", "/todos/:id",
|
||
|
|
.all = {
|
||
|
|
logged_in(),
|
||
|
|
input({"id", m_positive})
|
||
|
|
},
|
||
|
|
.patch = {
|
||
|
|
input({"finished", "1", "must be 1", .optional = true,}),
|
||
|
|
sqlite_query({"todos_db", "update_todo"}),
|
||
|
|
redirect("todos")
|
||
|
|
},
|
||
|
|
.delete = {
|
||
|
|
sqlite_query({"todos_db", "delete_todo"}),
|
||
|
|
redirect("todos")
|
||
|
|
}
|
||
|
|
);
|
||
|
|
|
||
|
|
sqlite_database(
|
||
|
|
.name ="todos_db",
|
||
|
|
.connect = "file:{{user_id}}_todo.db?mode=rwc",
|
||
|
|
.migrations = {"create_todos_table"}
|
||
|
|
);
|
||
|
|
|
||
|
|
error(m_error, {mustache("5xx")});
|
||
|
|
error(m_not_found, {mustache("404")});
|
||
|
|
|
||
|
|
sqlite();
|
||
|
|
session_auth();
|
||
|
|
}
|