aboutsummaryrefslogtreecommitdiffhomepage
path: root/backend/api/handler.go
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2024-08-11 20:53:17 +0900
committernsfisis <nsfisis@gmail.com>2024-08-11 20:53:17 +0900
commitfe8b14ccc77c829a2baa4034edb22daff9d5d8f8 (patch)
tree37528798ede5a89b1a7be6c6ee2fec20395668a2 /backend/api/handler.go
parente3502d9e649fe61bb0ba4046b2c23c0d78bc92e9 (diff)
parent0c448f5d403a084389acb0b3d215f8728a599302 (diff)
downloadiosdc-japan-2024-albatross-fe8b14ccc77c829a2baa4034edb22daff9d5d8f8.tar.gz
iosdc-japan-2024-albatross-fe8b14ccc77c829a2baa4034edb22daff9d5d8f8.tar.zst
iosdc-japan-2024-albatross-fe8b14ccc77c829a2baa4034edb22daff9d5d8f8.zip
Merge branch 'feat/send-problem-before-starting-game'
Diffstat (limited to 'backend/api/handler.go')
-rw-r--r--backend/api/handler.go49
1 files changed, 17 insertions, 32 deletions
diff --git a/backend/api/handler.go b/backend/api/handler.go
index 5b53791..4150ba6 100644
--- a/backend/api/handler.go
+++ b/backend/api/handler.go
@@ -89,17 +89,6 @@ func (h *Handler) GetGames(ctx context.Context, _ GetGamesRequestObject, user *a
startedAtTimestamp := int(row.StartedAt.Time.Unix())
startedAt = &startedAtTimestamp
}
- var problem *Problem
- if row.ProblemID != nil {
- if row.Title == nil || row.Description == nil {
- panic("inconsistent data")
- }
- problem = &Problem{
- ProblemID: int(*row.ProblemID),
- Title: *row.Title,
- Description: *row.Description,
- }
- }
games[i] = Game{
GameID: int(row.GameID),
GameType: GameGameType(row.GameType),
@@ -107,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{
@@ -117,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 {
@@ -134,19 +128,6 @@ func (h *Handler) GetGame(ctx context.Context, request GetGameRequestObject, use
startedAtTimestamp := int(row.StartedAt.Time.Unix())
startedAt = &startedAtTimestamp
}
- var problem *Problem
- if row.ProblemID != nil {
- if row.Title == nil || row.Description == nil {
- panic("inconsistent data")
- }
- 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())
@@ -176,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,
}