aboutsummaryrefslogtreecommitdiffhomepage
path: root/backend
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2024-08-05 02:33:54 +0900
committernsfisis <nsfisis@gmail.com>2024-08-05 03:02:18 +0900
commit968b835d0e6fe960c3d7ab915ef6d9cecec4ab7f (patch)
treeee5c3cd7e3817866439f71eccb085e8394a0a1a5 /backend
parent5988360d8cf0fc0028c6db1c82afc1e313ba0513 (diff)
downloadiosdc-japan-2025-albatross-968b835d0e6fe960c3d7ab915ef6d9cecec4ab7f.tar.gz
iosdc-japan-2025-albatross-968b835d0e6fe960c3d7ab915ef6d9cecec4ab7f.tar.zst
iosdc-japan-2025-albatross-968b835d0e6fe960c3d7ab915ef6d9cecec4ab7f.zip
feat(backend): allow to edit `game_type` in admin page
Diffstat (limited to 'backend')
-rw-r--r--backend/admin/handlers.go4
-rw-r--r--backend/admin/templates/game_edit.html13
-rw-r--r--backend/admin/templates/games.html2
-rw-r--r--backend/db/query.sql.go13
-rw-r--r--backend/query.sql11
5 files changed, 29 insertions, 14 deletions
diff --git a/backend/admin/handlers.go b/backend/admin/handlers.go
index 14523e6..d9a6977 100644
--- a/backend/admin/handlers.go
+++ b/backend/admin/handlers.go
@@ -130,6 +130,7 @@ func (h *AdminHandler) getGames(c echo.Context) error {
}
games[i] = echo.Map{
"GameID": g.GameID,
+ "GameType": g.GameType,
"State": g.State,
"DisplayName": g.DisplayName,
"DurationSeconds": g.DurationSeconds,
@@ -167,6 +168,7 @@ func (h *AdminHandler) getGameEdit(c echo.Context) error {
"Title": "Game Edit",
"Game": echo.Map{
"GameID": row.GameID,
+ "GameType": row.GameType,
"State": row.State,
"DisplayName": row.DisplayName,
"DurationSeconds": row.DurationSeconds,
@@ -190,6 +192,7 @@ func (h *AdminHandler) postGameEdit(c echo.Context) error {
}
}
+ gameType := c.FormValue("game_type")
state := c.FormValue("state")
displayName := c.FormValue("display_name")
durationSeconds, err := strconv.Atoi(c.FormValue("duration_seconds"))
@@ -247,6 +250,7 @@ func (h *AdminHandler) postGameEdit(c echo.Context) error {
err = h.q.UpdateGame(c.Request().Context(), db.UpdateGameParams{
GameID: int32(gameID),
+ GameType: gameType,
State: state,
DisplayName: displayName,
DurationSeconds: int32(durationSeconds),
diff --git a/backend/admin/templates/game_edit.html b/backend/admin/templates/game_edit.html
index 8bc5410..764b577 100644
--- a/backend/admin/templates/game_edit.html
+++ b/backend/admin/templates/game_edit.html
@@ -15,11 +15,18 @@
<input type="text" name="display_name" value="{{ .Game.DisplayName }}" required>
</div>
<div>
+ <label>Game Type</label>
+ <select name="game_type" required>
+ <option value="1v1"{{ if eq .Game.GameType "1v1" }} selected{{ end }}>1v1</option>
+ <option value="multiplayer"{{ if eq .Game.GameType "multiplayer" }} selected{{ end }}>Multiplayer</option>
+ </select>
+ </div>
+ <div>
<label>State</label>
- <select>
+ <select name="state" required>
<option value="closed"{{ if eq .Game.State "closed" }} selected{{ end }}>Closed</option>
- <option value="waiting_entries"{{ if eq .Game.State "waiting_entries" }} selected{{ end }}>WaitingEntries</option>
- <option value="waiting_start"{{ if eq .Game.State "waiting_start" }} selected{{ end }}>WaitingStart</option>
+ <option value="waiting_entries"{{ if eq .Game.State "waiting_entries" }} selected{{ end }}>Waiting Entries</option>
+ <option value="waiting_start"{{ if eq .Game.State "waiting_start" }} selected{{ end }}>Waiting Start</option>
<option value="prepare"{{ if eq .Game.State "prepare" }} selected{{ end }}>Prepare</option>
<option value="starting"{{ if eq .Game.State "starting" }} selected{{ end }}>Starting</option>
<option value="gaming"{{ if eq .Game.State "gaming" }} selected{{ end }}>Gaming</option>
diff --git a/backend/admin/templates/games.html b/backend/admin/templates/games.html
index 244fc94..47dc4a3 100644
--- a/backend/admin/templates/games.html
+++ b/backend/admin/templates/games.html
@@ -9,7 +9,7 @@
{{ range .Games }}
<li>
<a href="/admin/games/{{ .GameID }}">
- {{ .DisplayName }} (id={{ .GameID }})
+ {{ .DisplayName }} (id={{ .GameID }} type={{ .GameType }} state={{ .State }})
</a>
</li>
{{ end }}
diff --git a/backend/db/query.sql.go b/backend/db/query.sql.go
index 464d7f8..c574ca8 100644
--- a/backend/db/query.sql.go
+++ b/backend/db/query.sql.go
@@ -251,16 +251,18 @@ func (q *Queries) ListUsers(ctx context.Context) ([]User, error) {
const updateGame = `-- name: UpdateGame :exec
UPDATE games
SET
- state = $2,
- display_name = $3,
- duration_seconds = $4,
- started_at = $5,
- problem_id = $6
+ game_type = $2,
+ state = $3,
+ display_name = $4,
+ duration_seconds = $5,
+ started_at = $6,
+ problem_id = $7
WHERE game_id = $1
`
type UpdateGameParams struct {
GameID int32
+ GameType string
State string
DisplayName string
DurationSeconds int32
@@ -271,6 +273,7 @@ type UpdateGameParams struct {
func (q *Queries) UpdateGame(ctx context.Context, arg UpdateGameParams) error {
_, err := q.db.Exec(ctx, updateGame,
arg.GameID,
+ arg.GameType,
arg.State,
arg.DisplayName,
arg.DurationSeconds,
diff --git a/backend/query.sql b/backend/query.sql
index 886f96c..39b0b21 100644
--- a/backend/query.sql
+++ b/backend/query.sql
@@ -41,9 +41,10 @@ LIMIT 1;
-- name: UpdateGame :exec
UPDATE games
SET
- state = $2,
- display_name = $3,
- duration_seconds = $4,
- started_at = $5,
- problem_id = $6
+ game_type = $2,
+ state = $3,
+ display_name = $4,
+ duration_seconds = $5,
+ started_at = $6,
+ problem_id = $7
WHERE game_id = $1;