diff options
| author | nsfisis <nsfisis@gmail.com> | 2024-08-11 20:44:02 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2024-08-11 20:44:02 +0900 |
| commit | dbbbf887c8a2a7b196c9706c2a0ef2f443a5d918 (patch) | |
| tree | 661baf5282aac6b6bf022820c3cc4c1a51ea1062 /backend/api | |
| parent | 125e26b4d5c986f8531c098ecd5d291c1e1c7a76 (diff) | |
| download | phperkaigi-2025-albatross-dbbbf887c8a2a7b196c9706c2a0ef2f443a5d918.tar.gz phperkaigi-2025-albatross-dbbbf887c8a2a7b196c9706c2a0ef2f443a5d918.tar.zst phperkaigi-2025-albatross-dbbbf887c8a2a7b196c9706c2a0ef2f443a5d918.zip | |
feat(backend): always include `problem` property in `Game` object in APIs
Diffstat (limited to 'backend/api')
| -rw-r--r-- | backend/api/generated.go | 42 | ||||
| -rw-r--r-- | backend/api/handler.go | 38 |
2 files changed, 38 insertions, 42 deletions
diff --git a/backend/api/generated.go b/backend/api/generated.go index f7fd7e4..d93953f 100644 --- a/backend/api/generated.go +++ b/backend/api/generated.go @@ -81,7 +81,7 @@ type Game struct { GameID int `json:"game_id"` GameType GameGameType `json:"game_type"` Players []User `json:"players"` - Problem *Problem `json:"problem,omitempty"` + Problem Problem `json:"problem"` StartedAt *int `json:"started_at,omitempty"` State GameState `json:"state"` VerificationSteps []VerificationStep `json:"verification_steps"` @@ -1218,26 +1218,26 @@ var swaggerSpec = []string{ "xTnX0ZoKiBiNhSN39nwYNogfospm2i493bnQfP2AgOap8uv0TgFJ80QShRa48rCEah43cJqlGh6RkIq2", "dH4UBoJVhDnHa62Hs1kCaZv4tV2m0i0xlxBPsXQc/uX8+fMX5y+G3ggJiaXjdJQwAeqAWWEiCV1MgUqu", "0lZ+o+0ghRAyzAFZy8p/HUnzx5xQIpYQu0Hbqm/E7Q44mdsdMRUSsu4h/KsiOpGQNcNZY2x5jJaJ38Qi", - "dNnpIV6ZYy/qXdvgWgv9Ue44RuHPORp/2u9c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bs9+WJn1ekP01jbvBdFjB7O5O3b4faJ+Sm3lwv2Nzz4W9JekTi1CNVU99wgdADXrRNfQ728L", + "nApf7Q14TtWHbSvQ0it0aw4Ulhg4d/m2Y53C4axzCOkTkiBkhIXvB7O25mkPQataw0pDYxBuXeqc3EeW", + "XL++jsTtr+juh/E/V92y1PQY5rb7qBPn/i6kLUAeczBkHBKSEor5errj0nHAPmlqO9Cl3s/1qtqDEveU", + "Z7sP1Ldxuu/hhgXpC9J1eeGppb06GqrWgQ9LIgIiAhyUv2I3WxPzqFMIJZFJrQeyqHyDHP+Ny9YKrckd", + "a/mc1iOTA4ZKv7MlDX5l4POURIxO9ZDVERmQFC9ADG7Zkp7cZguvqJjiOCVufOc4EWWFnDGWANYjyFx4", + "KDk680VULW16oaC0xnNjpaKkMdDY4vbFtjFLacQ5wTNIapwCIQNV5f2ju/46C7ebMEiaXigpQudM/4xr", + "2IkukhmWnAkRbHZrsIJZcHH9xsxuhJmhDk9OT4YKM8uA4oygMTo7GZ4MkRnP6wAMFjg1oViAPnBVdHTA", + "3sRojK5AXukFofMiwY5rZrlk4H3RoLipTe9Hw+FBo2Q3eVvonQZrenrbZZgmdmTBHVC/JUIGbB4YiSJE", + "58PTXRC2Pg/csbYSOmsXqkz/1Smfpynm6w0Ea78IbSoHD3YgWLQltaechq1yzrsgT8CBbpn3ZLpToi90", + "iL9YhpXEebvE9iUQlxJXIANsAStKJGxhzvSMCQ8TrpmQb/USExwQ8iUzA6Qj85FhIVaMx7XfEey3p6Mz", + "35nKYUGEtJNpyf6BWpm/r/3z6XhknaGbDWHh+5nhvqhU9MrkXX6fVP5v70O1ki60npjebZ4nyTpQlAUq", + "FdQNaw+musND1dUEhnyah1vndh1IH/SCr7HKfFN5MeeDWDIuf07IHcQB1uYCA7AoiuK/AAAA//8G1YBf", + "QSgAAA==", } // GetSwagger returns the content of the embedded swagger specification file diff --git a/backend/api/handler.go b/backend/api/handler.go index e70f298..4150ba6 100644 --- a/backend/api/handler.go +++ b/backend/api/handler.go @@ -89,11 +89,6 @@ func (h *Handler) GetGames(ctx context.Context, _ GetGamesRequestObject, user *a startedAtTimestamp := int(row.StartedAt.Time.Unix()) startedAt = &startedAtTimestamp } - problem := &Problem{ - ProblemID: int(row.ProblemID), - Title: row.Title, - Description: row.Description, - } games[i] = Game{ GameID: int(row.GameID), GameType: GameGameType(row.GameType), @@ -101,7 +96,11 @@ func (h *Handler) GetGames(ctx context.Context, _ GetGamesRequestObject, user *a DisplayName: row.DisplayName, DurationSeconds: int(row.DurationSeconds), StartedAt: startedAt, - Problem: problem, + Problem: Problem{ + ProblemID: int(row.ProblemID), + Title: row.Title, + Description: row.Description, + }, } } return GetGames200JSONResponse{ @@ -111,6 +110,7 @@ func (h *Handler) GetGames(ctx context.Context, _ GetGamesRequestObject, user *a func (h *Handler) GetGame(ctx context.Context, request GetGameRequestObject, user *auth.JWTClaims) (GetGameResponseObject, error) { // TODO: check user permission + _ = user gameID := request.GameID row, err := h.q.GetGameByID(ctx, int32(gameID)) if err != nil { @@ -128,14 +128,6 @@ func (h *Handler) GetGame(ctx context.Context, request GetGameRequestObject, use startedAtTimestamp := int(row.StartedAt.Time.Unix()) startedAt = &startedAtTimestamp } - var problem *Problem - if user.IsAdmin || (GameState(row.State) != Closed && GameState(row.State) != WaitingEntries) { - problem = &Problem{ - ProblemID: int(row.ProblemID), - Title: row.Title, - Description: row.Description, - } - } playerRows, err := h.q.ListGamePlayers(ctx, int32(gameID)) if err != nil { return nil, echo.NewHTTPError(http.StatusInternalServerError, err.Error()) @@ -165,13 +157,17 @@ func (h *Handler) GetGame(ctx context.Context, request GetGameRequestObject, use } } game := Game{ - GameID: int(row.GameID), - GameType: GameGameType(row.GameType), - State: GameState(row.State), - DisplayName: row.DisplayName, - DurationSeconds: int(row.DurationSeconds), - StartedAt: startedAt, - Problem: problem, + GameID: int(row.GameID), + GameType: GameGameType(row.GameType), + State: GameState(row.State), + DisplayName: row.DisplayName, + DurationSeconds: int(row.DurationSeconds), + StartedAt: startedAt, + Problem: Problem{ + ProblemID: int(row.ProblemID), + Title: row.Title, + Description: row.Description, + }, Players: players, VerificationSteps: verificationSteps, } |
