Files
WotBlitzStatisticsBlazor/WotBlitzStatisticsPro.Logic/AccountInformationPipeline/Operations/GetAccountInfoOperation.cs
T

52 lines
2.1 KiB
C#
Raw Normal View History

2020-07-19 13:04:31 +02:00
using System;
using System.Threading.Tasks;
2020-08-20 13:40:08 +02:00
using AutoMapper;
2020-12-27 12:39:25 +01:00
using Microsoft.Extensions.Logging;
2020-08-20 13:40:08 +02:00
using WotBlitzStatisticsPro.DataAccess.Model.Accounts;
2020-11-17 12:36:02 +01:00
using WotBlitzStatisticsPro.Logic.AccountInformationPipeline.OperationContext;
2020-07-19 13:04:31 +02:00
using WotBlitzStatisticsPro.Logic.Pipeline;
2020-08-20 13:40:08 +02:00
using WotBlitzStatisticsPro.WgApiClient;
using WotBlitzStatisticsPro.WgApiClient.Model;
2020-07-19 13:04:31 +02:00
namespace WotBlitzStatisticsPro.Logic.AccountInformationPipeline.Operations
{
2020-11-17 12:36:02 +01:00
public class GetAccountInfoOperation: IOperation<IOperationContext>
2020-07-19 13:04:31 +02:00
{
2020-08-20 13:40:08 +02:00
private readonly IWargamingApiClient _wargamingApi;
private readonly IMapper _mapper;
2020-12-27 12:39:25 +01:00
private readonly ILogger<GetAccountInfoOperation> _logger;
2020-08-20 13:40:08 +02:00
public GetAccountInfoOperation(
IWargamingApiClient wargamingApi,
2020-12-27 12:39:25 +01:00
IMapper mapper,
ILogger<GetAccountInfoOperation> logger)
2020-07-19 13:04:31 +02:00
{
2020-08-20 13:40:08 +02:00
_wargamingApi = wargamingApi;
_mapper = mapper;
2020-12-27 12:39:25 +01:00
_logger = logger;
2020-08-20 13:40:08 +02:00
}
2020-12-27 12:39:25 +01:00
public async Task Invoke(IOperationContext context, Func<IOperationContext, Task>? next)
2020-08-20 13:40:08 +02:00
{
var accountInfo = await
2020-11-17 12:36:02 +01:00
_wargamingApi.GetPlayerAccountInfo(context.Request.AccountId, context.Request.RealmType, context.Request.RequestLanguage);
2020-08-20 13:40:08 +02:00
2020-12-27 12:39:25 +01:00
if (accountInfo == null)
{
_logger.LogInformation(
$"Account not found for AccountId {context.Request.AccountId} and {context.Request.RealmType} realm");
return;
}
2020-08-20 13:40:08 +02:00
// Store info to AccountInfo and in AccountInfoHistory
2020-11-17 12:36:02 +01:00
var contextData = context.Get<AccountInformationPipelineContextData>();
contextData.AccountInfo = _mapper.Map<WotAccountInfo, AccountInfo>(accountInfo);
contextData.AccountInfo.Realm = context.Request.RealmType;
2020-08-20 13:40:08 +02:00
2020-11-17 12:36:02 +01:00
contextData.AccountInfoHistory = new AccountInfoHistory(context.Request.AccountId, contextData.AccountInfo.LastBattleTime);
2020-12-27 12:39:25 +01:00
_mapper.Map(accountInfo.Statistics?.All, contextData.AccountInfoHistory);
2020-08-20 13:40:08 +02:00
2020-12-27 12:39:25 +01:00
if (next != null) await next.Invoke(context);
2020-07-19 13:04:31 +02:00
}
}
}