diff options
Diffstat (limited to 'backend')
| -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 }} |
