mirror of
https://github.com/DrMboga/WotBlitzStatisticsBlazor.git
synced 2026-10-21 02:17:20 +02:00
Encapsulated WG logic, added automapper, added realm and lang parameters
This commit is contained in:
1 parent
a4b3ae96fd
commit
ed770e8c30
10 files changed
+136
-24
No files matched your search
@@ -1,35 +1,30 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading.Tasks;
|
||||
using WotBlitzStatistics.Logic;
|
||||
using WotBlitzStatisticsPro.Common.Model;
|
||||
using WotBlitzStatisticsPro.WgApiClient;
|
||||
using WotBlitzStatisticsPro.WgApiClient.Model;
|
||||
|
||||
namespace WotBlitzStatistics.GraphQl.Query
|
||||
{
|
||||
public class WotBlitzStatisticsQuery
|
||||
{
|
||||
private readonly IWargamingApiClient _wargamingApiClient;
|
||||
private readonly IWargamingSearch _wargamingSearcher;
|
||||
|
||||
public WotBlitzStatisticsQuery(IWargamingApiClient wargamingApiClient)
|
||||
public WotBlitzStatisticsQuery(IWargamingSearch wargamingSearcher)
|
||||
{
|
||||
_wargamingApiClient = wargamingApiClient;
|
||||
_wargamingSearcher = wargamingSearcher;
|
||||
}
|
||||
|
||||
//public Task<AccountInfo> GetPlayerInfo(long accountId)
|
||||
//{
|
||||
// return _wargamingApiClient.GetPlayerAccountInfo(accountId);
|
||||
// return _wargamingSearcher.GetPlayerAccountInfo(accountId);
|
||||
//}
|
||||
|
||||
public async Task<AccountsSearchResponse> FindAccounts(string accountNick)
|
||||
public Task<AccountsSearchResponse> FindAccounts(
|
||||
string accountNick,
|
||||
RealmType? realmType,
|
||||
RequestLanguage? language)
|
||||
{
|
||||
var response = await _wargamingApiClient.FindAccounts(accountNick);
|
||||
// ToDo: Use auto mapper
|
||||
var result = new AccountsSearchResponse
|
||||
{
|
||||
AccountsCount = response.Count,
|
||||
Accounts = new List<AccountsSearchResponseItem>()
|
||||
};
|
||||
response.ForEach(r => result.Accounts.Add(new AccountsSearchResponseItem {AccountId = r.AccountId.Value, Nickname = r.Nickname}));
|
||||
return result;
|
||||
return _wargamingSearcher.FindAccounts(accountNick, realmType ?? RealmType.Ru, language ?? RequestLanguage.En);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,8 @@ using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using WotBlitzStatistics.GraphQl.ObjectTypes;
|
||||
using WotBlitzStatistics.GraphQl.Query;
|
||||
using WotBlitzStatistics.Logic;
|
||||
using WotBlitzStatisticsPro.Common.Model;
|
||||
using WotBlitzStatisticsPro.WgApiClient;
|
||||
using WotBlitzStatisticsPro.WgApiClient.Model;
|
||||
|
||||
@@ -29,7 +31,7 @@ namespace WotBlitzStatistics.GraphQl
|
||||
Configuration.GetSection("WargamingApi").Bind(wgApiConfig);
|
||||
|
||||
services.AddSingleton<IWargamingApiSettings>(wgApiConfig);
|
||||
services.AddHttpClient<IWargamingApiClient, WargamingApiClient>();
|
||||
WotBlitzStatisticsLogicInstaller.ConfigureServices(services);
|
||||
|
||||
// Global data loader - caches data between requests
|
||||
// ToDo: cause nullreference exception
|
||||
@@ -51,7 +53,9 @@ namespace WotBlitzStatistics.GraphQl
|
||||
//.AddSubscriptionType<SubscriptionType>()
|
||||
.AddType<AccountsSearchItemObjectType>()
|
||||
.AddType<AccountsSearchObjectType>()
|
||||
//.AddEnumType<MarkOfMastery>()
|
||||
.AddEnumType<MarkOfMastery>()
|
||||
.AddEnumType<RealmType>()
|
||||
.AddEnumType<RequestLanguage>()
|
||||
.Create());
|
||||
}
|
||||
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\WotBlitzStatistics.Logic\WotBlitzStatistics.Logic.csproj" />
|
||||
<ProjectReference Include="..\WotBlitzStatisticsPro.Common\WotBlitzStatisticsPro.Common.csproj" />
|
||||
<ProjectReference Include="..\WotBlitzStatisticsPro.WgApiClient\WotBlitzStatisticsPro.WgApiClient.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
using System.Threading.Tasks;
|
||||
using WotBlitzStatisticsPro.Common.Model;
|
||||
using WotBlitzStatisticsPro.WgApiClient.Model;
|
||||
|
||||
namespace WotBlitzStatistics.Logic
|
||||
{
|
||||
public interface IWargamingSearch
|
||||
{
|
||||
Task<AccountsSearchResponse> FindAccounts(
|
||||
string accountNick,
|
||||
RealmType realmType,
|
||||
RequestLanguage language);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using AutoMapper;
|
||||
using WotBlitzStatisticsPro.Common.Model;
|
||||
using WotBlitzStatisticsPro.WgApiClient.Model;
|
||||
|
||||
namespace WotBlitzStatistics.Logic.Mappers
|
||||
{
|
||||
public class AccountSearchResponseProfile : Profile
|
||||
{
|
||||
public AccountSearchResponseProfile()
|
||||
{
|
||||
CreateMap<WotAccountListResponse, AccountsSearchResponseItem>()
|
||||
.ForMember(
|
||||
d => d.AccountId,
|
||||
o => o.MapFrom(s => s.AccountId.Value));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using AutoMapper;
|
||||
using WotBlitzStatisticsPro.Common.Model;
|
||||
using WotBlitzStatisticsPro.WgApiClient;
|
||||
using WotBlitzStatisticsPro.WgApiClient.Model;
|
||||
|
||||
namespace WotBlitzStatistics.Logic
|
||||
{
|
||||
public class WargamingSearch : IWargamingSearch
|
||||
{
|
||||
private readonly IWargamingApiClient _wargamingApiClient;
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
public WargamingSearch(IWargamingApiClient wargamingApiClient, IMapper mapper)
|
||||
{
|
||||
_wargamingApiClient = wargamingApiClient;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
public async Task<AccountsSearchResponse> FindAccounts(
|
||||
string accountNick,
|
||||
RealmType realmType,
|
||||
RequestLanguage language)
|
||||
{
|
||||
var response = await _wargamingApiClient.FindAccounts(accountNick, realmType, language);
|
||||
return new AccountsSearchResponse
|
||||
{
|
||||
AccountsCount = response.Count,
|
||||
Accounts = _mapper.Map<List<WotAccountListResponse>, List<AccountsSearchResponseItem>>(response)
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AutoMapper" Version="9.0.0" />
|
||||
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.4" />
|
||||
<PackageReference Include="Microsoft.Extensions.Http" Version="3.1.4" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\WotBlitzStatisticsPro.Common\WotBlitzStatisticsPro.Common.csproj" />
|
||||
<ProjectReference Include="..\WotBlitzStatisticsPro.WgApiClient\WotBlitzStatisticsPro.WgApiClient.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,16 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using WotBlitzStatisticsPro.WgApiClient;
|
||||
|
||||
namespace WotBlitzStatistics.Logic
|
||||
{
|
||||
public static class WotBlitzStatisticsLogicInstaller
|
||||
{
|
||||
public static void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddAutoMapper(typeof(WotBlitzStatisticsLogicInstaller));
|
||||
services.AddHttpClient<IWargamingApiClient, WargamingApiClient>();
|
||||
services.AddTransient<IWargamingSearch, WargamingSearch>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,13 +7,15 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WotBlitzStatisticsPro.UI",
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WotBlitzStatisticsPro.UI.Server", "WotBlitzStatisticsPro.UI.Server\WotBlitzStatisticsPro.UI.Server.csproj", "{132C4637-1C92-4A8E-BD26-CEC0EFA9D05A}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WotBlitzStatisticsPro.Common", "WotBlitzStatisticsPro.Common\WotBlitzStatisticsPro.Common.csproj", "{2802CC24-35D6-48CE-9BC4-7080F9335C88}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WotBlitzStatisticsPro.Common", "WotBlitzStatisticsPro.Common\WotBlitzStatisticsPro.Common.csproj", "{2802CC24-35D6-48CE-9BC4-7080F9335C88}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WotBlitzStatisticsPro.UI.Wasm", "WotBlitzStatisticsPro.Wasm\WotBlitzStatisticsPro.UI.Wasm.csproj", "{57E96A78-BDA4-4023-9965-EC755C68D033}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WotBlitzStatisticsPro.UI.Wasm", "WotBlitzStatisticsPro.Wasm\WotBlitzStatisticsPro.UI.Wasm.csproj", "{57E96A78-BDA4-4023-9965-EC755C68D033}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WotBlitzStatistics.GraphQl", "WotBlitzStatistics.GraphQl\WotBlitzStatistics.GraphQl.csproj", "{9B268E2D-38A5-4755-BAEC-BAF1DC7DCEC7}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WotBlitzStatistics.GraphQl", "WotBlitzStatistics.GraphQl\WotBlitzStatistics.GraphQl.csproj", "{9B268E2D-38A5-4755-BAEC-BAF1DC7DCEC7}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WotBlitzStatisticsPro.WgApiClient", "WotBlitzStatisticsPro.WgApiClient\WotBlitzStatisticsPro.WgApiClient.csproj", "{E1AB7997-C2A1-433B-A4F5-F8E9C4B73515}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WotBlitzStatisticsPro.WgApiClient", "WotBlitzStatisticsPro.WgApiClient\WotBlitzStatisticsPro.WgApiClient.csproj", "{E1AB7997-C2A1-433B-A4F5-F8E9C4B73515}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WotBlitzStatistics.Logic", "WotBlitzStatistics.Logic\WotBlitzStatistics.Logic.csproj", "{0E04D1C0-DFB9-4BD3-B540-DD207358850C}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@@ -45,6 +47,10 @@ Global
|
||||
{E1AB7997-C2A1-433B-A4F5-F8E9C4B73515}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{E1AB7997-C2A1-433B-A4F5-F8E9C4B73515}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{E1AB7997-C2A1-433B-A4F5-F8E9C4B73515}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{0E04D1C0-DFB9-4BD3-B540-DD207358850C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{0E04D1C0-DFB9-4BD3-B540-DD207358850C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{0E04D1C0-DFB9-4BD3-B540-DD207358850C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{0E04D1C0-DFB9-4BD3-B540-DD207358850C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
Reference in new issue
Block a user