mirror of
https://github.com/DrMboga/WotBlitzStatisticsBlazor.git
synced 2026-10-21 02:17:20 +02:00
Preperation for savig account data
This commit is contained in:
1 parent
5e0369511f
commit
91f69a6e39
5 files changed
+75
-14
No files matched your search
@@ -1,5 +1,4 @@
|
||||
using System.Runtime.Serialization.Formatters;
|
||||
using MongoDB.Driver;
|
||||
using MongoDB.Driver;
|
||||
using WotBlitzStatisticsPro.Common;
|
||||
using WotBlitzStatisticsPro.DataAccess.Model.Accounts;
|
||||
|
||||
@@ -8,6 +7,9 @@ namespace WotBlitzStatisticsPro.DataAccess
|
||||
public class WargamingAccountDataAccessor : IWargamingAccountDataAccessor
|
||||
{
|
||||
private const string AccountInfoCollectionName = "account-info";
|
||||
private const string AccountInfoHistoryCollectionName = "account-info-history";
|
||||
private const string TankInfoCollectionName = "tank-info";
|
||||
private const string TankInfoHistoryCollectionName = "tank-info-history";
|
||||
|
||||
|
||||
private readonly IMongoDatabase _database;
|
||||
@@ -22,23 +24,45 @@ namespace WotBlitzStatisticsPro.DataAccess
|
||||
|
||||
private void CreateAccountIndexesIfNotExists()
|
||||
{
|
||||
// Account Info
|
||||
var accountInfoBuilder = Builders<AccountInfo>.IndexKeys;
|
||||
var accountInfoRealmIndexModel = new CreateIndexModel<AccountInfo>(accountInfoBuilder.Ascending(a => a.Realm));
|
||||
var accountInfoLastBattleTimeIndexModel = new CreateIndexModel<AccountInfo>(accountInfoBuilder.Descending(a => a.LastBattleTime));
|
||||
_database.GetCollection<AccountInfo>(AccountInfoCollectionName).Indexes
|
||||
.CreateMany(new[] {accountInfoRealmIndexModel, accountInfoLastBattleTimeIndexModel});
|
||||
|
||||
// AccountInfoHistory AccountId+LastBattleTime
|
||||
var accountInfoHistoryBuilder = Builders<AccountInfoHistory>.IndexKeys;
|
||||
var accountInfoHistoryIndexModel = new CreateIndexModel<AccountInfoHistory>(
|
||||
accountInfoHistoryBuilder.Combine(
|
||||
Builders<AccountInfoHistory>.IndexKeys.Ascending(h => h.AccountId),
|
||||
Builders<AccountInfoHistory>.IndexKeys.Ascending(h => h.LastBattleTime)));
|
||||
_database.GetCollection<AccountInfoHistory>(AccountInfoHistoryCollectionName).Indexes
|
||||
.CreateOne(accountInfoHistoryIndexModel);
|
||||
|
||||
/*
|
||||
// TankInfo AccountId+TankId, LastBattleTime
|
||||
var tankInfoBuilder = Builders<TankInfo>.IndexKeys;
|
||||
var tankInfoIndexModel = new CreateIndexModel<TankInfo>(
|
||||
tankInfoBuilder.Combine(
|
||||
Builders<TankInfo>.IndexKeys.Ascending(h => h.AccountId),
|
||||
Builders<TankInfo>.IndexKeys.Ascending(h => h.TankId)));
|
||||
var tankInfoLastBattleTimeIndexModel =
|
||||
new CreateIndexModel<TankInfo>(tankInfoBuilder.Ascending(t => t.LastBattleTime));
|
||||
_database.GetCollection<TankInfo>(TankInfoCollectionName).Indexes
|
||||
.CreateMany(new[] {tankInfoIndexModel, tankInfoLastBattleTimeIndexModel});
|
||||
|
||||
// Multiple keys
|
||||
var indexDefinition = Builders<FooDocument>.IndexKeys.Combine(
|
||||
Builders<FooDocument>.IndexKeys.Ascending(f => f.Key1),
|
||||
Builders<FooDocument>.IndexKeys.Ascending(f => f.Key2));
|
||||
|
||||
await collection.Indexes.CreateOneAsync(indexDefinition);
|
||||
*/
|
||||
|
||||
// TankInfoHistory AccountId+TankId+LastBattleTime
|
||||
var tankInfoHistoryBuilder = Builders<TankInfoHistory>.IndexKeys;
|
||||
var tankInfoHistoryIndexModel = new CreateIndexModel<TankInfoHistory>(
|
||||
tankInfoHistoryBuilder.Combine(
|
||||
Builders<TankInfoHistory>.IndexKeys.Ascending(h => h.AccountId),
|
||||
Builders<TankInfoHistory>.IndexKeys.Ascending(h => h.TankId),
|
||||
Builders<TankInfoHistory>.IndexKeys.Ascending(h => h.LastBattleTime)));
|
||||
_database.GetCollection<TankInfoHistory>(TankInfoHistoryCollectionName).Indexes
|
||||
.CreateOne(tankInfoHistoryIndexModel);
|
||||
}
|
||||
|
||||
// ToDo: Read account
|
||||
}
|
||||
}
|
||||
@@ -39,7 +39,7 @@ namespace WotBlitzStatisticsPro.GraphQl.Mutation
|
||||
/// <returns></returns>
|
||||
public Task<AccountInfoResponse> GatherAccountInformation(RealmType realmType, long accountId, RequestLanguage requestLanguage)
|
||||
{
|
||||
return _wargamingAccounts.GatherAccountInformation(realmType, accountId, requestLanguage);
|
||||
return _wargamingAccounts.GatherAndSaveAccountInformation(realmType, accountId, requestLanguage);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,10 +10,13 @@ namespace WotBlitzStatisticsPro.GraphQl.Query
|
||||
// 90277267 - Mboga Ru
|
||||
|
||||
private readonly IWargamingSearch _wargamingSearcher;
|
||||
private readonly IWargamingAccounts _wargamingAccounts;
|
||||
|
||||
public WotBlitzStatisticsQuery(IWargamingSearch wargamingSearcher)
|
||||
public WotBlitzStatisticsQuery(IWargamingSearch wargamingSearcher,
|
||||
IWargamingAccounts wargamingAccounts)
|
||||
{
|
||||
_wargamingSearcher = wargamingSearcher;
|
||||
_wargamingAccounts = wargamingAccounts;
|
||||
}
|
||||
|
||||
//public Task<AccountInfo> GetPlayerInfo(long accountId)
|
||||
@@ -50,5 +53,20 @@ namespace WotBlitzStatisticsPro.GraphQl.Query
|
||||
{
|
||||
return _wargamingSearcher.FindClans(searchString, realmType ?? RealmType.Ru, language ?? RequestLanguage.En);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gathers all account information
|
||||
/// </summary>
|
||||
/// <param name="realmType">Account region</param>
|
||||
/// <param name="accountId">AccountId</param>
|
||||
/// <param name="requestLanguage">Request language</param>
|
||||
public Task<AccountInfoResponse> AccountInfo(
|
||||
long accountId,
|
||||
RealmType? realmType,
|
||||
RequestLanguage? requestLanguage
|
||||
)
|
||||
{
|
||||
return _wargamingAccounts.GatherAccountInformation(realmType ?? RealmType.Ru, accountId, requestLanguage ?? RequestLanguage.En);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,5 +6,7 @@ namespace WotBlitzStatisticsPro.Logic
|
||||
public interface IWargamingAccounts
|
||||
{
|
||||
Task<AccountInfoResponse> GatherAccountInformation(RealmType realm, long accountId, RequestLanguage requestLanguage);
|
||||
|
||||
Task<AccountInfoResponse> GatherAndSaveAccountInformation(RealmType realm, long accountId, RequestLanguage requestLanguage);
|
||||
}
|
||||
}
|
||||
@@ -25,13 +25,30 @@ namespace WotBlitzStatisticsPro.Logic
|
||||
.AddOperation<CalculateStatisticsOperation>()
|
||||
.AddOperation<BuildAccountInfoResponseOperation>()
|
||||
;
|
||||
// ToDo: add other operations
|
||||
|
||||
await pipeline.Build()
|
||||
.Invoke(context, null)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
// ToDo: return context response
|
||||
return context.Response;
|
||||
}
|
||||
|
||||
public async Task<AccountInfoResponse> GatherAndSaveAccountInformation(RealmType realm, long accountId, RequestLanguage requestLanguage)
|
||||
{
|
||||
var context = new AccountInformationPipelineContext(accountId, realm, requestLanguage);
|
||||
var pipeline = new Pipeline<AccountInformationPipelineContext>(_operationFactory);
|
||||
|
||||
pipeline.AddOperation<GetAccountInfoOperation>()
|
||||
// ToDo: add operation for reading AccountFrom DB
|
||||
.AddOperation<GetTanksInfoOperation>()
|
||||
.AddOperation<CalculateStatisticsOperation>()
|
||||
// ToDo: add operation for save info into DB
|
||||
.AddOperation<BuildAccountInfoResponseOperation>()
|
||||
;
|
||||
|
||||
await pipeline.Build()
|
||||
.Invoke(context, null)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
return context.Response;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user