From 32344d99c473b634c37f5d11e52ef389d46d4510 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sat, 8 Mar 2025 10:45:23 +0900 Subject: game start button --- backend/admin/handler.go | 23 +++++++++++++++++++++++ backend/admin/templates/game_edit.html | 5 ++++- 2 files changed, 27 insertions(+), 1 deletion(-) (limited to 'backend') diff --git a/backend/admin/handler.go b/backend/admin/handler.go index 9123ba0..3e185ea 100644 --- a/backend/admin/handler.go +++ b/backend/admin/handler.go @@ -68,6 +68,7 @@ func (h *Handler) RegisterHandlers(g *echo.Group) { g.GET("/games", h.getGames) g.GET("/games/:gameID", h.getGameEdit) g.POST("/games/:gameID", h.postGameEdit) + g.POST("/games/:gameID/start", h.postGameStart) } func (h *Handler) getDashboard(c echo.Context) error { @@ -271,3 +272,25 @@ func (h *Handler) postGameEdit(c echo.Context) error { return c.Redirect(http.StatusSeeOther, basePath+"/admin/games") } + +func (h *Handler) postGameStart(c echo.Context) error { + gameID, err := strconv.Atoi(c.Param("gameID")) + if err != nil { + return echo.NewHTTPError(http.StatusBadRequest, "Invalid game id") + } + + startedAt := time.Now().Add(11 * time.Second) + + err = h.q.UpdateGameStartedAt(c.Request().Context(), db.UpdateGameStartedAtParams{ + GameID: int32(gameID), + StartedAt: pgtype.Timestamp{ + Time: startedAt, + Valid: true, + }, + }) + if err != nil { + return echo.NewHTTPError(http.StatusInternalServerError, err.Error()) + } + + return c.Redirect(http.StatusSeeOther, basePath+"/admin/games") +} diff --git a/backend/admin/templates/game_edit.html b/backend/admin/templates/game_edit.html index 2c80558..3b9d9de 100644 --- a/backend/admin/templates/game_edit.html +++ b/backend/admin/templates/game_edit.html @@ -34,7 +34,7 @@
- +
@@ -43,5 +43,8 @@
+
+ +
{{ end }} -- cgit v1.2.3-70-g09d2