Reimplement cursor as part of WebRequest extensions

> Added WebRequestExtensions
> Moved Cursor request logic from SearchBeatmapSetsRequest
This commit is contained in:
「空白」 2020-05-13 05:04:39 +09:00
parent cabf3a89b1
commit 5962dedd35
3 changed files with 29 additions and 15 deletions

View File

@ -0,0 +1,25 @@
using osu.Framework.IO.Network;
using osu.Framework.Extensions.IEnumerableExtensions;
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace osu.Game.Extensions
{
public class Cursor
{
[JsonExtensionData]
public IDictionary<string, JToken> Properties;
}
public static class WebRequestExtensions
{
public static void AddCursor(this WebRequest webRequest, Cursor cursor)
{
cursor?.Properties.ForEach(x =>
{
webRequest.AddParameter("cursor[" + x.Key + "]", x.Value.ToString());
});
}
}
}

View File

@ -2,24 +2,15 @@
// See the LICENCE file in the repository root for full licence text.
using osu.Framework.IO.Network;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Game.Extensions;
using osu.Game.Overlays;
using osu.Game.Overlays.BeatmapListing;
using osu.Game.Rulesets;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
namespace osu.Game.Online.API.Requests
{
public class SearchBeatmapSetsRequest : APIRequest<SearchBeatmapSetsResponse>
{
public class Cursor
{
[JsonExtensionData]
public IDictionary<string, JToken> Properties;
}
public SearchCategory SearchCategory { get; set; }
public SortCriteria SortCriteria { get; set; }
@ -68,10 +59,7 @@ protected override WebRequest CreateWebRequest()
req.AddParameter("sort", $"{SortCriteria.ToString().ToLowerInvariant()}_{directionString}");
cursor?.Properties.ForEach(x =>
{
req.AddParameter("cursor[" + x.Key + "]", x.Value?.ToString());
});
req.AddCursor(cursor);
return req;
}

View File

@ -3,11 +3,12 @@
using System.Collections.Generic;
using Newtonsoft.Json;
using osu.Game.Extensions;
using osu.Game.Online.API.Requests.Responses;
namespace osu.Game.Online.API.Requests
{
public class SearchBeatmapSetsResponse : ResponseWithCursor<SearchBeatmapSetsRequest.Cursor>
public class SearchBeatmapSetsResponse : ResponseWithCursor<Cursor>
{
[JsonProperty("beatmapsets")]
public IEnumerable<APIBeatmapSet> BeatmapSets;