mirror of
https://github.com/ppy/osu.git
synced 2025-02-13 18:32:55 +08:00
add a user most played beatmaps request/response
This commit is contained in:
parent
1f379cab8f
commit
48b44e8e4e
@ -65,7 +65,7 @@ namespace osu.Game.Online.API.Requests
|
||||
Ranked = ranked,
|
||||
LastUpdated = lastUpdated,
|
||||
},
|
||||
Beatmaps = beatmaps.Select(b => b.ToBeatmap(rulesets)).ToList(),
|
||||
Beatmaps = beatmaps?.Select(b => b.ToBeatmap(rulesets)).ToList(),
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -1,18 +1,19 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System;
|
||||
using Humanizer;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace osu.Game.Online.API.Requests
|
||||
{
|
||||
public class GetUserBeatmapsRequest : APIRequest<List<GetBeatmapSetsResponse>>
|
||||
public class GetUserBeatmapsRequest<T> : APIRequest<List<T>>
|
||||
{
|
||||
private readonly long userId;
|
||||
private readonly int offset;
|
||||
private readonly BeatmapSetType type;
|
||||
|
||||
public GetUserBeatmapsRequest(long userId, BeatmapSetType type, int offset = 0)
|
||||
protected GetUserBeatmapsRequest(long userId, BeatmapSetType type, int offset = 0)
|
||||
{
|
||||
this.userId = userId;
|
||||
this.offset = offset;
|
||||
@ -22,6 +23,16 @@ namespace osu.Game.Online.API.Requests
|
||||
protected override string Target => $@"users/{userId}/beatmapsets/{type.ToString().Underscore()}?offset={offset}";
|
||||
}
|
||||
|
||||
public class GetUserBeatmapsRequest : GetUserBeatmapsRequest<GetBeatmapSetsResponse>
|
||||
{
|
||||
public GetUserBeatmapsRequest(long userID, BeatmapSetType type, int offset = 0)
|
||||
: base(userID, type, offset)
|
||||
{
|
||||
if(type == BeatmapSetType.MostPlayed)
|
||||
throw new ArgumentException("Please use " + nameof(GetUserMostPlayedBeatmapsRequest) + " instead");
|
||||
}
|
||||
}
|
||||
|
||||
public enum BeatmapSetType
|
||||
{
|
||||
MostPlayed,
|
||||
|
@ -0,0 +1,67 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using osu.Framework.Extensions;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Rulesets;
|
||||
|
||||
namespace osu.Game.Online.API.Requests
|
||||
{
|
||||
public class GetUserMostPlayedBeatmapsRequest : GetUserBeatmapsRequest<UserMostPlayedBeatmapsResponse>
|
||||
{
|
||||
public GetUserMostPlayedBeatmapsRequest(long userID, BeatmapSetType type, int offset = 0)
|
||||
: base(userID, type, offset)
|
||||
{
|
||||
if (type != BeatmapSetType.MostPlayed)
|
||||
throw new ArgumentException("Please use " + nameof(GetUserBeatmapsRequest) + " instead");
|
||||
}
|
||||
}
|
||||
|
||||
public class UserMostPlayedBeatmapsResponse
|
||||
{
|
||||
[JsonProperty("beatmap_id")]
|
||||
public int BeatmapID;
|
||||
|
||||
[JsonProperty("count")]
|
||||
public int PlayCount;
|
||||
|
||||
[JsonProperty]
|
||||
private BeatmapResponse beatmap;
|
||||
|
||||
[JsonProperty]
|
||||
private GetBeatmapSetsResponse beatmapSet;
|
||||
|
||||
public BeatmapInfo GetBeatmapInfo(RulesetStore rulesets)
|
||||
{
|
||||
BeatmapSetInfo setInfo = beatmapSet.ToBeatmapSet(rulesets);
|
||||
return new BeatmapInfo
|
||||
{
|
||||
OnlineBeatmapID = beatmap.Id,
|
||||
OnlineBeatmapSetID = setInfo.OnlineBeatmapSetID,
|
||||
Ruleset = rulesets.AvailableRulesets.FirstOrDefault(ruleset => ruleset.Name.Equals(beatmap.Mode)),
|
||||
StarDifficulty = beatmap.DifficultyRating,
|
||||
Version = beatmap.Version,
|
||||
Metadata = setInfo.Metadata,
|
||||
BeatmapSet = setInfo,
|
||||
};
|
||||
}
|
||||
|
||||
private class BeatmapResponse
|
||||
{
|
||||
[JsonProperty]
|
||||
public int Id;
|
||||
|
||||
[JsonProperty]
|
||||
public string Mode;
|
||||
|
||||
[JsonProperty("difficulty_rating")]
|
||||
public double DifficultyRating;
|
||||
|
||||
[JsonProperty]
|
||||
public string Version;
|
||||
}
|
||||
}
|
||||
}
|
@ -282,6 +282,7 @@
|
||||
<Compile Include="Migrations\OsuDbContextModelSnapshot.cs" />
|
||||
<Compile Include="Online\API\Requests\GetBeatmapSetRequest.cs" />
|
||||
<Compile Include="Online\API\Requests\GetBeatmapSetsResponse.cs" />
|
||||
<Compile Include="Online\API\Requests\GetUserMostPlayedBeatmapsRequest.cs" />
|
||||
<Compile Include="Overlays\BeatmapSet\Scores\ClickableUsername.cs" />
|
||||
<Compile Include="Overlays\BeatmapSet\Scores\DrawableScore.cs" />
|
||||
<Compile Include="Overlays\BeatmapSet\Scores\DrawableTopScore.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user