mirror of https://github.com/ppy/osu
Add concept of "initial items count" in paginated API requests
This commit is contained in:
parent
587f1e2c4f
commit
9d59cd408f
|
@ -13,8 +13,8 @@ public class GetUserBeatmapsRequest : PaginatedAPIRequest<List<APIBeatmapSet>>
|
|||
|
||||
private readonly BeatmapSetType type;
|
||||
|
||||
public GetUserBeatmapsRequest(long userId, BeatmapSetType type, int page = 0, int itemsPerPage = 6)
|
||||
: base(page, itemsPerPage)
|
||||
public GetUserBeatmapsRequest(long userId, BeatmapSetType type, int page, int itemsPerPage, int initialItems)
|
||||
: base(page, itemsPerPage, initialItems)
|
||||
{
|
||||
this.userId = userId;
|
||||
this.type = type;
|
||||
|
|
|
@ -10,8 +10,8 @@ public class GetUserKudosuHistoryRequest : PaginatedAPIRequest<List<APIKudosuHis
|
|||
{
|
||||
private readonly long userId;
|
||||
|
||||
public GetUserKudosuHistoryRequest(long userId, int page = 0, int itemsPerPage = 5)
|
||||
: base(page, itemsPerPage)
|
||||
public GetUserKudosuHistoryRequest(long userId, int page, int itemsPerPage, int initialItems)
|
||||
: base(page, itemsPerPage, initialItems)
|
||||
{
|
||||
this.userId = userId;
|
||||
}
|
||||
|
|
|
@ -10,8 +10,8 @@ public class GetUserMostPlayedBeatmapsRequest : PaginatedAPIRequest<List<APIUser
|
|||
{
|
||||
private readonly long userId;
|
||||
|
||||
public GetUserMostPlayedBeatmapsRequest(long userId, int page = 0, int itemsPerPage = 5)
|
||||
: base(page, itemsPerPage)
|
||||
public GetUserMostPlayedBeatmapsRequest(long userId, int page, int itemsPerPage, int initialItems)
|
||||
: base(page, itemsPerPage, initialItems)
|
||||
{
|
||||
this.userId = userId;
|
||||
}
|
||||
|
|
|
@ -10,8 +10,8 @@ public class GetUserRecentActivitiesRequest : PaginatedAPIRequest<List<APIRecent
|
|||
{
|
||||
private readonly long userId;
|
||||
|
||||
public GetUserRecentActivitiesRequest(long userId, int page = 0, int itemsPerPage = 5)
|
||||
: base(page, itemsPerPage)
|
||||
public GetUserRecentActivitiesRequest(long userId, int page, int itemsPerPage, int initialItems)
|
||||
: base(page, itemsPerPage, initialItems)
|
||||
{
|
||||
this.userId = userId;
|
||||
}
|
||||
|
|
|
@ -14,8 +14,8 @@ public class GetUserScoresRequest : PaginatedAPIRequest<List<APIScore>>
|
|||
private readonly ScoreType type;
|
||||
private readonly RulesetInfo ruleset;
|
||||
|
||||
public GetUserScoresRequest(long userId, ScoreType type, int page = 0, int itemsPerPage = 5, RulesetInfo ruleset = null)
|
||||
: base(page, itemsPerPage)
|
||||
public GetUserScoresRequest(long userId, ScoreType type, int page, int itemsPerPage, int initialItems, RulesetInfo ruleset = null)
|
||||
: base(page, itemsPerPage, initialItems)
|
||||
{
|
||||
this.userId = userId;
|
||||
this.type = type;
|
||||
|
|
|
@ -9,11 +9,13 @@ namespace osu.Game.Online.API.Requests
|
|||
public abstract class PaginatedAPIRequest<T> : APIRequest<T> where T : class
|
||||
{
|
||||
private readonly int page;
|
||||
private readonly int initialItems;
|
||||
private readonly int itemsPerPage;
|
||||
|
||||
protected PaginatedAPIRequest(int page, int itemsPerPage)
|
||||
protected PaginatedAPIRequest(int page, int itemsPerPage, int initialItems)
|
||||
{
|
||||
this.page = page;
|
||||
this.initialItems = initialItems;
|
||||
this.itemsPerPage = itemsPerPage;
|
||||
}
|
||||
|
||||
|
@ -21,8 +23,13 @@ protected override WebRequest CreateWebRequest()
|
|||
{
|
||||
var req = base.CreateWebRequest();
|
||||
|
||||
req.AddParameter("offset", (page * itemsPerPage).ToString(CultureInfo.InvariantCulture));
|
||||
req.AddParameter("limit", itemsPerPage.ToString(CultureInfo.InvariantCulture));
|
||||
if (page == 0)
|
||||
req.AddParameter("limit", initialItems.ToString(CultureInfo.InvariantCulture));
|
||||
else
|
||||
{
|
||||
req.AddParameter("offset", (initialItems + (page - 1) * itemsPerPage).ToString(CultureInfo.InvariantCulture));
|
||||
req.AddParameter("limit", itemsPerPage.ToString(CultureInfo.InvariantCulture));
|
||||
}
|
||||
|
||||
return req;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue