Updated ef migrations.

This commit is contained in:
2026-07-29 13:03:30 +02:00
parent 44846eaa13
commit acc8423fc6
10 changed files with 410 additions and 22 deletions
@@ -8,8 +8,20 @@ public enum AccountType
Revenue
}
public record Account(int Id, decimal Balance, AccountType Type)
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.Liability or AccountType.Debit or AccountType.Revenue)
{
throw new InvalidStartingBalanceException("Insufficient funds.");
}
}
public Account ApplyPosting(decimal amount, EntryType entryType)
{
if (amount <= 0)
@@ -18,7 +30,6 @@ public record Account(int Id, decimal Balance, AccountType Type)
}
var newBalance = entryType == EntryType.Credit ? Balance + amount : Balance - amount;
;
if (newBalance < 0 && Type is AccountType.Liability or AccountType.Debit or AccountType.Revenue)
{
@@ -27,6 +38,15 @@ public record Account(int Id, decimal Balance, AccountType Type)
return this with { Balance = newBalance };
}
}
public class InsufficientFundsException(string insufficientFunds) : Exception(insufficientFunds);
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,3 @@
namespace FinancialApi.Domain.Entities;
public class InsufficientFundsException(string message) : Exception(message);
@@ -0,0 +1,3 @@
namespace FinancialApi.Domain.Entities;
public class InvalidStartingBalanceException(string message) : Exception(message);