2020-05-29 23:03:32 +02:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2020-05-23 10:44:04 +02:00
|
|
|
using System.Threading.Tasks;
|
2022-07-22 10:01:45 +02:00
|
|
|
using AutoMapper;
|
2020-12-27 17:20:57 +01:00
|
|
|
using Microsoft.Extensions.Logging;
|
2022-07-22 10:01:45 +02:00
|
|
|
using WotBlitzStatisticsPro.Common.Dictionaries;
|
2020-05-21 17:53:01 +02:00
|
|
|
using WotBlitzStatisticsPro.Common.Model;
|
2022-07-22 10:01:45 +02:00
|
|
|
using WotBlitzStatisticsPro.DataAccess;
|
2020-05-29 23:03:32 +02:00
|
|
|
using WotBlitzStatisticsPro.Logic.Dictionaries;
|
2020-05-21 17:53:01 +02:00
|
|
|
|
2020-05-23 11:43:14 +02:00
|
|
|
namespace WotBlitzStatisticsPro.Logic
|
2020-05-21 17:53:01 +02:00
|
|
|
{
|
|
|
|
|
public class WargamingDictionaries: IWargamingDictionaries
|
|
|
|
|
{
|
2020-05-29 23:03:32 +02:00
|
|
|
private readonly DictionariesUpdaterResolver _dictionaryUpdaterFactoryMethod;
|
2022-07-22 10:01:45 +02:00
|
|
|
private readonly IDictionariesDataAccessor _dictionariesDataAccessor;
|
|
|
|
|
private readonly IMapper _mapper;
|
2020-12-27 17:20:57 +01:00
|
|
|
private readonly ILogger<WargamingDictionaries> _logger;
|
2020-05-29 23:03:32 +02:00
|
|
|
|
2022-07-22 10:01:45 +02:00
|
|
|
public WargamingDictionaries(
|
|
|
|
|
DictionariesUpdaterResolver dictionaryUpdaterFactoryMethod,
|
|
|
|
|
IDictionariesDataAccessor dictionariesDataAccessor,
|
|
|
|
|
ILogger<WargamingDictionaries> logger,
|
|
|
|
|
IMapper mapper)
|
2020-05-29 23:03:32 +02:00
|
|
|
{
|
|
|
|
|
_dictionaryUpdaterFactoryMethod = dictionaryUpdaterFactoryMethod;
|
2022-07-22 10:01:45 +02:00
|
|
|
_dictionariesDataAccessor = dictionariesDataAccessor;
|
2020-12-27 17:20:57 +01:00
|
|
|
_logger = logger;
|
2022-07-22 10:01:45 +02:00
|
|
|
_mapper = mapper;
|
2020-05-29 23:03:32 +02:00
|
|
|
}
|
2022-07-22 10:01:45 +02:00
|
|
|
|
|
|
|
|
public async Task<List<VehicleResponse>?> GetVehiclesByNation(string nationId, RequestLanguage? language)
|
|
|
|
|
{
|
|
|
|
|
language = language ?? RequestLanguage.En;
|
|
|
|
|
var vehicles = await _dictionariesDataAccessor.GetVehiclesByNation(nationId);
|
|
|
|
|
return _mapper.Map<List<IVehiclesDictionary>, List<VehicleResponse>>(vehicles, opts =>
|
|
|
|
|
{
|
|
|
|
|
opts.Items["language"] = language;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-29 23:03:32 +02:00
|
|
|
public async Task<UpdateDictionariesResponseItem[]> UpdateDictionaries(UpdateDictionariesRequest updateDictionariesRequest)
|
2020-05-21 17:53:01 +02:00
|
|
|
{
|
2020-05-23 10:44:04 +02:00
|
|
|
var response = new List<UpdateDictionariesResponseItem>();
|
2020-05-29 23:03:32 +02:00
|
|
|
|
2020-12-27 17:20:57 +01:00
|
|
|
try
|
2020-05-21 17:53:01 +02:00
|
|
|
{
|
2020-12-27 17:20:57 +01:00
|
|
|
foreach (var dictionaryType in (DictionaryType[]) Enum.GetValues(typeof(DictionaryType)))
|
2020-05-29 23:03:32 +02:00
|
|
|
{
|
2020-12-27 17:20:57 +01:00
|
|
|
if ((updateDictionariesRequest.DictionaryTypes & dictionaryType) != 0)
|
2020-05-31 15:43:39 +02:00
|
|
|
{
|
2020-12-27 17:20:57 +01:00
|
|
|
var dictionaryUpdater = _dictionaryUpdaterFactoryMethod(dictionaryType);
|
|
|
|
|
if (dictionaryUpdater != null)
|
|
|
|
|
{
|
|
|
|
|
response.Add(await dictionaryUpdater.Update());
|
|
|
|
|
}
|
2020-05-31 15:43:39 +02:00
|
|
|
}
|
2020-05-29 23:03:32 +02:00
|
|
|
}
|
2020-05-21 17:53:01 +02:00
|
|
|
}
|
2020-12-27 17:20:57 +01:00
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(e, "UpdateDictionaries error");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
2020-05-23 10:44:04 +02:00
|
|
|
|
2020-05-29 23:03:32 +02:00
|
|
|
return response.ToArray();
|
2020-05-21 17:53:01 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|