mirror of
https://github.com/DrMboga/WotBlitzStatisticsBlazor.git
synced 2026-10-23 19:30:06 +02:00
feat: Clan Resolver first step
This commit is contained in:
1 parent
7f713e5357
commit
8fb1b170df
11 files changed
+203
-2
No files matched your search
@@ -163,5 +163,10 @@ namespace WotBlitzStatisticsPro.Common.Model
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public List<TankInfoResponse>? Tanks { get; set; }
|
public List<TankInfoResponse>? Tanks { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clan info
|
||||||
|
/// </summary>
|
||||||
|
public ClanInfoResponse? ClanInfo { get; set; }
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,96 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace WotBlitzStatisticsPro.Common.Model
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Clan information
|
||||||
|
/// </summary>
|
||||||
|
public class ClanInfoResponse
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Clan ID
|
||||||
|
/// </summary>
|
||||||
|
public long ClanId { get; set; }
|
||||||
|
|
||||||
|
///<summary>
|
||||||
|
/// Date of joining clan
|
||||||
|
///</summary>
|
||||||
|
public DateTime JoinedAt { get; set; } = new DateTime(1970, 1, 1);
|
||||||
|
|
||||||
|
///<summary>
|
||||||
|
/// Player clan role
|
||||||
|
///</summary>
|
||||||
|
public string? Role { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clan name
|
||||||
|
/// </summary>
|
||||||
|
public string? Name { get; set; }
|
||||||
|
|
||||||
|
///<summary>
|
||||||
|
/// Date of clan creation
|
||||||
|
///</summary>
|
||||||
|
public DateTime CreatedAt { get; set; } = new DateTime(1970, 1, 1);
|
||||||
|
|
||||||
|
///<summary>
|
||||||
|
/// Clan creator account id
|
||||||
|
///</summary>
|
||||||
|
public long? CreatorId { get; set; }
|
||||||
|
|
||||||
|
///<summary>
|
||||||
|
/// Clan creator nick
|
||||||
|
///</summary>
|
||||||
|
public string? CreatorName { get; set; }
|
||||||
|
|
||||||
|
///<summary>
|
||||||
|
/// Clan description
|
||||||
|
///</summary>
|
||||||
|
public string? Description { get; set; }
|
||||||
|
|
||||||
|
///<summary>
|
||||||
|
/// Html Clan description
|
||||||
|
///</summary>
|
||||||
|
public string? DescriptionHtml { get; set; }
|
||||||
|
|
||||||
|
///<summary>
|
||||||
|
/// Clan commander accountId
|
||||||
|
///</summary>
|
||||||
|
public long? LeaderId { get; set; }
|
||||||
|
|
||||||
|
///<summary>
|
||||||
|
/// Clan commander nick
|
||||||
|
///</summary>
|
||||||
|
public string? LeaderName { get; set; }
|
||||||
|
|
||||||
|
///<summary>
|
||||||
|
/// Clan members count
|
||||||
|
///</summary>
|
||||||
|
public long? MembersCount { get; set; }
|
||||||
|
|
||||||
|
///<summary>
|
||||||
|
/// Clan motto
|
||||||
|
///</summary>
|
||||||
|
public string? Motto { get; set; }
|
||||||
|
|
||||||
|
///<summary>
|
||||||
|
/// Renamed clan name
|
||||||
|
///</summary>
|
||||||
|
public string? OldName { get; set; }
|
||||||
|
|
||||||
|
///<summary>
|
||||||
|
/// Renamed clan tag
|
||||||
|
///</summary>
|
||||||
|
public string? OldTag { get; set; }
|
||||||
|
|
||||||
|
///<summary>
|
||||||
|
/// Clan tag
|
||||||
|
///</summary>
|
||||||
|
public string? Tag { get; set; }
|
||||||
|
|
||||||
|
///<summary>
|
||||||
|
/// Clan info updated at
|
||||||
|
///</summary>
|
||||||
|
public int? UpdatedAt { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
namespace WotBlitzStatisticsPro.Common.Model
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Represents pair of realm type a nd requested language
|
||||||
|
/// </summary>
|
||||||
|
public record RealmAndLanguage (RealmType realm, RequestLanguage language);
|
||||||
|
}
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,10 +1,12 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using HotChocolate.Types;
|
||||||
using WotBlitzStatisticsPro.Common.Model;
|
using WotBlitzStatisticsPro.Common.Model;
|
||||||
using WotBlitzStatisticsPro.Logic;
|
using WotBlitzStatisticsPro.Logic;
|
||||||
|
|
||||||
namespace WotBlitzStatisticsPro.GraphQl.Query
|
namespace WotBlitzStatisticsPro.GraphQl.Query
|
||||||
{
|
{
|
||||||
|
[ExtendObjectType(Name = "Query")]
|
||||||
public class WotBlitzStatisticsQuery
|
public class WotBlitzStatisticsQuery
|
||||||
{
|
{
|
||||||
// 571050560 - mboga Eu
|
// 571050560 - mboga Eu
|
||||||
|
|||||||
@@ -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<AccountInfoResponse>
|
||||||
|
{
|
||||||
|
protected override void Configure(IObjectTypeDescriptor<AccountInfoResponse> descriptor)
|
||||||
|
{
|
||||||
|
descriptor.Field(t => t.ClanInfo)
|
||||||
|
.Resolver(ctx => ctx.Service<IWargamingClans>().GelClanInfoByAccount(ctx.Parent<AccountInfoResponse>().AccountId, ctx.Operation.ParseOperation()));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,6 +9,7 @@ using WotBlitzStatisticsPro.Common.Model;
|
|||||||
using WotBlitzStatisticsPro.GraphQl.Mutation;
|
using WotBlitzStatisticsPro.GraphQl.Mutation;
|
||||||
using WotBlitzStatisticsPro.GraphQl.ObjectTypes;
|
using WotBlitzStatisticsPro.GraphQl.ObjectTypes;
|
||||||
using WotBlitzStatisticsPro.GraphQl.Query;
|
using WotBlitzStatisticsPro.GraphQl.Query;
|
||||||
|
using WotBlitzStatisticsPro.GraphQl.Resolvers;
|
||||||
using WotBlitzStatisticsPro.Logic;
|
using WotBlitzStatisticsPro.Logic;
|
||||||
|
|
||||||
namespace WotBlitzStatisticsPro.GraphQl
|
namespace WotBlitzStatisticsPro.GraphQl
|
||||||
@@ -41,7 +42,9 @@ namespace WotBlitzStatisticsPro.GraphQl
|
|||||||
|
|
||||||
// Add GraphQL Services
|
// Add GraphQL Services
|
||||||
services.AddGraphQLServer()
|
services.AddGraphQLServer()
|
||||||
.AddQueryType<WotBlitzStatisticsQuery>()
|
.AddQueryType(d => d.Name("Query"))
|
||||||
|
.AddType<WotBlitzStatisticsQuery>()
|
||||||
|
.AddType<AccountInfoResolver>()
|
||||||
.AddMutationType<WotBlitzStatisticsMutation>()
|
.AddMutationType<WotBlitzStatisticsMutation>()
|
||||||
.AddType<AccountsSearchItemObjectType>()
|
.AddType<AccountsSearchItemObjectType>()
|
||||||
.AddType<AccountsSearchObjectType>()
|
.AddType<AccountsSearchObjectType>()
|
||||||
|
|||||||
@@ -23,7 +23,6 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="DataLoaders\" />
|
<Folder Include="DataLoaders\" />
|
||||||
<Folder Include="Resolvers\" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
using System.Threading.Tasks;
|
||||||
|
using WotBlitzStatisticsPro.Common.Model;
|
||||||
|
|
||||||
|
namespace WotBlitzStatisticsPro.Logic
|
||||||
|
{
|
||||||
|
public interface IWargamingClans
|
||||||
|
{
|
||||||
|
Task<ClanInfoResponse> GelClanInfoByAccount(long accountId, RealmAndLanguage queryParams);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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<ClanInfoResponse> GelClanInfoByAccount(long accountId, RealmAndLanguage queryParams)
|
||||||
|
{
|
||||||
|
// ToDo: Make Wargaming request
|
||||||
|
return Task.FromResult(new ClanInfoResponse {ClanId = 42, Name = "Fake clan"});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -29,6 +29,7 @@ namespace WotBlitzStatisticsPro.Logic
|
|||||||
services.AddTransient<IWargamingSearch, WargamingSearch>();
|
services.AddTransient<IWargamingSearch, WargamingSearch>();
|
||||||
services.AddTransient<IWargamingDictionaries, WargamingDictionaries>();
|
services.AddTransient<IWargamingDictionaries, WargamingDictionaries>();
|
||||||
services.AddTransient<IWargamingAccounts, WargamingAccounts>();
|
services.AddTransient<IWargamingAccounts, WargamingAccounts>();
|
||||||
|
services.AddTransient<IWargamingClans, WargamingClans>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ConfigureDictionariesFactory(IServiceCollection services)
|
private static void ConfigureDictionariesFactory(IServiceCollection services)
|
||||||
|
|||||||
Reference in new issue
Block a user