mirror of
https://github.com/DrMboga/WotBlitzStatisticsBlazor.git
synced 2026-10-23 19:30:06 +02:00
Account db read operation
This commit is contained in:
1 parent
91f69a6e39
commit
1c803585e1
7 files changed
+61
-5
No files matched your search
@@ -1,7 +1,10 @@
|
|||||||
namespace WotBlitzStatisticsPro.DataAccess
|
using System.Threading.Tasks;
|
||||||
|
using WotBlitzStatisticsPro.DataAccess.Model.Accounts;
|
||||||
|
|
||||||
|
namespace WotBlitzStatisticsPro.DataAccess
|
||||||
{
|
{
|
||||||
public interface IWargamingAccountDataAccessor
|
public interface IWargamingAccountDataAccessor
|
||||||
{
|
{
|
||||||
|
Task<AccountInfo> ReadAccountInfo(long accountId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using MongoDB.Driver;
|
using System.Threading.Tasks;
|
||||||
|
using MongoDB.Driver;
|
||||||
using WotBlitzStatisticsPro.Common;
|
using WotBlitzStatisticsPro.Common;
|
||||||
using WotBlitzStatisticsPro.DataAccess.Model.Accounts;
|
using WotBlitzStatisticsPro.DataAccess.Model.Accounts;
|
||||||
|
|
||||||
@@ -63,6 +64,11 @@ namespace WotBlitzStatisticsPro.DataAccess
|
|||||||
.CreateOne(tankInfoHistoryIndexModel);
|
.CreateOne(tankInfoHistoryIndexModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToDo: Read account
|
public async Task<AccountInfo> ReadAccountInfo(long accountId)
|
||||||
|
{
|
||||||
|
var account = await _database.GetCollection<AccountInfo>(AccountInfoCollectionName)
|
||||||
|
.FindAsync(Builders<AccountInfo>.Filter.Where(a => a.AccountId == accountId));
|
||||||
|
return account.FirstOrDefault();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+2
@@ -31,5 +31,7 @@ namespace WotBlitzStatisticsPro.Logic.AccountInformationPipeline
|
|||||||
|
|
||||||
public AccountInfoResponse Response { get; set; }
|
public AccountInfoResponse Response { get; set; }
|
||||||
|
|
||||||
|
public AccountInfo DbAccountInfo { get; set; }
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using WotBlitzStatisticsPro.Logic.Pipeline;
|
||||||
|
|
||||||
|
namespace WotBlitzStatisticsPro.Logic.AccountInformationPipeline.Operations
|
||||||
|
{
|
||||||
|
public class CheckLAstBattleDateOperation : IOperation<AccountInformationPipelineContext>
|
||||||
|
{
|
||||||
|
public Task Invoke(AccountInformationPipelineContext context, Func<AccountInformationPipelineContext, Task> next)
|
||||||
|
{
|
||||||
|
if (context.DbAccountInfo == null ||
|
||||||
|
context.DbAccountInfo.LastBattleTime >= context.AccountInfo.LastBattleTime)
|
||||||
|
{
|
||||||
|
return next.Invoke(context);
|
||||||
|
}
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+23
@@ -0,0 +1,23 @@
|
|||||||
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using WotBlitzStatisticsPro.DataAccess;
|
||||||
|
using WotBlitzStatisticsPro.Logic.Pipeline;
|
||||||
|
|
||||||
|
namespace WotBlitzStatisticsPro.Logic.AccountInformationPipeline.Operations
|
||||||
|
{
|
||||||
|
public class ReadAccountInfoFromDbOperation : IOperation<AccountInformationPipelineContext>
|
||||||
|
{
|
||||||
|
private readonly IWargamingAccountDataAccessor _accountDataAccessor;
|
||||||
|
|
||||||
|
public ReadAccountInfoFromDbOperation(IWargamingAccountDataAccessor accountDataAccessor)
|
||||||
|
{
|
||||||
|
_accountDataAccessor = accountDataAccessor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task Invoke(AccountInformationPipelineContext context, Func<AccountInformationPipelineContext, Task> next)
|
||||||
|
{
|
||||||
|
context.DbAccountInfo = await _accountDataAccessor.ReadAccountInfo(context.AccountId);
|
||||||
|
await next.Invoke(context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -39,7 +39,8 @@ namespace WotBlitzStatisticsPro.Logic
|
|||||||
var pipeline = new Pipeline<AccountInformationPipelineContext>(_operationFactory);
|
var pipeline = new Pipeline<AccountInformationPipelineContext>(_operationFactory);
|
||||||
|
|
||||||
pipeline.AddOperation<GetAccountInfoOperation>()
|
pipeline.AddOperation<GetAccountInfoOperation>()
|
||||||
// ToDo: add operation for reading AccountFrom DB
|
.AddOperation<ReadAccountInfoFromDbOperation>()
|
||||||
|
.AddOperation<CheckLAstBattleDateOperation>()
|
||||||
.AddOperation<GetTanksInfoOperation>()
|
.AddOperation<GetTanksInfoOperation>()
|
||||||
.AddOperation<CalculateStatisticsOperation>()
|
.AddOperation<CalculateStatisticsOperation>()
|
||||||
// ToDo: add operation for save info into DB
|
// ToDo: add operation for save info into DB
|
||||||
|
|||||||
@@ -60,6 +60,8 @@ namespace WotBlitzStatisticsPro.Logic
|
|||||||
private static void ConfigureOperationsFactory(IServiceCollection services)
|
private static void ConfigureOperationsFactory(IServiceCollection services)
|
||||||
{
|
{
|
||||||
services.AddTransient<GetAccountInfoOperation>();
|
services.AddTransient<GetAccountInfoOperation>();
|
||||||
|
services.AddTransient<ReadAccountInfoFromDbOperation>();
|
||||||
|
services.AddTransient<CheckLAstBattleDateOperation>();
|
||||||
services.AddTransient<GetTanksInfoOperation>();
|
services.AddTransient<GetTanksInfoOperation>();
|
||||||
services.AddTransient<CalculateStatisticsOperation>();
|
services.AddTransient<CalculateStatisticsOperation>();
|
||||||
services.AddTransient<BuildAccountInfoResponseOperation>();
|
services.AddTransient<BuildAccountInfoResponseOperation>();
|
||||||
|
|||||||
Reference in new issue
Block a user