1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 09:42:54 +08:00

Create API request and reponse model.

This commit is contained in:
naoey 2018-02-25 19:18:39 +05:30
parent c701b8eae5
commit e3a1b07172
No known key found for this signature in database
GPG Key ID: 3908EC682A3E19C7
5 changed files with 165 additions and 3 deletions

View File

@ -0,0 +1,89 @@
using Newtonsoft.Json;
using osu.Game.Rulesets.Scoring;
using Humanizer;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using osu.Game.Rulesets;
using osu.Game.Overlays.Profile.Sections.Recent;
namespace osu.Game.Online.API.Requests
{
public class GetUserRecentActivitiesRequest : APIRequest<List<RecentActivity>>
{
}
public class RecentActivity
{
[JsonProperty("id")]
public int ID;
[JsonProperty("created_at")]
public DateTimeOffset CreatedAt;
[JsonProperty]
private string type
{
set => Type = (RecentActivityType)Enum.Parse(typeof(RecentActivityType), value.Pascalize());
}
public RecentActivityType Type;
[JsonProperty]
private string scoreRank
{
set => ScoreRank = (ScoreRank)Enum.Parse(typeof(ScoreRank), value);
}
public ScoreRank ScoreRank;
[JsonProperty("rank")]
public int Rank;
[JsonProperty("mode")]
public string Mode;
[JsonProperty("beatmap")]
public RecentActivityBeatmap Beatmap;
[JsonProperty("user")]
public RecentActivityUser User;
public class RecentActivityBeatmap
{
[JsonProperty("title")]
public string Title;
[JsonProperty("url")]
public string Url;
}
public class RecentActivityUser
{
[JsonProperty("username")]
public string Username;
[JsonProperty("url")]
public string Url;
}
}
public enum RecentActivityType
{
Achievement,
BeatmapPlaycount,
BeatmapsetApprove,
BeatmapsetDelete,
BeatmapsetRevive,
BeatmapsetUpdate,
Medal,
Rank,
RankLost,
UserSupportAgain,
UserSupportFirst,
UserSupportGift,
UsernameChange,
}
}

View File

@ -0,0 +1,63 @@
using osu.Framework.Configuration;
using osu.Game.Online.API.Requests;
using osu.Game.Users;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace osu.Game.Overlays.Profile.Sections
{
class PaginatedRecentActivityContainer : PaginatedContainer
{
public PaginatedRecentActivityContainer(Bindable<User> user, string header, string missing)
: base(user, header, missing)
{
ItemsPerPage = 5;
}
//protected override void ShowMore()
//{
// base.ShowMore();
// var req = new GetUserRecentActivitiesRequest(User.Value.Id, VisiblePages++ * ItemsPerPage);
// req.Success += scores =>
// {
// foreach (var s in scores)
// s.ApplyRuleset(Rulesets.GetRuleset(s.OnlineRulesetID));
// ShowMoreButton.FadeTo(scores.Count == ItemsPerPage ? 1 : 0);
// ShowMoreLoading.Hide();
// if (!scores.Any() && VisiblePages == 1)
// {
// MissingText.Show();
// return;
// }
// MissingText.Hide();
// foreach (OnlineScore score in scores)
// {
// DrawableProfileScore drawableScore;
// switch (type)
// {
// default:
// drawableScore = new DrawablePerformanceScore(score, includeWeight ? Math.Pow(0.95, ItemsContainer.Count) : (double?)null);
// break;
// case ScoreType.Recent:
// drawableScore = new DrawableTotalScore(score);
// break;
// }
// ItemsContainer.Add(drawableScore);
// }
// };
// Api.Queue(req);
//}
}
}

View File

@ -7,6 +7,14 @@ namespace osu.Game.Overlays.Profile.Sections
{ {
public override string Title => "Recent"; public override string Title => "Recent";
public override string Identifier => "recent_activities"; public override string Identifier => "recent_activity";
public RecentSection()
{
Children = new[]
{
new PaginatedRecentActivityContainer(User, @"Recent", @"This user hasn't done anything notable recently!"),
};
}
} }
} }

View File

@ -82,7 +82,7 @@ namespace osu.Game.Overlays
sections = new ProfileSection[] sections = new ProfileSection[]
{ {
//new AboutSection(), //new AboutSection(),
//new RecentSection(), new RecentSection(),
new RanksSection(), new RanksSection(),
//new MedalsSection(), //new MedalsSection(),
new HistoricalSection(), new HistoricalSection(),

View File

@ -293,12 +293,14 @@
<Compile Include="Online\API\DummyAPIAccess.cs" /> <Compile Include="Online\API\DummyAPIAccess.cs" />
<Compile Include="Online\API\IAPIProvider.cs" /> <Compile Include="Online\API\IAPIProvider.cs" />
<Compile Include="Online\API\APIDownloadRequest.cs" /> <Compile Include="Online\API\APIDownloadRequest.cs" />
<Compile Include="Online\API\Requests\GetUserRecentActivitiesRequest.cs" />
<Compile Include="Online\API\Requests\GetUserRequest.cs" /> <Compile Include="Online\API\Requests\GetUserRequest.cs" />
<Compile Include="Migrations\20180125143340_Settings.cs" /> <Compile Include="Migrations\20180125143340_Settings.cs" />
<Compile Include="Migrations\20180125143340_Settings.Designer.cs"> <Compile Include="Migrations\20180125143340_Settings.Designer.cs">
<DependentUpon>20180125143340_Settings.cs</DependentUpon> <DependentUpon>20180125143340_Settings.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="Migrations\20180131154205_AddMuteBinding.cs" /> <Compile Include="Migrations\20180131154205_AddMuteBinding.cs" />
<Compile Include="Overlays\Profile\Sections\Recent\PaginatedRecentActivityContainer.cs" />
<Compile Include="Overlays\Profile\SupporterIcon.cs" /> <Compile Include="Overlays\Profile\SupporterIcon.cs" />
<Compile Include="Online\API\Requests\GetFriendsRequest.cs" /> <Compile Include="Online\API\Requests\GetFriendsRequest.cs" />
<Compile Include="Overlays\Settings\DangerousSettingsButton.cs" /> <Compile Include="Overlays\Settings\DangerousSettingsButton.cs" />