chore: Account search extended

This commit is contained in:
Mikhail Shabanov committed 2021-05-12 16:30:23 +02:00
1 parent 4ff19d7f21
commit 1d0ab97b35
5 files changed
+131 -8

No files matched your search

+51 -5
View File
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using AutoMapper;
using WotBlitzStatisticsPro.Common.Model;
@@ -23,18 +24,63 @@ namespace WotBlitzStatisticsPro.Logic
RealmType realmType,
RequestLanguage language)
{
var response = await _wargamingApiClient.FindAccounts(accountNick, realmType, language);
var searchResponse = await _wargamingApiClient.FindAccounts(accountNick, realmType, language);
if (response == null)
if (searchResponse == null)
{
return new AccountsSearchResponse();
}
return new AccountsSearchResponse
var response = new AccountsSearchResponse
{
AccountsCount = response.Count,
Accounts = _mapper.Map<List<WotAccountListResponse>, List<AccountsSearchResponseItem>>(response)
AccountsCount = searchResponse.Count,
Accounts = _mapper.Map<List<WotAccountListResponse>, List<AccountsSearchResponseItem>>(searchResponse)
};
if (searchResponse.Count > 100)
{
return response;
}
var accountIds = response.Accounts.Select(a => a.AccountId).ToArray();
var shortAccountInfos =
await _wargamingApiClient.GetShortPlayerAccountsInfo(accountIds, realmType, language);
var accountClans = await _wargamingApiClient.GetBulkPlayerClans(accountIds, realmType, language);
List<ClanInfo>? clans = null;
if (accountClans != null)
{
clans = await _wargamingApiClient.GetShortClansInfo(accountClans.Where(c => c.ClanId.HasValue).Select(c => c.ClanId!.Value).ToArray(),
realmType, language);
}
for (int i = 0; i < response.Accounts.Count; i++)
{
var accountResponse = response.Accounts.ToArray()[i];
var shortAccountInfo = shortAccountInfos?.FirstOrDefault(a => a.AccountId == accountResponse.AccountId);
if (shortAccountInfo != null)
{
_mapper.Map(shortAccountInfo, accountResponse);
}
// Clan
if (accountClans != null && clans != null)
{
var aClan = accountClans.FirstOrDefault(c => c.AccountId == accountResponse.AccountId);
var clan = clans.FirstOrDefault(c => c.ClanId == aClan?.ClanId);
if (clan != null)
{
accountResponse.ClanTag = clan.Tag;
}
}
}
// Filter WOT Blitz accounts
response.Accounts = response.Accounts.Where(a => a.BattlesCount > 0).ToList();
response.AccountsCount = response.Accounts.Count;
return response;
}
public async Task<ClanSearchResponse> FindClans(