Skip to content

Commit da07efe

Browse files
committed
Support limit/skip pagination on changes endpoints
Signed-off-by: Matheus Pimenta <matheuscscp@gmail.com>
1 parent 4280949 commit da07efe

5 files changed

Lines changed: 64 additions & 17 deletions

File tree

list_measurement_changes_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,8 @@ func TestClient_ListMeasurementChanges(t *testing.T) {
174174
g.Expect(query.Get("rikishiId")).To(Equal("123"))
175175
g.Expect(query.Get("bashoId")).To(Equal("202501"))
176176
g.Expect(query.Get("sortOrder")).To(Equal("asc"))
177+
g.Expect(query.Get("limit")).To(Equal("50"))
178+
g.Expect(query.Get("skip")).To(Equal("10"))
177179
return nil
178180
},
179181
response: &http.Response{
@@ -187,6 +189,8 @@ func TestClient_ListMeasurementChanges(t *testing.T) {
187189
RikishiID: 123,
188190
BashoID: &bashoID,
189191
SortOrder: "asc",
192+
Limit: 50,
193+
Skip: 10,
190194
})
191195

192196
g.Expect(err).ToNot(HaveOccurred())
@@ -208,6 +212,8 @@ func TestClient_ListMeasurementChanges(t *testing.T) {
208212
g.Expect(query.Has("rikishiId")).To(BeFalse())
209213
g.Expect(query.Has("bashoId")).To(BeFalse())
210214
g.Expect(query.Has("sortOrder")).To(BeFalse())
215+
g.Expect(query.Has("limit")).To(BeFalse())
216+
g.Expect(query.Has("skip")).To(BeFalse())
211217
return nil
212218
},
213219
response: &http.Response{

list_rank_changes_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ func TestClient_ListRankChanges(t *testing.T) {
167167
g.Expect(query.Get("rikishiId")).To(Equal("123"))
168168
g.Expect(query.Get("bashoId")).To(Equal("202501"))
169169
g.Expect(query.Get("sortOrder")).To(Equal("asc"))
170+
g.Expect(query.Get("limit")).To(Equal("50"))
171+
g.Expect(query.Get("skip")).To(Equal("10"))
170172
return nil
171173
},
172174
response: &http.Response{
@@ -180,6 +182,8 @@ func TestClient_ListRankChanges(t *testing.T) {
180182
RikishiID: 123,
181183
BashoID: &bashoID,
182184
SortOrder: "asc",
185+
Limit: 50,
186+
Skip: 10,
183187
})
184188

185189
g.Expect(err).ToNot(HaveOccurred())
@@ -200,6 +204,8 @@ func TestClient_ListRankChanges(t *testing.T) {
200204
g.Expect(query.Has("rikishiId")).To(BeFalse())
201205
g.Expect(query.Has("bashoId")).To(BeFalse())
202206
g.Expect(query.Has("sortOrder")).To(BeFalse())
207+
g.Expect(query.Has("limit")).To(BeFalse())
208+
g.Expect(query.Has("skip")).To(BeFalse())
203209
return nil
204210
},
205211
response: &http.Response{

list_rikishi_changes.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ type ListRikishiChangesRequest struct {
1111
RikishiID int `json:"rikishiId,omitempty" jsonschema:"The ID of the rikishi (sumo wrestler) whose changes are to be listed. Cannot be used together with bashoId."`
1212
BashoID *BashoID `json:"bashoId,omitempty" jsonschema:"The ID of the basho (sumo tournament) for which rikishi (sumo wrestler) changes are to be listed. Cannot be used together with rikishiId."`
1313
SortOrder string `json:"sortOrder,omitempty" jsonschema:"The order in which to sort the results by basho (sumo tournament). Valid values are 'asc' for ascending and 'desc' for descending. Default is 'desc'."`
14+
Limit int `json:"limit,omitempty" jsonschema:"The maximum number of results to return."`
15+
Skip int `json:"skip,omitempty" jsonschema:"The number of results to skip over for pagination."`
1416
}
1517

1618
func listRikishiChanges[obj any](ctx context.Context, c *client, path string, req ListRikishiChangesRequest) ([]obj, error) {
@@ -24,5 +26,11 @@ func listRikishiChanges[obj any](ctx context.Context, c *client, path string, re
2426
if order := getSortOrder(req.SortOrder); order != "" {
2527
query.Set("sortOrder", order)
2628
}
29+
if req.Limit > 0 {
30+
query.Set("limit", fmt.Sprint(req.Limit))
31+
}
32+
if req.Skip > 0 {
33+
query.Set("skip", fmt.Sprint(req.Skip))
34+
}
2735
return listObjects[obj](ctx, c, path, query)
2836
}

list_shikona_changes_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ func TestClient_ListShikonaChanges(t *testing.T) {
172172
g.Expect(query.Get("rikishiId")).To(Equal("123"))
173173
g.Expect(query.Get("bashoId")).To(Equal("202501"))
174174
g.Expect(query.Get("sortOrder")).To(Equal("asc"))
175+
g.Expect(query.Get("limit")).To(Equal("50"))
176+
g.Expect(query.Get("skip")).To(Equal("10"))
175177
return nil
176178
},
177179
response: &http.Response{
@@ -185,6 +187,8 @@ func TestClient_ListShikonaChanges(t *testing.T) {
185187
RikishiID: 123,
186188
BashoID: &bashoID,
187189
SortOrder: "asc",
190+
Limit: 50,
191+
Skip: 10,
188192
})
189193

190194
g.Expect(err).ToNot(HaveOccurred())
@@ -206,6 +210,8 @@ func TestClient_ListShikonaChanges(t *testing.T) {
206210
g.Expect(query.Has("rikishiId")).To(BeFalse())
207211
g.Expect(query.Has("bashoId")).To(BeFalse())
208212
g.Expect(query.Has("sortOrder")).To(BeFalse())
213+
g.Expect(query.Has("limit")).To(BeFalse())
214+
g.Expect(query.Has("skip")).To(BeFalse())
209215
return nil
210216
},
211217
response: &http.Response{

tests/integration/list_rank_changes_test.go

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,31 @@ import (
1212
func TestIntegration_ListRankChanges(t *testing.T) {
1313
client := sumoapi.New()
1414

15+
// Use a non-default limit to exercise the Limit input as well.
16+
const pageLimit = 99
17+
18+
listAllRanks := func(g *WithT, req sumoapi.ListRikishiChangesRequest) []sumoapi.Rank {
19+
req.Limit = pageLimit
20+
var all []sumoapi.Rank
21+
for {
22+
req.Skip = len(all)
23+
page, err := client.ListRankChanges(context.Background(), req)
24+
g.Expect(err).ToNot(HaveOccurred())
25+
g.Expect(page).ToNot(BeNil())
26+
all = append(all, page...)
27+
if len(page) < pageLimit {
28+
return all
29+
}
30+
}
31+
}
32+
1533
t.Run("for rikishi", func(t *testing.T) {
1634
g := NewWithT(t)
1735

18-
resp, err := client.ListRankChanges(context.Background(), sumoapi.ListRikishiChangesRequest{
36+
resp := listAllRanks(g, sumoapi.ListRikishiChangesRequest{
1937
RikishiID: 3081, // Hakuho
2038
})
2139

22-
g.Expect(err).ToNot(HaveOccurred())
23-
g.Expect(resp).ToNot(BeNil())
2440
g.Expect(resp).To(HaveLen(122))
2541

2642
expectedBashoID := sumoapi.BashoID{Year: 2021, Month: 9}
@@ -48,24 +64,29 @@ func TestIntegration_ListRankChanges(t *testing.T) {
4864
Month: 9,
4965
}
5066

51-
resp, err := client.ListRankChanges(context.Background(), sumoapi.ListRikishiChangesRequest{
67+
resp := listAllRanks(g, sumoapi.ListRikishiChangesRequest{
5268
BashoID: &bashoID,
5369
})
5470

55-
g.Expect(err).ToNot(HaveOccurred())
56-
g.Expect(resp).ToNot(BeNil())
5771
g.Expect(resp).To(HaveLen(611))
5872

59-
g.Expect(resp[0].ID).To(Equal(sumoapi.RikishiChangeID{BashoID: bashoID, RikishiID: 8850}))
60-
g.Expect(resp[0].BashoID).To(Equal(bashoID))
61-
g.Expect(resp[0].RikishiID).To(Equal(8850))
62-
g.Expect(resp[0].HumanReadableName).To(Equal("Yokozuna 1 East"))
63-
g.Expect(resp[0].NumericName).To(Equal(101))
64-
65-
g.Expect(resp[610].ID).To(Equal(sumoapi.RikishiChangeID{BashoID: bashoID, RikishiID: 9101}))
66-
g.Expect(resp[610].BashoID).To(Equal(bashoID))
67-
g.Expect(resp[610].RikishiID).To(Equal(9101))
68-
g.Expect(resp[610].HumanReadableName).To(Equal("Jonokuchi 26 East"))
69-
g.Expect(resp[610].NumericName).To(Equal(1026))
73+
// The /ranks endpoint does not return basho-scoped results in any
74+
// deterministic order (the first record changes depending on the
75+
// limit value), so assert membership rather than position. Pagination
76+
// still yields all 611 unique records.
77+
g.Expect(resp).To(ContainElement(sumoapi.Rank{
78+
ID: sumoapi.RikishiChangeID{BashoID: bashoID, RikishiID: 8850},
79+
BashoID: bashoID,
80+
RikishiID: 8850,
81+
HumanReadableName: "Yokozuna 1 East",
82+
NumericName: 101,
83+
}))
84+
g.Expect(resp).To(ContainElement(sumoapi.Rank{
85+
ID: sumoapi.RikishiChangeID{BashoID: bashoID, RikishiID: 9101},
86+
BashoID: bashoID,
87+
RikishiID: 9101,
88+
HumanReadableName: "Jonokuchi 26 East",
89+
NumericName: 1026,
90+
}))
7091
})
7192
}

0 commit comments

Comments
 (0)