diff --git a/WotBlitzStatistics.GraphQl/ObjectTypes/ClanInfoObjectType.cs b/WotBlitzStatistics.GraphQl/ObjectTypes/ClanInfoObjectType.cs new file mode 100644 index 0000000..8deeda7 --- /dev/null +++ b/WotBlitzStatistics.GraphQl/ObjectTypes/ClanInfoObjectType.cs @@ -0,0 +1,10 @@ +using HotChocolate.Types; +using WotBlitzStatisticsPro.WgApiClient.Model; + +namespace WotBlitzStatistics.GraphQl.ObjectTypes +{ + public class ClanInfoObjectType : ObjectType + { + + } +} \ No newline at end of file diff --git a/WotBlitzStatistics.GraphQl/ObjectTypes/PlayerAccountInfoObjectType.cs b/WotBlitzStatistics.GraphQl/ObjectTypes/PlayerAccountInfoObjectType.cs index 1c1b5e4..9a55df0 100644 --- a/WotBlitzStatistics.GraphQl/ObjectTypes/PlayerAccountInfoObjectType.cs +++ b/WotBlitzStatistics.GraphQl/ObjectTypes/PlayerAccountInfoObjectType.cs @@ -10,7 +10,7 @@ namespace WotBlitzStatistics.GraphQl.ObjectTypes protected override void Configure(IObjectTypeDescriptor descriptor) { descriptor.Field(a => a.Private).Ignore(); - descriptor.Field("clanInfo") + descriptor.Field("accountClanInfo") //.Argument("accountId", a => a.Type>()) //.Type() .Resolver(c => c.Service() diff --git a/WotBlitzStatistics.GraphQl/ObjectTypes/PlayerClanInfoObjectType.cs b/WotBlitzStatistics.GraphQl/ObjectTypes/PlayerClanInfoObjectType.cs index a08867b..3650d20 100644 --- a/WotBlitzStatistics.GraphQl/ObjectTypes/PlayerClanInfoObjectType.cs +++ b/WotBlitzStatistics.GraphQl/ObjectTypes/PlayerClanInfoObjectType.cs @@ -1,9 +1,19 @@ using HotChocolate.Types; +using WotBlitzStatisticsPro.WgApiClient; using WotBlitzStatisticsPro.WgApiClient.Model; namespace WotBlitzStatistics.GraphQl.ObjectTypes { public class PlayerClanInfoObjectType : ObjectType { + protected override void Configure(IObjectTypeDescriptor descriptor) + { + // ToDo: Cache clan info! + // https://hotchocolate.io/docs/dataloaders + descriptor.Field("clanInfo") + .Resolver(c => c.Service() + .GetClanInfo(c.Parent().ClanId.Value)); + + } } } diff --git a/WotBlitzStatistics.GraphQl/Startup.cs b/WotBlitzStatistics.GraphQl/Startup.cs index 022f1be..017a79a 100644 --- a/WotBlitzStatistics.GraphQl/Startup.cs +++ b/WotBlitzStatistics.GraphQl/Startup.cs @@ -45,6 +45,7 @@ namespace WotBlitzStatistics.GraphQl .AddType() .AddType() .AddType() + .AddType() //.AddEnumType() .Create()); } diff --git a/WotBlitzStatisticsPro.WgApiClient/IWargamingApiClient.cs b/WotBlitzStatisticsPro.WgApiClient/IWargamingApiClient.cs index decd87d..c9863a5 100644 --- a/WotBlitzStatisticsPro.WgApiClient/IWargamingApiClient.cs +++ b/WotBlitzStatisticsPro.WgApiClient/IWargamingApiClient.cs @@ -17,5 +17,9 @@ namespace WotBlitzStatisticsPro.WgApiClient Task GetPlayerClanInfo(long accountId, RealmType realmType = RealmType.Ru, RequestLanguage language = RequestLanguage.En); + + Task GetClanInfo(long clanId, + RealmType realmType = RealmType.Ru, + RequestLanguage language = RequestLanguage.En); } } diff --git a/WotBlitzStatisticsPro.WgApiClient/Model/ClanInfo.cs b/WotBlitzStatisticsPro.WgApiClient/Model/ClanInfo.cs new file mode 100644 index 0000000..6506b68 --- /dev/null +++ b/WotBlitzStatisticsPro.WgApiClient/Model/ClanInfo.cs @@ -0,0 +1,216 @@ +using System; +using System.Collections.Generic; +using Newtonsoft.Json; + +namespace WotBlitzStatisticsPro.WgApiClient.Model +{ + public class ClanInfo + { + /// + /// Clan can accept new players + /// + [JsonProperty("accepts_join_requests")] + public bool AcceptsJoinRequests { get; set; } + + /// + /// Clan identifier + /// + [JsonProperty("clan_id")] + public long? ClanId { get; set; } + + /// + /// Clan color in HEX #RRGGBB + /// + [JsonProperty("color")] + public string Color { get; set; } + + /// + /// Date of clan creation + /// + [JsonProperty("created_at")] + public int? CreatedAt { get; set; } + + /// + /// Clan creator account id + /// + [JsonProperty("creator_id")] + public long? CreatorId { get; set; } + + /// + /// Clan creator nick + /// + [JsonProperty("creator_name")] + public string CreatorName { get; set; } + + /// + /// Clan description + /// + [JsonProperty("description")] + public string Description { get; set; } + + /// + /// Html Clan description + /// + [JsonProperty("description_html")] + public string DescriptionHtml { get; set; } + + /// + /// Is clan deleted. Actual info about deleted clan only in fields: clan_id, is_clan_disbanded, updated_at. + /// + [JsonProperty("is_clan_disbanded")] + public bool IsClanDisbanded { get; set; } + + /// + /// Clan commander accountId + /// + [JsonProperty("leader_id")] + public long? LeaderId { get; set; } + + /// + /// Clan commander nick + /// + [JsonProperty("leader_name")] + public string LeaderName { get; set; } + + /// + /// Clan members count + /// + [JsonProperty("members_count")] + public long? MembersCount { get; set; } + + /// + /// Clan motto + /// + [JsonProperty("motto")] + public string Motto { get; set; } + + /// + /// Clan name + /// + [JsonProperty("name")] + public string Name { get; set; } + + /// + /// Renamed clan name + /// + [JsonProperty("old_name")] + public string OldName { get; set; } + + /// + /// Renamed clan tag + /// + [JsonProperty("old_tag")] + public string OldTag { get; set; } + + /// + /// Clan renaming time in UTC + /// + [JsonProperty("renamed_at")] + public int? RenamedAt { get; set; } + + /// + /// Clan tag + /// + [JsonProperty("tag")] + public string Tag { get; set; } + + /// + /// Clan info updated at + /// + [JsonProperty("updated_at")] + public int? UpdatedAt { get; set; } + + /// + /// Clan emblems info + /// + [JsonProperty("emblems")] + public WgnClansInfoEmblems Emblems { get; set; } + + /// + /// Clan members information. Depends on members_key field in request. + /// + [JsonProperty("members")] + public WgnClansInfoMembers Members { get; set; } + + /// + /// Private clan info + /// + [JsonProperty("private")] + public WgnClansInfoPrivate Private { get; set; } + } + + public class WgnClansInfoEmblems + { + /// + /// 195x195 px Icons list + /// + [JsonProperty("x195")] + public Dictionary X195 { get; set; } + + /// + /// 24x24 px Icons list + /// + [JsonProperty("x24")] + public Dictionary X24 { get; set; } + + /// + /// 256x256 px Icons list + /// + [JsonProperty("x256")] + public Dictionary X256 { get; set; } + + /// + /// 32x32 px Icons list + /// + [JsonProperty("x32")] + public Dictionary X32 { get; set; } + + /// + /// 64x64 px Icons list + /// + [JsonProperty("x64")] + public Dictionary X64 { get; set; } + } + + public class WgnClansInfoMembers + { + /// + /// Clan member account id + /// + [JsonProperty("account_id")] + public long? AccountId { get; set; } + + /// + /// Clan member nick + /// + [JsonProperty("account_name")] + public string AccountName { get; set; } + + /// + /// Date of joining the clan + /// + [JsonProperty("joined_at")] + public int? JoinedAt { get; set; } + + /// + /// Clan member role + /// + [JsonProperty("role")] + public string Role { get; set; } + + /// + /// Localized member role + /// + [JsonProperty("role_i18n")] + public string RoleI18n { get; set; } + } + + public class WgnClansInfoPrivate + { + [JsonProperty("online_members")] + public int[] OnlineMembers { get; set; } + + [JsonProperty("treasury")] + public long? Treasury { get; set; } + } +} \ No newline at end of file diff --git a/WotBlitzStatisticsPro.WgApiClient/WargamingApiClient.cs b/WotBlitzStatisticsPro.WgApiClient/WargamingApiClient.cs index 7d5b2ea..110fd97 100644 --- a/WotBlitzStatisticsPro.WgApiClient/WargamingApiClient.cs +++ b/WotBlitzStatisticsPro.WgApiClient/WargamingApiClient.cs @@ -49,5 +49,24 @@ namespace WotBlitzStatisticsPro.WgApiClient } return null; } + + public async Task GetClanInfo( + long clanId, + RealmType realmType = RealmType.Ru, + RequestLanguage language = RequestLanguage.En) + { + // https://api.wotblitz.ru/wotb/clans/info/?application_id=adc1387489cf9fc8d9a1d85dbd27763d&clan_id=40493 + var clanInfo = await GetFromBlitzApi>( + realmType, + language, + "clans/info/", + $"clan_id={clanId}").ConfigureAwait(false); + if (clanInfo.ContainsKey(clanId.ToString())) + { + return clanInfo[clanId.ToString()]; + } + return null; + } + } }