From bf53833b7bcf6636211d3b3a483a1ab96b1a811e Mon Sep 17 00:00:00 2001 From: cdwcgt Date: Fri, 1 Nov 2024 12:52:37 +0800 Subject: [PATCH] add API model and request --- .../Online/API/Requests/FriendAddRequest.cs | 31 +++++++++++++++++++ .../API/Requests/FriendDeleteRequest.cs | 27 ++++++++++++++++ .../Online/API/Requests/GetFriendsRequest.cs | 2 +- .../API/Requests/Responses/APIRelation.cs | 28 +++++++++++++++++ 4 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 osu.Game/Online/API/Requests/FriendAddRequest.cs create mode 100644 osu.Game/Online/API/Requests/FriendDeleteRequest.cs create mode 100644 osu.Game/Online/API/Requests/Responses/APIRelation.cs diff --git a/osu.Game/Online/API/Requests/FriendAddRequest.cs b/osu.Game/Online/API/Requests/FriendAddRequest.cs new file mode 100644 index 0000000000..3efba4a740 --- /dev/null +++ b/osu.Game/Online/API/Requests/FriendAddRequest.cs @@ -0,0 +1,31 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System.Net.Http; +using osu.Framework.IO.Network; +using osu.Game.Online.API.Requests.Responses; + +namespace osu.Game.Online.API.Requests +{ + public class FriendAddRequest : APIRequest + { + private readonly int targetId; + + public FriendAddRequest(int targetId) + { + this.targetId = targetId; + } + + protected override WebRequest CreateWebRequest() + { + var req = base.CreateWebRequest(); + + req.Method = HttpMethod.Post; + req.AddParameter("target", targetId.ToString(), RequestParameterType.Query); + + return req; + } + + protected override string Target => @"friends"; + } +} diff --git a/osu.Game/Online/API/Requests/FriendDeleteRequest.cs b/osu.Game/Online/API/Requests/FriendDeleteRequest.cs new file mode 100644 index 0000000000..d365031c8e --- /dev/null +++ b/osu.Game/Online/API/Requests/FriendDeleteRequest.cs @@ -0,0 +1,27 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System.Net.Http; +using osu.Framework.IO.Network; + +namespace osu.Game.Online.API.Requests +{ + public class FriendDeleteRequest : APIRequest + { + private readonly int targetId; + + public FriendDeleteRequest(int targetId) + { + this.targetId = targetId; + } + + protected override WebRequest CreateWebRequest() + { + var req = base.CreateWebRequest(); + req.Method = HttpMethod.Delete; + return req; + } + + protected override string Target => $@"friends/{targetId}"; + } +} diff --git a/osu.Game/Online/API/Requests/GetFriendsRequest.cs b/osu.Game/Online/API/Requests/GetFriendsRequest.cs index 63a221d91a..77b37e87d0 100644 --- a/osu.Game/Online/API/Requests/GetFriendsRequest.cs +++ b/osu.Game/Online/API/Requests/GetFriendsRequest.cs @@ -6,7 +6,7 @@ using osu.Game.Online.API.Requests.Responses; namespace osu.Game.Online.API.Requests { - public class GetFriendsRequest : APIRequest> + public class GetFriendsRequest : APIRequest> { protected override string Target => @"friends"; } diff --git a/osu.Game/Online/API/Requests/Responses/APIRelation.cs b/osu.Game/Online/API/Requests/Responses/APIRelation.cs new file mode 100644 index 0000000000..75b9a97ffc --- /dev/null +++ b/osu.Game/Online/API/Requests/Responses/APIRelation.cs @@ -0,0 +1,28 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using Newtonsoft.Json; + +namespace osu.Game.Online.API.Requests.Responses +{ + public class APIRelation + { + [JsonProperty("target_id")] + public int TargetID { get; set; } + + [JsonProperty("relation_type")] + public RelationType RelationType { get; set; } + + [JsonProperty("mutual")] + public bool Mutual { get; set; } + + [JsonProperty("target")] + public APIUser? TargetUser { get; set; } + } + + public enum RelationType + { + Friend, + Block, + } +}