sync public allowlist from private myoffice
This commit is contained in:
@@ -1,22 +0,0 @@
|
||||
namespace MyOffice.Data.Repositories.Currency;
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Models.Currencies;
|
||||
using MyOffice.DbContext;
|
||||
|
||||
public class CurrencyGlobalRepository : AppRepository<CurrencyGlobal>, ICurrencyGlobalRepository
|
||||
{
|
||||
public CurrencyGlobalRepository(AppDbContext context) : base(context)
|
||||
{
|
||||
}
|
||||
|
||||
public List<CurrencyGlobal> GetAll()
|
||||
{
|
||||
return _context.CurrencyGlobals.ToList();
|
||||
}
|
||||
|
||||
public async Task<List<CurrencyGlobal>> GetAllAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return await _context.CurrencyGlobals.ToListAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
@@ -1,115 +0,0 @@
|
||||
namespace MyOffice.Data.Repositories.Currency;
|
||||
|
||||
using System.Xml.Schema;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Models.Currencies;
|
||||
using MyOffice.DbContext;
|
||||
|
||||
public class CurrencyRateRepository : AppRepository<CurrencyRate>, ICurrencyRateRepository
|
||||
{
|
||||
public CurrencyRateRepository(AppDbContext context) : base(context)
|
||||
{
|
||||
}
|
||||
|
||||
public List<CurrencyRate> GetLastRates(Guid currencyId, DateTime? before = null, int count = 1)
|
||||
{
|
||||
before = before ?? DateTime.UtcNow;
|
||||
|
||||
return _context.CurrencyRates
|
||||
.Where(x => x.CurrencyId == currencyId)
|
||||
.Where(x => x.DateTime <= before)
|
||||
.OrderByDescending(x => x.DateTime)
|
||||
.ThenByDescending(x => x.Id)
|
||||
.Take(count)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public async Task<List<CurrencyRate>> GetLastRatesAsync(
|
||||
Guid currencyId,
|
||||
DateTime? before = null,
|
||||
int count = 1,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
before ??= DateTime.UtcNow;
|
||||
|
||||
return await _context.CurrencyRates
|
||||
.Where(x => x.CurrencyId == currencyId)
|
||||
.Where(x => x.DateTime <= before)
|
||||
.OrderByDescending(x => x.DateTime)
|
||||
.ThenByDescending(x => x.Id)
|
||||
.Take(count)
|
||||
.ToListAsync(cancellationToken);
|
||||
}
|
||||
|
||||
public Dictionary<string, CurrencyRate> GetLastRates(Guid userId, List<string> currencyIds, DateTime? before = null)
|
||||
{
|
||||
return _context.CurrencyRates
|
||||
.Include(x => x.Currency)
|
||||
.Include(x => x.Currency!.CurrencyGlobal)
|
||||
.Where(x => x.DateTime <= before)
|
||||
.Where(x => x.Currency!.UserId == userId)
|
||||
.Where(x => currencyIds.Contains(x.Currency!.CurrencyGlobalId))
|
||||
.GroupBy(x => new
|
||||
{
|
||||
x.Currency!.CurrencyGlobalId
|
||||
}, (key, g) => new
|
||||
{
|
||||
key.CurrencyGlobalId,
|
||||
rate = g.OrderByDescending(x => x.DateTime).First()
|
||||
})
|
||||
.ToDictionary(x => x.CurrencyGlobalId, x => x.rate);
|
||||
}
|
||||
|
||||
public async Task<Dictionary<string, CurrencyRate>> GetLastRatesAsync(
|
||||
Guid userId,
|
||||
List<string> currencyIds,
|
||||
DateTime? before = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
var rows = await _context.CurrencyRates
|
||||
.Include(x => x.Currency)
|
||||
.Include(x => x.Currency!.CurrencyGlobal)
|
||||
.Where(x => x.DateTime <= before)
|
||||
.Where(x => x.Currency!.UserId == userId)
|
||||
.Where(x => currencyIds.Contains(x.Currency!.CurrencyGlobalId))
|
||||
.GroupBy(x => new
|
||||
{
|
||||
x.Currency!.CurrencyGlobalId
|
||||
}, (key, g) => new
|
||||
{
|
||||
key.CurrencyGlobalId,
|
||||
rate = g.OrderByDescending(x => x.DateTime).First()
|
||||
})
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
return rows.ToDictionary(x => x.CurrencyGlobalId, x => x.rate);
|
||||
}
|
||||
|
||||
public bool AddRate(CurrencyRate currencyRate)
|
||||
{
|
||||
return this.AddBase(currencyRate) > 0;
|
||||
}
|
||||
|
||||
public async Task<bool> AddRateAsync(CurrencyRate currencyRate, CancellationToken cancellationToken = default)
|
||||
{
|
||||
return await AddBaseAsync(currencyRate, cancellationToken) > 0;
|
||||
}
|
||||
|
||||
public List<CurrencyRate> GetAtDate(Guid currencyId, DateTime date)
|
||||
{
|
||||
return _context.CurrencyRates
|
||||
.Where(x => x.CurrencyId == currencyId && x.DateTime == date)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public async Task<List<CurrencyRate>> GetAtDateAsync(
|
||||
Guid currencyId,
|
||||
DateTime date,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
return await _context.CurrencyRates
|
||||
.Where(x => x.CurrencyId == currencyId && x.DateTime == date)
|
||||
.ToListAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
@@ -1,102 +0,0 @@
|
||||
namespace MyOffice.Data.Repositories.Currency;
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Models.Currencies;
|
||||
using MyOffice.Data.Repositories;
|
||||
using MyOffice.DbContext;
|
||||
|
||||
public class CurrencyRepository : AppRepository<Currency>, ICurrencyRepository
|
||||
{
|
||||
public CurrencyRepository(AppDbContext context) : base(context)
|
||||
{
|
||||
}
|
||||
|
||||
public List<Currency> GetAll(Guid userId)
|
||||
{
|
||||
return _context.Currencies
|
||||
.Include(x => x.CurrencyGlobal)
|
||||
.Where(x => x.UserId == userId)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public async Task<List<Currency>> GetAllAsync(Guid userId, CancellationToken cancellationToken = default)
|
||||
{
|
||||
return await _context.Currencies
|
||||
.Include(x => x.CurrencyGlobal)
|
||||
.Where(x => x.UserId == userId)
|
||||
.ToListAsync(cancellationToken);
|
||||
}
|
||||
|
||||
public Currency? Get(Guid userId, Guid id)
|
||||
{
|
||||
return _context
|
||||
.Currencies
|
||||
.Include(x => x.CurrencyGlobal)
|
||||
.FirstOrDefault(x => x.Id == id && x.UserId == userId);
|
||||
}
|
||||
|
||||
public async Task<Currency?> GetAsync(Guid userId, Guid id, CancellationToken cancellationToken = default)
|
||||
{
|
||||
return await _context
|
||||
.Currencies
|
||||
.Include(x => x.CurrencyGlobal)
|
||||
.FirstOrDefaultAsync(x => x.Id == id && x.UserId == userId, cancellationToken);
|
||||
}
|
||||
|
||||
public Currency? GetByGlobalCurrency(Guid userId, string globalCurrencyId)
|
||||
{
|
||||
return _context.Currencies.FirstOrDefault(x => x.UserId == userId && x.CurrencyGlobalId == globalCurrencyId);
|
||||
}
|
||||
|
||||
public async Task<Currency?> GetByGlobalCurrencyAsync(
|
||||
Guid userId,
|
||||
string globalCurrencyId,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
return await _context.Currencies.FirstOrDefaultAsync(
|
||||
x => x.UserId == userId && x.CurrencyGlobalId == globalCurrencyId,
|
||||
cancellationToken);
|
||||
}
|
||||
|
||||
public bool Add(Currency currency)
|
||||
{
|
||||
return AddBase(currency) > 0;
|
||||
}
|
||||
|
||||
public async Task<bool> AddAsync(Currency currency, CancellationToken cancellationToken = default)
|
||||
{
|
||||
return await AddBaseAsync(currency, cancellationToken) > 0;
|
||||
}
|
||||
|
||||
public bool Update(Currency currency)
|
||||
{
|
||||
return UpdateBase(currency) > 0;
|
||||
}
|
||||
|
||||
public async Task<bool> UpdateAsync(Currency currency, CancellationToken cancellationToken = default)
|
||||
{
|
||||
return await UpdateBaseAsync(currency, cancellationToken) > 0;
|
||||
}
|
||||
|
||||
public bool Remove(Currency currency)
|
||||
{
|
||||
return RemoveBase(currency) > 0;
|
||||
}
|
||||
|
||||
public async Task<bool> RemoveAsync(Currency currency, CancellationToken cancellationToken = default)
|
||||
{
|
||||
return await RemoveBaseAsync(currency, cancellationToken) > 0;
|
||||
}
|
||||
|
||||
public List<Currency> GetPrimaries(Guid userId)
|
||||
{
|
||||
return _context.Currencies.Where(x => x.UserId == userId && x.IsPrimary).ToList();
|
||||
}
|
||||
|
||||
public async Task<List<Currency>> GetPrimariesAsync(Guid userId, CancellationToken cancellationToken = default)
|
||||
{
|
||||
return await _context.Currencies
|
||||
.Where(x => x.UserId == userId && x.IsPrimary)
|
||||
.ToListAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
namespace MyOffice.Data.Repositories.Currency;
|
||||
|
||||
using Models.Currencies;
|
||||
|
||||
public interface ICurrencyGlobalRepository
|
||||
{
|
||||
List<CurrencyGlobal> GetAll();
|
||||
Task<List<CurrencyGlobal>> GetAllAsync(CancellationToken cancellationToken = default);
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
namespace MyOffice.Data.Repositories.Currency;
|
||||
|
||||
using Models.Currencies;
|
||||
|
||||
public interface ICurrencyRateRepository
|
||||
{
|
||||
List<CurrencyRate> GetLastRates(Guid currencyId, DateTime? before = null, int count = 1);
|
||||
Task<List<CurrencyRate>> GetLastRatesAsync(Guid currencyId, DateTime? before = null, int count = 1, CancellationToken cancellationToken = default);
|
||||
Dictionary<string, CurrencyRate> GetLastRates(Guid userId, List<string> currencyIds, DateTime? before = null);
|
||||
Task<Dictionary<string, CurrencyRate>> GetLastRatesAsync(
|
||||
Guid userId,
|
||||
List<string> currencyIds,
|
||||
DateTime? before = null,
|
||||
CancellationToken cancellationToken = default);
|
||||
bool AddRate(CurrencyRate currencyRate);
|
||||
Task<bool> AddRateAsync(CurrencyRate currencyRate, CancellationToken cancellationToken = default);
|
||||
List<CurrencyRate> GetAtDate(Guid currencyId, DateTime date);
|
||||
Task<List<CurrencyRate>> GetAtDateAsync(Guid currencyId, DateTime date, CancellationToken cancellationToken = default);
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
namespace MyOffice.Data.Repositories.Currency;
|
||||
|
||||
using Models.Currencies;
|
||||
|
||||
public interface ICurrencyRepository
|
||||
{
|
||||
List<Currency> GetAll(Guid userId);
|
||||
Task<List<Currency>> GetAllAsync(Guid userId, CancellationToken cancellationToken = default);
|
||||
Currency? Get(Guid userId, Guid id);
|
||||
Task<Currency?> GetAsync(Guid userId, Guid id, CancellationToken cancellationToken = default);
|
||||
Currency? GetByGlobalCurrency(Guid userId, string globalCurrencyId);
|
||||
Task<Currency?> GetByGlobalCurrencyAsync(Guid userId, string globalCurrencyId, CancellationToken cancellationToken = default);
|
||||
bool Add(Currency currency);
|
||||
Task<bool> AddAsync(Currency currency, CancellationToken cancellationToken = default);
|
||||
bool Update(Currency currency);
|
||||
Task<bool> UpdateAsync(Currency currency, CancellationToken cancellationToken = default);
|
||||
bool Remove(Currency currency);
|
||||
Task<bool> RemoveAsync(Currency currency, CancellationToken cancellationToken = default);
|
||||
List<Currency> GetPrimaries(Guid userId);
|
||||
Task<List<Currency>> GetPrimariesAsync(Guid userId, CancellationToken cancellationToken = default);
|
||||
}
|
||||
Reference in New Issue
Block a user