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/handler.go | |
| 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/handler.go')
| -rw-r--r-- | backend/api/handler.go | 38 |
1 files changed, 17 insertions, 21 deletions
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, } |
