Skip to content

Commit 24901bf

Browse files
committed
feat: GET /maps/{mapId}/builders
1 parent ab95c3d commit 24901bf

3 files changed

Lines changed: 64 additions & 0 deletions

File tree

api/v4Internal/openapi.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,26 @@ paths:
8282
schema:
8383
type: object
8484
/maps/{mapId}/builders:
85+
get:
86+
operationId: getMapBuilders
87+
parameters:
88+
- name: mapId
89+
in: path
90+
required: true
91+
schema:
92+
type: string
93+
- name: onlyActive
94+
in: query
95+
required: true
96+
schema:
97+
type: boolean
98+
responses:
99+
"200":
100+
description: Successful response
101+
content:
102+
application/json:
103+
schema:
104+
type: object
85105
post:
86106
operationId: inviteMapBuilder
87107
parameters:

api/v4Internal/server.gen.go

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v4Internal/server_maps.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,38 @@ type (
2222
}
2323
)
2424

25+
type (
26+
GetMapBuildersRequest struct {
27+
MapID string `path:"mapId"`
28+
OnlyActive bool `query:"onlyActive"`
29+
}
30+
GetMapBuildersResponse struct {
31+
Results []MapBuilder `json:"results"`
32+
}
33+
)
34+
35+
// GET /maps/{mapId}/builders
36+
func (s *Server) GetMapBuilders(ctx context.Context, request GetMapBuildersRequest) (*GetMapBuildersResponse, error) {
37+
builders, err := s.mapStore.MulitGetMapBuilders(ctx, []string{request.MapID})
38+
if err != nil {
39+
return nil, fmt.Errorf("failed to get map builders: %w", err)
40+
}
41+
42+
results := make([]MapBuilder, 0, len(builders))
43+
for _, b := range builders {
44+
if b.IsPending && request.OnlyActive {
45+
continue
46+
}
47+
48+
results = append(results, MapBuilder{
49+
ID: b.PlayerID,
50+
CreatedAt: b.CreatedAt,
51+
Pending: b.IsPending,
52+
})
53+
}
54+
return &GetMapBuildersResponse{results}, nil
55+
}
56+
2557
type InviteMapBuilderRequest struct {
2658
PlayerID string `json:"playerId"` // Player being invited
2759
}

0 commit comments

Comments
 (0)