Added a-frame-architecture usiung wolverine sample.
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
using FinancialApi.Domain.Exceptions;
|
||||
|
||||
namespace FinancialApi.Domain.Entities;
|
||||
|
||||
public enum AccountType
|
||||
{
|
||||
Spend,
|
||||
Borrow,
|
||||
Revenue
|
||||
}
|
||||
|
||||
public record Account
|
||||
{
|
||||
public Account(int Id, decimal Balance, AccountType Type)
|
||||
{
|
||||
this.Id = Id;
|
||||
this.Balance = Balance;
|
||||
this.Type = Type;
|
||||
|
||||
if (Balance < 0 && Type is AccountType.Spend or AccountType.Revenue)
|
||||
{
|
||||
throw new InvalidStartingBalanceException("Insufficient funds.");
|
||||
}
|
||||
}
|
||||
|
||||
public Account ApplyPosting(decimal amount, EntryType entryType)
|
||||
{
|
||||
if (amount <= 0)
|
||||
{
|
||||
throw new ArgumentException("Amount must be positive.");
|
||||
}
|
||||
|
||||
var newBalance = entryType == EntryType.Credit ? Balance + amount : Balance - amount;
|
||||
|
||||
if (newBalance < 0 && Type is AccountType.Spend or AccountType.Revenue)
|
||||
{
|
||||
throw new InsufficientFundsException("Insufficient funds.");
|
||||
}
|
||||
|
||||
return this with { Balance = newBalance };
|
||||
}
|
||||
|
||||
public int Id { get; init; }
|
||||
public decimal Balance { get; init; }
|
||||
public AccountType Type { get; init; }
|
||||
|
||||
public void Deconstruct(out int Id, out decimal Balance, out AccountType Type)
|
||||
{
|
||||
Id = this.Id;
|
||||
Balance = this.Balance;
|
||||
Type = this.Type;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
namespace FinancialApi.Domain.Entities;
|
||||
|
||||
public record BalancedJournalEntry
|
||||
{
|
||||
public Guid Id { get; init; }
|
||||
public string Description { get; init; } = null!;
|
||||
public DateTimeOffset CreatedAt { get; init; }
|
||||
public List<JournalLine> Lines { get; init; } = [];
|
||||
|
||||
internal BalancedJournalEntry() { }
|
||||
|
||||
internal BalancedJournalEntry(Guid id, string description, DateTimeOffset createdAt, List<JournalLine> lines)
|
||||
{
|
||||
Lines = lines;
|
||||
Id = id;
|
||||
Description = description;
|
||||
CreatedAt = createdAt;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace FinancialApi.Domain.Entities;
|
||||
|
||||
public enum EntryType
|
||||
{
|
||||
Debit,
|
||||
Credit
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
namespace FinancialApi.Domain.Entities;
|
||||
|
||||
public record JournalLine(int AccountId, decimal Amount, EntryType Type);
|
||||
Reference in New Issue
Block a user