aboutsummaryrefslogtreecommitdiffhomepage
path: root/backend/admin/handler.go
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2025-03-04 22:55:01 +0900
committernsfisis <nsfisis@gmail.com>2025-03-08 10:12:44 +0900
commit1e6df136d8202c8adf65948527f4c3e7583b338c (patch)
tree7c82476f6bbbc71d72ab7e71e39559eca197fd95 /backend/admin/handler.go
parent54316868c3bec1ff9b04643dfe6c13cf56bf3246 (diff)
downloadphperkaigi-2025-albatross-1e6df136d8202c8adf65948527f4c3e7583b338c.tar.gz
phperkaigi-2025-albatross-1e6df136d8202c8adf65948527f4c3e7583b338c.tar.zst
phperkaigi-2025-albatross-1e6df136d8202c8adf65948527f4c3e7583b338c.zip
websocket to polling
Diffstat (limited to 'backend/admin/handler.go')
-rw-r--r--backend/admin/handler.go46
1 files changed, 14 insertions, 32 deletions
diff --git a/backend/admin/handler.go b/backend/admin/handler.go
index ca70639..9123ba0 100644
--- a/backend/admin/handler.go
+++ b/backend/admin/handler.go
@@ -24,18 +24,17 @@ const (
var jst = time.FixedZone("Asia/Tokyo", 9*60*60)
type Handler struct {
- q *db.Queries
- hubs GameHubsInterface
+ q *db.Queries
+ hub GameHubInterface
}
-type GameHubsInterface interface {
- StartGame(gameID int) error
-}
+// TODO
+type GameHubInterface any
-func NewHandler(q *db.Queries, hubs GameHubsInterface) *Handler {
+func NewHandler(q *db.Queries, hub GameHubInterface) *Handler {
return &Handler{
- q: q,
- hubs: hubs,
+ q: q,
+ hub: hub,
}
}
@@ -150,20 +149,20 @@ func (h *Handler) postUserFetchIcon(c echo.Context) error {
}
func (h *Handler) getGames(c echo.Context) error {
- rows, err := h.q.ListGames(c.Request().Context())
+ rows, err := h.q.ListAllGames(c.Request().Context())
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, err.Error())
}
games := make([]echo.Map, len(rows))
for i, g := range rows {
var startedAt string
- if !g.StartedAt.Valid {
+ if g.StartedAt.Valid {
startedAt = g.StartedAt.Time.In(jst).Format("2006-01-02T15:04")
}
games[i] = echo.Map{
"GameID": g.GameID,
"GameType": g.GameType,
- "State": g.State,
+ "IsPublic": g.IsPublic,
"DisplayName": g.DisplayName,
"DurationSeconds": g.DurationSeconds,
"StartedAt": startedAt,
@@ -192,7 +191,7 @@ func (h *Handler) getGameEdit(c echo.Context) error {
}
var startedAt string
- if !row.StartedAt.Valid {
+ if row.StartedAt.Valid {
startedAt = row.StartedAt.Time.In(jst).Format("2006-01-02T15:04")
}
@@ -202,7 +201,7 @@ func (h *Handler) getGameEdit(c echo.Context) error {
"Game": echo.Map{
"GameID": row.GameID,
"GameType": row.GameType,
- "State": row.State,
+ "IsPublic": row.IsPublic,
"DisplayName": row.DisplayName,
"DurationSeconds": row.DurationSeconds,
"StartedAt": startedAt,
@@ -216,16 +215,9 @@ func (h *Handler) postGameEdit(c echo.Context) error {
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, "Invalid game id")
}
- row, err := h.q.GetGameByID(c.Request().Context(), int32(gameID))
- if err != nil {
- if errors.Is(err, pgx.ErrNoRows) {
- return echo.NewHTTPError(http.StatusNotFound)
- }
- return echo.NewHTTPError(http.StatusInternalServerError, err.Error())
- }
gameType := c.FormValue("game_type")
- state := c.FormValue("state")
+ isPublic := c.FormValue("is_public") == "public"
displayName := c.FormValue("display_name")
durationSeconds, err := strconv.Atoi(c.FormValue("duration_seconds"))
if err != nil {
@@ -267,7 +259,7 @@ func (h *Handler) postGameEdit(c echo.Context) error {
err = h.q.UpdateGame(c.Request().Context(), db.UpdateGameParams{
GameID: int32(gameID),
GameType: gameType,
- State: state,
+ IsPublic: isPublic,
DisplayName: displayName,
DurationSeconds: int32(durationSeconds),
StartedAt: changedStartedAt,
@@ -277,15 +269,5 @@ func (h *Handler) postGameEdit(c echo.Context) error {
return echo.NewHTTPError(http.StatusInternalServerError, err.Error())
}
- {
- // TODO:
- if state != row.State && state == "starting" {
- err := h.hubs.StartGame(int(gameID))
- if err != nil {
- return echo.NewHTTPError(http.StatusInternalServerError, err.Error())
- }
- }
- }
-
return c.Redirect(http.StatusSeeOther, basePath+"/admin/games")
}