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 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()); } }