From 1d13507aa7ae919ec120aa18f3aa5db6a870a40d Mon Sep 17 00:00:00 2001 From: Michael Shabanov Date: Tue, 25 Feb 2020 00:46:02 +0300 Subject: [PATCH] ClanInfo added --- .../PlayerAccountInfoObjectType.cs | 9 ++++- .../ObjectTypes/PlayerClanInfoObjectType.cs | 7 +++- WotBlitzStatistics.GraphQl/Startup.cs | 1 + .../IWargamingApiClient.cs | 4 ++ .../Model/ClanAccountInfo.cs | 38 +++++++++++++++++++ .../WargamingApiClient.cs | 19 +++++++++- 6 files changed, 74 insertions(+), 4 deletions(-) create mode 100644 WotBlitzStatisticsPro.WgApiClient/Model/ClanAccountInfo.cs diff --git a/WotBlitzStatistics.GraphQl/ObjectTypes/PlayerAccountInfoObjectType.cs b/WotBlitzStatistics.GraphQl/ObjectTypes/PlayerAccountInfoObjectType.cs index 8b88641..1c1b5e4 100644 --- a/WotBlitzStatistics.GraphQl/ObjectTypes/PlayerAccountInfoObjectType.cs +++ b/WotBlitzStatistics.GraphQl/ObjectTypes/PlayerAccountInfoObjectType.cs @@ -1,5 +1,6 @@ using HotChocolate.Types; using System.Collections.Generic; +using WotBlitzStatisticsPro.WgApiClient; using WotBlitzStatisticsPro.WgApiClient.Model; namespace WotBlitzStatistics.GraphQl.ObjectTypes @@ -9,7 +10,13 @@ namespace WotBlitzStatistics.GraphQl.ObjectTypes protected override void Configure(IObjectTypeDescriptor descriptor) { descriptor.Field(a => a.Private).Ignore(); - descriptor.Field("Tanks").Type>>() + descriptor.Field("clanInfo") + //.Argument("accountId", a => a.Type>()) + //.Type() + .Resolver(c => c.Service() + .GetPlayerClanInfo(c.Parent().AccountId.Value)); + + descriptor.Field("tanks").Type>>() .Resolver(c => new List { "Fuck yeah" }); // Add resolver for Clan, Tanks, Achievements // https://hotchocolate.io/docs/schema-object-type diff --git a/WotBlitzStatistics.GraphQl/ObjectTypes/PlayerClanInfoObjectType.cs b/WotBlitzStatistics.GraphQl/ObjectTypes/PlayerClanInfoObjectType.cs index 4769d2c..a08867b 100644 --- a/WotBlitzStatistics.GraphQl/ObjectTypes/PlayerClanInfoObjectType.cs +++ b/WotBlitzStatistics.GraphQl/ObjectTypes/PlayerClanInfoObjectType.cs @@ -1,6 +1,9 @@ -namespace WotBlitzStatistics.GraphQl.ObjectTypes +using HotChocolate.Types; +using WotBlitzStatisticsPro.WgApiClient.Model; + +namespace WotBlitzStatistics.GraphQl.ObjectTypes { - public class PlayerClanInfoObjectType + public class PlayerClanInfoObjectType : ObjectType { } } diff --git a/WotBlitzStatistics.GraphQl/Startup.cs b/WotBlitzStatistics.GraphQl/Startup.cs index 1d08734..022f1be 100644 --- a/WotBlitzStatistics.GraphQl/Startup.cs +++ b/WotBlitzStatistics.GraphQl/Startup.cs @@ -44,6 +44,7 @@ namespace WotBlitzStatistics.GraphQl .AddType() .AddType() .AddType() + .AddType() //.AddEnumType() .Create()); } diff --git a/WotBlitzStatisticsPro.WgApiClient/IWargamingApiClient.cs b/WotBlitzStatisticsPro.WgApiClient/IWargamingApiClient.cs index f34658c..decd87d 100644 --- a/WotBlitzStatisticsPro.WgApiClient/IWargamingApiClient.cs +++ b/WotBlitzStatisticsPro.WgApiClient/IWargamingApiClient.cs @@ -13,5 +13,9 @@ namespace WotBlitzStatisticsPro.WgApiClient Task GetPlayerAccountInfo(long accountId, RealmType realmType = RealmType.Ru, RequestLanguage language = RequestLanguage.En); + + Task GetPlayerClanInfo(long accountId, + RealmType realmType = RealmType.Ru, + RequestLanguage language = RequestLanguage.En); } } diff --git a/WotBlitzStatisticsPro.WgApiClient/Model/ClanAccountInfo.cs b/WotBlitzStatisticsPro.WgApiClient/Model/ClanAccountInfo.cs new file mode 100644 index 0000000..e20d2ea --- /dev/null +++ b/WotBlitzStatisticsPro.WgApiClient/Model/ClanAccountInfo.cs @@ -0,0 +1,38 @@ +using Newtonsoft.Json; + +namespace WotBlitzStatisticsPro.WgApiClient.Model +{ + public class ClanAccountInfo + { + /// + /// AccountId + /// + [JsonProperty("account_id")] + public long? AccountId { get; set; } + + /// + /// Account nick + /// + [JsonProperty("account_name")] + public string AccountName { get; set; } + + /// + /// ClanId + /// + [JsonProperty("clan_id")] + public long? ClanId { get; set; } + + /// + /// Date of joining clan + /// + [JsonProperty("joined_at")] + public int? JoinedAt { get; set; } + + /// + /// Player clan role + /// + [JsonProperty("role")] + public string Role { get; set; } + + } +} diff --git a/WotBlitzStatisticsPro.WgApiClient/WargamingApiClient.cs b/WotBlitzStatisticsPro.WgApiClient/WargamingApiClient.cs index 4758241..7d5b2ea 100644 --- a/WotBlitzStatisticsPro.WgApiClient/WargamingApiClient.cs +++ b/WotBlitzStatisticsPro.WgApiClient/WargamingApiClient.cs @@ -8,6 +8,7 @@ namespace WotBlitzStatisticsPro.WgApiClient { public class WargamingApiClient : WagramingApiClientBase, IWargamingApiClient { + // ToDo: AddLogging public WargamingApiClient( HttpClient httpClient, IWargamingApiSettings wargamingApiSettings) : base(httpClient, wargamingApiSettings) @@ -29,8 +30,24 @@ namespace WotBlitzStatisticsPro.WgApiClient realmType, language, "account/info/", - $"account_id={accountId}"); + $"account_id={accountId}").ConfigureAwait(false); return account[accountId.ToString()]; } + + public async Task GetPlayerClanInfo(long accountId, + RealmType realmType = RealmType.Ru, + RequestLanguage language = RequestLanguage.En) + { + var clanInfo = await GetFromBlitzApi>( + realmType, + language, + "clans/accountinfo/", + $"account_id={accountId}").ConfigureAwait(false); + if (clanInfo.ContainsKey(accountId.ToString())) + { + return clanInfo[accountId.ToString()]; + } + return null; + } } }