Adjust location of classes further.

This commit is contained in:
2026-07-17 17:10:28 +02:00
parent 69cb05f389
commit 29d179a23a
21 changed files with 82 additions and 56 deletions
@@ -0,0 +1,34 @@
using FinancialApi.Domain.Entities;
namespace FinancialApi.Domain.Aggregates;
public record BalancedJournal
{
public JournalEntry Entry { get; }
private BalancedJournal(JournalEntry entry) => Entry = entry;
public static BalancedJournal Create(Guid id, string description, DateTimeOffset createdAt, List<JournalLine> lines)
{
var debits = lines.Where(l => l.Type == EntryType.Debit).Sum(l => l.Amount);
var credits = lines.Where(l => l.Type == EntryType.Credit).Sum(l => l.Amount);
if (debits != credits)
{
throw new InvalidOperationException(
$"GAAP Violation: Total Debits ({debits}) must equal Total Credits ({credits})!"
);
}
return new(new JournalEntry(id, description, createdAt, lines));
}
public static BalancedJournal CreateReversal(JournalEntry original, string reason, DateTimeOffset now)
{
var reversedLines = original.Lines.Select(l =>
l with { Type = l.Type == EntryType.Debit ? EntryType.Credit : EntryType.Debit })
.ToList();
return Create(Guid.NewGuid(), reason, now, reversedLines);
}
}