From 7125bc2d2a834b3b666f7e2e3695408a25ed08e1 Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Sat, 2 Aug 2025 13:56:39 -0400 Subject: [PATCH 1/2] All the pages are working again, but Alpine is insanely frustrating. --- Makefile | 2 +- admin/handlers.go | 18 +++++++--------- api/handlers.go | 21 ++++++++++++++++++- data/models.go | 8 +++++++ .../20250802154952_create_game_table.sql | 10 +++++++++ pages/game/index.html | 12 ++++++----- pages/stream/index.html | 5 ++--- static/js/code.js | 8 +++++-- tests/admin_ui_tests.go | 15 +++++++++++++ views/admin/table/contents.html | 2 +- views/admin/table/index.html | 2 +- views/admin/table/new.html | 4 ++-- views/admin/table/view.html | 2 +- views/game.html | 12 ++++++----- views/stream.html | 14 ++++++------- 15 files changed, 95 insertions(+), 40 deletions(-) create mode 100644 migrations/20250802154952_create_game_table.sql create mode 100644 tests/admin_ui_tests.go diff --git a/Makefile b/Makefile index e47f84f..79d3c83 100644 --- a/Makefile +++ b/Makefile @@ -17,7 +17,7 @@ test: site test_only: go test zedshaw.games/webapp/tests -c -o runtests$(GO_IS_STUPID_EXE) - ./runtests$(GO_IS_STUPID_EXE) -test.run TestAdminIndexPage + ./runtests$(GO_IS_STUPID_EXE) -test.run TestGamePage migrate_up: go tool goose sqlite3 db.sqlite3 -dir migrations up diff --git a/admin/handlers.go b/admin/handlers.go index cb73f67..fb88d57 100644 --- a/admin/handlers.go +++ b/admin/handlers.go @@ -159,19 +159,15 @@ func GetPageAdminIndex(c *fiber.Ctx) error { func Setup(app *fiber.App) { app.Get("/admin/table/", GetPageAdminIndex) - app.Get("/api/admin/table/", GetApiTableIndex) - - app.Get("/api/admin/table/:table/", GetApiSelectAll) app.Get("/admin/table/:table/", GetPageSelectAll) - app.Get("/admin/new/table/:table/", GetPageInsert) - app.Get("/api/admin/new/table/:table/", GetApiInsert) - app.Post("/api/admin/new/table/:table/", PostApiInsert) - - app.Get("/api/admin/table/:table/:id/", GetApiSelectOne) app.Get("/admin/table/:table/:id/", GetPageSelectOne) - app.Post("/api/admin/table/:table/:id/", PostApiUpdate) - - app.Delete("/api/admin/table/:table/:id/", DeleteApi) + app.Get("/api/admin/table", GetApiTableIndex) + app.Get("/api/admin/table/:table", GetApiSelectAll) + app.Get("/api/admin/new/table/:table", GetApiInsert) + app.Post("/api/admin/new/table/:table", PostApiInsert) + app.Get("/api/admin/table/:table/:id", GetApiSelectOne) + app.Post("/api/admin/table/:table/:id", PostApiUpdate) + app.Delete("/api/admin/table/:table/:id", DeleteApi) } diff --git a/api/handlers.go b/api/handlers.go index 2bb2ad1..c23341d 100644 --- a/api/handlers.go +++ b/api/handlers.go @@ -110,6 +110,21 @@ func PostApiLink(c *fiber.Ctx) error { return c.Redirect("/live/") } +func GetApiGame(c *fiber.Ctx) error { + sql, args, err := sq.Select("*").From("game").ToSql() + err = data.SelectJson[data.Game](c, err, sql, args...) + + return IfErrNil(err, c) +} + +func GetApiGameId(c *fiber.Ctx) error { + sql, args, err := sq.Select("*"). + From("game").Where(sq.Eq{"id": c.Params("id")}).ToSql() + + err = data.GetJson[data.Game](c, err, sql, args...) + return IfErrNil(err, c) +} + func Setup(app *fiber.App) { STORE = session.New() @@ -120,7 +135,11 @@ func Setup(app *fiber.App) { }) app.Get("/stream/:id/", Page("stream")) - app.Get("/game/:id/:name/", Page("game")) + app.Get("/game/:id/:slug/", Page("game")) + + app.Get("/api/game", GetApiGame) + app.Get("/api/game/:id", GetApiGameId) + app.Get("/api/stream", GetApiStream) app.Get("/api/logout", GetApiLogout) app.Get("/api/stream/:id", GetApiStreamId) diff --git a/data/models.go b/data/models.go index 5c63c88..00829fc 100644 --- a/data/models.go +++ b/data/models.go @@ -27,10 +27,18 @@ type Stream struct { Description string `db:"description" json:"description"` } +type Game struct { + Id int `db:"id" json:"id"` + Slug string `db:"slug" json:"slug"` + Title string `db:"title" json:"title"` + Description string `db:"description" json:"description"` +} + func Models() map[string]reflect.Type { return map[string]reflect.Type{ "stream": reflect.TypeFor[Stream](), "stream_link": reflect.TypeFor[Link](), "user": reflect.TypeFor[User](), + "game": reflect.TypeFor[Game](), } } diff --git a/migrations/20250802154952_create_game_table.sql b/migrations/20250802154952_create_game_table.sql new file mode 100644 index 0000000..67c2063 --- /dev/null +++ b/migrations/20250802154952_create_game_table.sql @@ -0,0 +1,10 @@ +-- +goose Up +-- +goose StatementBegin +CREATE TABLE game (id INTEGER PRIMARY KEY, + slug TEXT, title TEXT, description TEXT); +-- +goose StatementEnd + +-- +goose Down +-- +goose StatementBegin +DROP TABLE game; +-- +goose StatementEnd diff --git a/pages/game/index.html b/pages/game/index.html index 85ae9b0..56a2fbb 100644 --- a/pages/game/index.html +++ b/pages/game/index.html @@ -1,5 +1,5 @@ @@ -11,14 +11,16 @@
-