Skip to content

Commit

Permalink
feat: include worlds when returning list of games
Browse files Browse the repository at this point in the history
  • Loading branch information
SomethingSexy committed Sep 21, 2024
1 parent ce278b7 commit 1419eb9
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 14 deletions.
10 changes: 5 additions & 5 deletions internal/chronicle/adapter/http/game/game_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import (
)

type GameRequest struct {
ID string `jsonapi:"primary,game"`
GameId string `jsonapi:"attr,gameId"`
Name string `jsonapi:"attr,name"`
Type string `jsonapi:"attr,type"`
Worlds []domain.World `jsonapi:"relation,worlds"`
ID string `jsonapi:"primary,games"`
GameId string `jsonapi:"attr,gameId"`
Name string `jsonapi:"attr,name"`
Type string `jsonapi:"attr,type"`
Worlds []*WorldRequest `jsonapi:"relation,worlds"`
// ID int `jsonapi:"primary,blogs"`
// Title string `jsonapi:"attr,title"`
// Posts []*Post `jsonapi:"relation,posts"`
Expand Down
10 changes: 10 additions & 0 deletions internal/chronicle/adapter/http/game/game_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,21 @@ func (h GameHttpServer) ListGames(w http.ResponseWriter, r *http.Request) {

responses := make([]*GameRequest, len(games))
for i, game := range games {
worlds := make([]*WorldRequest, len(game.Worlds))

for x, world := range game.Worlds {
worlds[x] = &WorldRequest{
ID: world.WorldId.String(),
WorldId: world.WorldId.String(),
Name: world.Name,
}
}
responses[i] = &GameRequest{
ID: game.GameId.String(),
GameId: game.GameId.String(),
Name: game.Name,
Type: game.Type,
Worlds: worlds,
}
}

Expand Down
2 changes: 1 addition & 1 deletion internal/chronicle/adapter/http/game/world_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

type WorldRequest struct {
ID string `jsonapi:"primary,world"`
ID string `jsonapi:"primary,worlds"`
WorldId string `jsonapi:"attr,worldId"`
GameId string `jsonapi:"attr,gameId"`
Name string `jsonapi:"attr,name"`
Expand Down
10 changes: 4 additions & 6 deletions internal/chronicle/core/application/query/list_game.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,13 @@ func (h listGamesHandler) Handle(ctx context.Context, _ gamePort.AllGamesQuery)
return nil, err
}

for _, game := range games {
world, err := h.Persistence.GetGameWorlds(ctx, game.GameId)
for i := 0; i < len(games); i++ {
world, err := h.Persistence.GetGameWorlds(ctx, games[i].GameId)
if err != nil {
return nil, err
}
// TODO: Need to decide how many worlds to support in a game
if len(world) > 0 {
game.World = &world[0]
}

games[i].Worlds = world
}

return games, nil
Expand Down
3 changes: 1 addition & 2 deletions internal/chronicle/core/domain/game.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ type Game struct {
GameId uuid.UUID
Name string
Type string
// TODO: Need to decide how many worlds to support in a game.. maybe just open it up?
World *World
Worlds []World
}

0 comments on commit 1419eb9

Please sign in to comment.