diff options
| author | nsfisis <nsfisis@gmail.com> | 2025-03-08 10:45:23 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2025-03-08 10:45:23 +0900 |
| commit | 32344d99c473b634c37f5d11e52ef389d46d4510 (patch) | |
| tree | 6c36ad60bc7ff6e18493f7045cb23bb18153fec7 /backend/admin/handler.go | |
| parent | c889a9ad33374eae03cec5b0358d79016d6fd97e (diff) | |
| download | phperkaigi-2025-albatross-32344d99c473b634c37f5d11e52ef389d46d4510.tar.gz phperkaigi-2025-albatross-32344d99c473b634c37f5d11e52ef389d46d4510.tar.zst phperkaigi-2025-albatross-32344d99c473b634c37f5d11e52ef389d46d4510.zip | |
game start button
Diffstat (limited to 'backend/admin/handler.go')
| -rw-r--r-- | backend/admin/handler.go | 23 |
1 files changed, 23 insertions, 0 deletions
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") +} |
