Encapsulated WG logic, added automapper, added realm and lang parameters

This commit is contained in:
Mikhail Shabanov committed 2020-05-18 17:29:54 +02:00
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);
}
}
}
+6 -2
View File
@@ -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>