From 0b520dc2529d7df6263842480d4ba7eaf07f4dcd Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sat, 10 Aug 2024 14:06:28 +0900 Subject: feat(backend): include `players` in `Game` object --- backend/api/handler.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'backend/api/handler.go') diff --git a/backend/api/handler.go b/backend/api/handler.go index 23c3cfe..8830d1c 100644 --- a/backend/api/handler.go +++ b/backend/api/handler.go @@ -135,6 +135,20 @@ func (h *Handler) GetGame(ctx context.Context, request GetGameRequestObject, use } } } + playerRows, err := h.q.ListGamePlayers(ctx, int32(gameID)) + if err != nil { + return nil, echo.NewHTTPError(http.StatusInternalServerError, err.Error()) + } + players := make([]User, len(playerRows)) + for i, playerRow := range playerRows { + players[i] = User{ + UserID: int(playerRow.UserID), + Username: playerRow.Username, + DisplayName: playerRow.DisplayName, + IconPath: playerRow.IconPath, + IsAdmin: playerRow.IsAdmin, + } + } game := Game{ GameID: int(row.GameID), GameType: GameGameType(row.GameType), @@ -143,6 +157,7 @@ func (h *Handler) GetGame(ctx context.Context, request GetGameRequestObject, use DurationSeconds: int(row.DurationSeconds), StartedAt: startedAt, Problem: problem, + Players: players, } return GetGame200JSONResponse{ Game: game, -- cgit v1.2.3-70-g09d2