diff --git a/WotBlitzStatisticsPro.DataAccess/WargamingAccountDataAccessor.cs b/WotBlitzStatisticsPro.DataAccess/WargamingAccountDataAccessor.cs index dfea248..1ccad64 100644 --- a/WotBlitzStatisticsPro.DataAccess/WargamingAccountDataAccessor.cs +++ b/WotBlitzStatisticsPro.DataAccess/WargamingAccountDataAccessor.cs @@ -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.IndexKeys; var accountInfoRealmIndexModel = new CreateIndexModel(accountInfoBuilder.Ascending(a => a.Realm)); var accountInfoLastBattleTimeIndexModel = new CreateIndexModel(accountInfoBuilder.Descending(a => a.LastBattleTime)); _database.GetCollection(AccountInfoCollectionName).Indexes .CreateMany(new[] {accountInfoRealmIndexModel, accountInfoLastBattleTimeIndexModel}); + // AccountInfoHistory AccountId+LastBattleTime + var accountInfoHistoryBuilder = Builders.IndexKeys; + var accountInfoHistoryIndexModel = new CreateIndexModel( + accountInfoHistoryBuilder.Combine( + Builders.IndexKeys.Ascending(h => h.AccountId), + Builders.IndexKeys.Ascending(h => h.LastBattleTime))); + _database.GetCollection(AccountInfoHistoryCollectionName).Indexes + .CreateOne(accountInfoHistoryIndexModel); - /* + // TankInfo AccountId+TankId, LastBattleTime + var tankInfoBuilder = Builders.IndexKeys; + var tankInfoIndexModel = new CreateIndexModel( + tankInfoBuilder.Combine( + Builders.IndexKeys.Ascending(h => h.AccountId), + Builders.IndexKeys.Ascending(h => h.TankId))); + var tankInfoLastBattleTimeIndexModel = + new CreateIndexModel(tankInfoBuilder.Ascending(t => t.LastBattleTime)); + _database.GetCollection(TankInfoCollectionName).Indexes + .CreateMany(new[] {tankInfoIndexModel, tankInfoLastBattleTimeIndexModel}); -// Multiple keys -var indexDefinition = Builders.IndexKeys.Combine( -Builders.IndexKeys.Ascending(f => f.Key1), -Builders.IndexKeys.Ascending(f => f.Key2)); - -await collection.Indexes.CreateOneAsync(indexDefinition); - */ + // TankInfoHistory AccountId+TankId+LastBattleTime + var tankInfoHistoryBuilder = Builders.IndexKeys; + var tankInfoHistoryIndexModel = new CreateIndexModel( + tankInfoHistoryBuilder.Combine( + Builders.IndexKeys.Ascending(h => h.AccountId), + Builders.IndexKeys.Ascending(h => h.TankId), + Builders.IndexKeys.Ascending(h => h.LastBattleTime))); + _database.GetCollection(TankInfoHistoryCollectionName).Indexes + .CreateOne(tankInfoHistoryIndexModel); } + + // ToDo: Read account } } \ No newline at end of file diff --git a/WotBlitzStatisticsPro.GraphQl/Mutation/WotBlitzStatisticsMutation.cs b/WotBlitzStatisticsPro.GraphQl/Mutation/WotBlitzStatisticsMutation.cs index 1d46a42..eb49b3a 100644 --- a/WotBlitzStatisticsPro.GraphQl/Mutation/WotBlitzStatisticsMutation.cs +++ b/WotBlitzStatisticsPro.GraphQl/Mutation/WotBlitzStatisticsMutation.cs @@ -39,7 +39,7 @@ namespace WotBlitzStatisticsPro.GraphQl.Mutation /// public Task GatherAccountInformation(RealmType realmType, long accountId, RequestLanguage requestLanguage) { - return _wargamingAccounts.GatherAccountInformation(realmType, accountId, requestLanguage); + return _wargamingAccounts.GatherAndSaveAccountInformation(realmType, accountId, requestLanguage); } } } \ No newline at end of file diff --git a/WotBlitzStatisticsPro.GraphQl/Query/WotBlitzStatisticsQuery.cs b/WotBlitzStatisticsPro.GraphQl/Query/WotBlitzStatisticsQuery.cs index 7284ca0..b237b6c 100644 --- a/WotBlitzStatisticsPro.GraphQl/Query/WotBlitzStatisticsQuery.cs +++ b/WotBlitzStatisticsPro.GraphQl/Query/WotBlitzStatisticsQuery.cs @@ -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 GetPlayerInfo(long accountId) @@ -50,5 +53,20 @@ namespace WotBlitzStatisticsPro.GraphQl.Query { return _wargamingSearcher.FindClans(searchString, realmType ?? RealmType.Ru, language ?? RequestLanguage.En); } + + /// + /// Gathers all account information + /// + /// Account region + /// AccountId + /// Request language + public Task AccountInfo( + long accountId, + RealmType? realmType, + RequestLanguage? requestLanguage + ) + { + return _wargamingAccounts.GatherAccountInformation(realmType ?? RealmType.Ru, accountId, requestLanguage ?? RequestLanguage.En); + } } } diff --git a/WotBlitzStatisticsPro.Logic/IWargamingAccounts.cs b/WotBlitzStatisticsPro.Logic/IWargamingAccounts.cs index c49fe58..e28dc55 100644 --- a/WotBlitzStatisticsPro.Logic/IWargamingAccounts.cs +++ b/WotBlitzStatisticsPro.Logic/IWargamingAccounts.cs @@ -6,5 +6,7 @@ namespace WotBlitzStatisticsPro.Logic public interface IWargamingAccounts { Task GatherAccountInformation(RealmType realm, long accountId, RequestLanguage requestLanguage); + + Task GatherAndSaveAccountInformation(RealmType realm, long accountId, RequestLanguage requestLanguage); } } \ No newline at end of file diff --git a/WotBlitzStatisticsPro.Logic/WargamingAccounts.cs b/WotBlitzStatisticsPro.Logic/WargamingAccounts.cs index c4332be..0a399fc 100644 --- a/WotBlitzStatisticsPro.Logic/WargamingAccounts.cs +++ b/WotBlitzStatisticsPro.Logic/WargamingAccounts.cs @@ -25,13 +25,30 @@ namespace WotBlitzStatisticsPro.Logic .AddOperation() .AddOperation() ; - // ToDo: add other operations await pipeline.Build() .Invoke(context, null) .ConfigureAwait(false); - // ToDo: return context response + return context.Response; + } + + public async Task GatherAndSaveAccountInformation(RealmType realm, long accountId, RequestLanguage requestLanguage) + { + var context = new AccountInformationPipelineContext(accountId, realm, requestLanguage); + var pipeline = new Pipeline(_operationFactory); + + pipeline.AddOperation() + // ToDo: add operation for reading AccountFrom DB + .AddOperation() + .AddOperation() + // ToDo: add operation for save info into DB + .AddOperation() + ; + + await pipeline.Build() + .Invoke(context, null) + .ConfigureAwait(false); return context.Response; }