refactor(app): implement year filter for account entries and update related services

This commit is contained in:
2026-04-03 14:11:42 +02:00
parent 08185f88cd
commit 4636acf7b0
11 changed files with 196 additions and 42 deletions

View File

@@ -13,14 +13,20 @@ public class EntryService : IEntryService
public EntryService(IDbContextFactory<FinanceDbContext> dbFactory) => _dbFactory = dbFactory;
public async Task<List<EntryDto>> GetEntriesAsync(int accountId, bool currentYearOnly)
public Task<List<EntryDto>> GetEntriesAsync(int accountId, bool currentYearOnly)
{
var year = currentYearOnly ? DateTime.Now.Year : (int?)null;
return GetEntriesAsync(accountId, year);
}
public async Task<List<EntryDto>> GetEntriesAsync(int accountId, int? year)
{
await using var db = await _dbFactory.CreateDbContextAsync();
var query = db.Entries.Where(e => e.AccountId == accountId);
if (currentYearOnly)
query = query.Where(e => e.Date.Year == DateTime.Now.Year);
if (year.HasValue)
query = query.Where(e => e.Date.Year == year.Value);
var entries = await query
.OrderBy(e => e.Date)
@@ -59,6 +65,18 @@ public class EntryService : IEntryService
}).ToList();
}
public async Task<List<int>> GetEntryYearsAsync(int accountId)
{
await using var db = await _dbFactory.CreateDbContextAsync();
return await db.Entries
.Where(e => e.AccountId == accountId)
.Select(e => e.Date.Year)
.Distinct()
.OrderByDescending(y => y)
.ToListAsync();
}
public async Task<EntryDto> CreateEntryAsync(int accountId, EntryType type, DateTime date, string title, decimal amount)
{
await using var db = await _dbFactory.CreateDbContextAsync();