Files
silver-octo-spoon/wolverine/a-frame-architecture/FinancialApi.Infrastructure/ReversalQuery.cs
T

32 lines
1001 B
C#

using FinancialApi.Application.Commands;
using FinancialApi.Application.Handlers;
using FinancialApi.Application.Interfaces;
using FinancialApi.Application.Models;
using Microsoft.EntityFrameworkCore;
namespace FinancialApi.Infrastructure;
public class ReversalQuery(AccountDbContext db, TimeProvider timeProvider) : IReversalQuery
{
public async Task<JournalReversalContext?> GetReversalDataAsync(Guid journalEntryId)
{
var entry = await db.JournalEntries.Include(x => x.Lines)
.AsNoTracking()
.FirstOrDefaultAsync(x => x.Id == journalEntryId);
if (entry == null)
{
return null;
}
var accountIds = entry.Lines.Select(l => l.AccountId)
.Distinct()
.ToList();
var accounts = await db.Accounts.AsNoTracking()
.Where(a => accountIds.Contains(a.Id))
.ToListAsync();
return new JournalReversalContext(entry, accounts, timeProvider.GetUtcNow());
}
}