Add Domain project and shifted handlers to application.
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
namespace FinancialApi.Domain;
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user