MaCH repo
This commit is contained in:
44
07_roundest_pokemon_htmx/main.c
Normal file
44
07_roundest_pokemon_htmx/main.c
Normal file
@@ -0,0 +1,44 @@
|
||||
#include <mach.h>
|
||||
#include <htmx.h>
|
||||
#include <sqlite.h>
|
||||
#include <tailwind.h>
|
||||
|
||||
void mach(){
|
||||
htmx_config();
|
||||
tailwind_config();
|
||||
|
||||
sqlite_database(
|
||||
.name = "pokemon_db",
|
||||
.connect = "file::memory:?cache=shared",
|
||||
.migrations = {"create_pokemons_table.sql"}
|
||||
);
|
||||
|
||||
resource("home", "/",
|
||||
.get = {
|
||||
sqlite_query({"pokemon_db", "get_challengers", "challengers"}),
|
||||
exec(^(){
|
||||
auto const t = get("challengers");
|
||||
auto const p0 = table_get(t, 0);
|
||||
auto const p1 = table_get(t, 1);
|
||||
record_set(p0, "opponent_id", record_get(p1, "id"));
|
||||
record_set(p1, "opponent_id", record_get(p0, "id"));
|
||||
}),
|
||||
mustache("home")
|
||||
},
|
||||
.post = {
|
||||
input(
|
||||
{"winner", m_positive},
|
||||
{"loser", m_positive}
|
||||
),
|
||||
sqlite_query({"pokemon_db", "vote"}),
|
||||
reroute("home")
|
||||
}
|
||||
);
|
||||
|
||||
resource("result", "/results",
|
||||
.get = {
|
||||
sqlite_query({"pokemon_db", "get_results", "results"}),
|
||||
mustache("results")
|
||||
}
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user