From 8fb1b170df8b3c855b5e213b2f40e727ca8f71fc Mon Sep 17 00:00:00 2001 From: Mikhail Shabanov Date: Fri, 19 Mar 2021 19:49:58 +0100 Subject: [PATCH] feat: Clan Resolver first step --- .../Model/AccountInfoResponse.cs | 5 + .../Model/ClanInfoResponse.cs | 96 +++++++++++++++++++ .../Model/RealmAndLanguage.cs | 7 ++ .../Helpers/ParametersParser.cs | 42 ++++++++ .../Query/WotBlitzStatisticsQuery.cs | 2 + .../Resolvers/AccountInfoResolver.cs | 18 ++++ WotBlitzStatisticsPro.GraphQl/Startup.cs | 5 +- .../WotBlitzStatisticsPro.GraphQl.csproj | 1 - .../IWargamingClans.cs | 10 ++ WotBlitzStatisticsPro.Logic/WargamingClans.cs | 18 ++++ .../WotBlitzStatisticsLogicInstaller.cs | 1 + 11 files changed, 203 insertions(+), 2 deletions(-) create mode 100644 WotBlitzStatisticsPro.Common/Model/ClanInfoResponse.cs create mode 100644 WotBlitzStatisticsPro.Common/Model/RealmAndLanguage.cs create mode 100644 WotBlitzStatisticsPro.GraphQl/Helpers/ParametersParser.cs create mode 100644 WotBlitzStatisticsPro.GraphQl/Resolvers/AccountInfoResolver.cs create mode 100644 WotBlitzStatisticsPro.Logic/IWargamingClans.cs create mode 100644 WotBlitzStatisticsPro.Logic/WargamingClans.cs diff --git a/WotBlitzStatisticsPro.Common/Model/AccountInfoResponse.cs b/WotBlitzStatisticsPro.Common/Model/AccountInfoResponse.cs index f30526f..8d2d0c8 100644 --- a/WotBlitzStatisticsPro.Common/Model/AccountInfoResponse.cs +++ b/WotBlitzStatisticsPro.Common/Model/AccountInfoResponse.cs @@ -163,5 +163,10 @@ namespace WotBlitzStatisticsPro.Common.Model /// public List? Tanks { get; set; } + /// + /// Clan info + /// + public ClanInfoResponse? ClanInfo { get; set; } + } } \ No newline at end of file diff --git a/WotBlitzStatisticsPro.Common/Model/ClanInfoResponse.cs b/WotBlitzStatisticsPro.Common/Model/ClanInfoResponse.cs new file mode 100644 index 0000000..f9a01ee --- /dev/null +++ b/WotBlitzStatisticsPro.Common/Model/ClanInfoResponse.cs @@ -0,0 +1,96 @@ +using System; + +namespace WotBlitzStatisticsPro.Common.Model +{ + /// + /// Clan information + /// + public class ClanInfoResponse + { + /// + /// Clan ID + /// + public long ClanId { get; set; } + + /// + /// Date of joining clan + /// + public DateTime JoinedAt { get; set; } = new DateTime(1970, 1, 1); + + /// + /// Player clan role + /// + public string? Role { get; set; } + + + /// + /// Clan name + /// + public string? Name { get; set; } + + /// + /// Date of clan creation + /// + public DateTime CreatedAt { get; set; } = new DateTime(1970, 1, 1); + + /// + /// Clan creator account id + /// + public long? CreatorId { get; set; } + + /// + /// Clan creator nick + /// + public string? CreatorName { get; set; } + + /// + /// Clan description + /// + public string? Description { get; set; } + + /// + /// Html Clan description + /// + public string? DescriptionHtml { get; set; } + + /// + /// Clan commander accountId + /// + public long? LeaderId { get; set; } + + /// + /// Clan commander nick + /// + public string? LeaderName { get; set; } + + /// + /// Clan members count + /// + public long? MembersCount { get; set; } + + /// + /// Clan motto + /// + public string? Motto { get; set; } + + /// + /// Renamed clan name + /// + public string? OldName { get; set; } + + /// + /// Renamed clan tag + /// + public string? OldTag { get; set; } + + /// + /// Clan tag + /// + public string? Tag { get; set; } + + /// + /// Clan info updated at + /// + public int? UpdatedAt { get; set; } + } +} \ No newline at end of file diff --git a/WotBlitzStatisticsPro.Common/Model/RealmAndLanguage.cs b/WotBlitzStatisticsPro.Common/Model/RealmAndLanguage.cs new file mode 100644 index 0000000..3721c52 --- /dev/null +++ b/WotBlitzStatisticsPro.Common/Model/RealmAndLanguage.cs @@ -0,0 +1,7 @@ +namespace WotBlitzStatisticsPro.Common.Model +{ + /// + /// Represents pair of realm type a nd requested language + /// + public record RealmAndLanguage (RealmType realm, RequestLanguage language); +} \ No newline at end of file diff --git a/WotBlitzStatisticsPro.GraphQl/Helpers/ParametersParser.cs b/WotBlitzStatisticsPro.GraphQl/Helpers/ParametersParser.cs new file mode 100644 index 0000000..bffde51 --- /dev/null +++ b/WotBlitzStatisticsPro.GraphQl/Helpers/ParametersParser.cs @@ -0,0 +1,42 @@ +using System; +using System.Linq; +using HotChocolate.Language; +using WotBlitzStatisticsPro.Common.Model; + +namespace WotBlitzStatisticsPro.GraphQl.Helpers +{ + public static class ParametersParser + { + private const RealmType DefaultRealm = RealmType.Ru; + private const RequestLanguage DefaultRequestLanguage = RequestLanguage.En; + + public static RealmAndLanguage ParseOperation(this OperationDefinitionNode operationDefinition) + { + var realm = DefaultRealm; + var language = DefaultRequestLanguage; + var selections = operationDefinition?.SelectionSet.Selections.ToArray(); + if (selections != null && selections.Length == 1) + { + var node = selections[0] as FieldNode; + if (node?.Arguments != null) + { + foreach (var argument in node.Arguments.Where(a => a != null)) + { + switch (argument.Name.Value) + { + case "realmType" when argument?.Value?.Value != null: + realm = (RealmType)Enum.Parse(typeof(RealmType), argument.Value.Value.ToString() ?? "Ru", true); + break; + case "requestLanguage" when argument?.Value?.Value != null: + language = (RequestLanguage)Enum.Parse(typeof(RequestLanguage), argument.Value.Value.ToString() ?? "En", true); + break; + } + } + } + } + + return new (realm, language); + } + + } +} \ No newline at end of file diff --git a/WotBlitzStatisticsPro.GraphQl/Query/WotBlitzStatisticsQuery.cs b/WotBlitzStatisticsPro.GraphQl/Query/WotBlitzStatisticsQuery.cs index 76a9b2c..ca2d09b 100644 --- a/WotBlitzStatisticsPro.GraphQl/Query/WotBlitzStatisticsQuery.cs +++ b/WotBlitzStatisticsPro.GraphQl/Query/WotBlitzStatisticsQuery.cs @@ -1,10 +1,12 @@ using System; using System.Threading.Tasks; +using HotChocolate.Types; using WotBlitzStatisticsPro.Common.Model; using WotBlitzStatisticsPro.Logic; namespace WotBlitzStatisticsPro.GraphQl.Query { + [ExtendObjectType(Name = "Query")] public class WotBlitzStatisticsQuery { // 571050560 - mboga Eu diff --git a/WotBlitzStatisticsPro.GraphQl/Resolvers/AccountInfoResolver.cs b/WotBlitzStatisticsPro.GraphQl/Resolvers/AccountInfoResolver.cs new file mode 100644 index 0000000..43a9a1d --- /dev/null +++ b/WotBlitzStatisticsPro.GraphQl/Resolvers/AccountInfoResolver.cs @@ -0,0 +1,18 @@ +using HotChocolate.Types; +using WotBlitzStatisticsPro.Common.Model; +using WotBlitzStatisticsPro.GraphQl.Helpers; +using WotBlitzStatisticsPro.Logic; + +namespace WotBlitzStatisticsPro.GraphQl.Resolvers +{ + [ExtendObjectType(Name = "Query")] + public class AccountInfoResolver: ObjectType + { + protected override void Configure(IObjectTypeDescriptor descriptor) + { + descriptor.Field(t => t.ClanInfo) + .Resolver(ctx => ctx.Service().GelClanInfoByAccount(ctx.Parent().AccountId, ctx.Operation.ParseOperation())); + + } + } +} \ No newline at end of file diff --git a/WotBlitzStatisticsPro.GraphQl/Startup.cs b/WotBlitzStatisticsPro.GraphQl/Startup.cs index b975f87..42a37b7 100644 --- a/WotBlitzStatisticsPro.GraphQl/Startup.cs +++ b/WotBlitzStatisticsPro.GraphQl/Startup.cs @@ -9,6 +9,7 @@ using WotBlitzStatisticsPro.Common.Model; using WotBlitzStatisticsPro.GraphQl.Mutation; using WotBlitzStatisticsPro.GraphQl.ObjectTypes; using WotBlitzStatisticsPro.GraphQl.Query; +using WotBlitzStatisticsPro.GraphQl.Resolvers; using WotBlitzStatisticsPro.Logic; namespace WotBlitzStatisticsPro.GraphQl @@ -41,7 +42,9 @@ namespace WotBlitzStatisticsPro.GraphQl // Add GraphQL Services services.AddGraphQLServer() - .AddQueryType() + .AddQueryType(d => d.Name("Query")) + .AddType() + .AddType() .AddMutationType() .AddType() .AddType() diff --git a/WotBlitzStatisticsPro.GraphQl/WotBlitzStatisticsPro.GraphQl.csproj b/WotBlitzStatisticsPro.GraphQl/WotBlitzStatisticsPro.GraphQl.csproj index d90d73f..f8a0d72 100644 --- a/WotBlitzStatisticsPro.GraphQl/WotBlitzStatisticsPro.GraphQl.csproj +++ b/WotBlitzStatisticsPro.GraphQl/WotBlitzStatisticsPro.GraphQl.csproj @@ -23,7 +23,6 @@ - diff --git a/WotBlitzStatisticsPro.Logic/IWargamingClans.cs b/WotBlitzStatisticsPro.Logic/IWargamingClans.cs new file mode 100644 index 0000000..6e568e8 --- /dev/null +++ b/WotBlitzStatisticsPro.Logic/IWargamingClans.cs @@ -0,0 +1,10 @@ +using System.Threading.Tasks; +using WotBlitzStatisticsPro.Common.Model; + +namespace WotBlitzStatisticsPro.Logic +{ + public interface IWargamingClans + { + Task GelClanInfoByAccount(long accountId, RealmAndLanguage queryParams); + } +} \ No newline at end of file diff --git a/WotBlitzStatisticsPro.Logic/WargamingClans.cs b/WotBlitzStatisticsPro.Logic/WargamingClans.cs new file mode 100644 index 0000000..479ec07 --- /dev/null +++ b/WotBlitzStatisticsPro.Logic/WargamingClans.cs @@ -0,0 +1,18 @@ +using System; +using System.Threading.Tasks; +using WotBlitzStatisticsPro.Common.Model; + +namespace WotBlitzStatisticsPro.Logic +{ + public class WargamingClans: IWargamingClans + { + private const RealmType DefaultRealm = RealmType.Ru; + private const RequestLanguage DefaultRequestLanguage = RequestLanguage.En; + + public Task GelClanInfoByAccount(long accountId, RealmAndLanguage queryParams) + { + // ToDo: Make Wargaming request + return Task.FromResult(new ClanInfoResponse {ClanId = 42, Name = "Fake clan"}); + } + } +} \ No newline at end of file diff --git a/WotBlitzStatisticsPro.Logic/WotBlitzStatisticsLogicInstaller.cs b/WotBlitzStatisticsPro.Logic/WotBlitzStatisticsLogicInstaller.cs index 86a6331..8b0df9c 100644 --- a/WotBlitzStatisticsPro.Logic/WotBlitzStatisticsLogicInstaller.cs +++ b/WotBlitzStatisticsPro.Logic/WotBlitzStatisticsLogicInstaller.cs @@ -29,6 +29,7 @@ namespace WotBlitzStatisticsPro.Logic services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); } private static void ConfigureDictionariesFactory(IServiceCollection services)