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 | |
| parent | c889a9ad33374eae03cec5b0358d79016d6fd97e (diff) | |
| download | iosdc-japan-2025-albatross-32344d99c473b634c37f5d11e52ef389d46d4510.tar.gz iosdc-japan-2025-albatross-32344d99c473b634c37f5d11e52ef389d46d4510.tar.zst iosdc-japan-2025-albatross-32344d99c473b634c37f5d11e52ef389d46d4510.zip | |
game start button
| -rw-r--r-- | backend/admin/handler.go | 23 | ||||
| -rw-r--r-- | backend/admin/templates/game_edit.html | 5 |
2 files changed, 27 insertions, 1 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") +} 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 @@ </div> <div> <label>Started At</label> - <input type="datetime-local" name="started_at" value="{{ if .Game.StartedAt }}{{ .Game.StartedAt }}{{ end }}"> + <input type="datetime-local" name="started_at" value="{{ if .Game.StartedAt }}{{ .Game.StartedAt }}{{ end }}" readonly> </div> <div> <label>Problem ID</label> @@ -43,5 +43,8 @@ <div> <button type="submit">Save</button> </div> + <div> + <button type="submit" formaction="{{ .BasePath }}/admin/games/{{ .Game.GameID }}/start">Start</button> + </div> </form> {{ end }} |
