initial commit

This commit is contained in:
Kukks
2023-01-16 10:31:48 +01:00
parent 136273406c
commit 25ccd99558
171 changed files with 10592 additions and 0 deletions

View File

@@ -0,0 +1,51 @@
using System.Threading.Tasks;
using BTCPayServer.Abstractions.Contracts;
using Microsoft.Extensions.Caching.Memory;
namespace BTCPayServer.Plugins.AOPP
{
public class AOPPService
{
private readonly ISettingsRepository _settingsRepository;
private readonly IMemoryCache _memoryCache;
private readonly IStoreRepository _storeRepository;
public AOPPService(ISettingsRepository settingsRepository, IMemoryCache memoryCache,
IStoreRepository storeRepository)
{
_settingsRepository = settingsRepository;
_memoryCache = memoryCache;
_storeRepository = storeRepository;
}
public async Task<AOPPSettings> GetAOPPForStore(string storeId)
{
var k = $"{nameof(AOPPSettings)}_{storeId}";
return await _memoryCache.GetOrCreateAsync(k, async _ =>
{
var res = await _storeRepository.GetSettingAsync<AOPPSettings>(storeId,
nameof(AOPPSettings));
if (res is not null) return res;
res = await _settingsRepository.GetSettingAsync<AOPPSettings>(k);
if (res is not null)
{
await SetAOPPForStore(storeId, res);
}
await _settingsRepository.UpdateSetting<AOPPSettings>(null, k);
return res;
});
}
public async Task SetAOPPForStore(string storeId, AOPPSettings AOPPSettings)
{
var k = $"{nameof(AOPPSettings)}_{storeId}";
await _storeRepository.UpdateSetting(storeId, nameof(AOPPSettings), AOPPSettings);
_memoryCache.Set(k, AOPPSettings);
}
}
}