Adjust location of classes further.
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
namespace FinancialApi.Domain.Entities;
|
||||
|
||||
public record Account(int Id, decimal Balance, string AccountType)
|
||||
{
|
||||
public Account ApplyPosting(decimal amount, EntryType entryType)
|
||||
{
|
||||
if (amount <= 0)
|
||||
{
|
||||
throw new ArgumentException("Credit amount must be positive.");
|
||||
}
|
||||
|
||||
var newBalance = Balance;
|
||||
if (AccountType == "Revenue")
|
||||
{
|
||||
newBalance = entryType == EntryType.Credit ? newBalance + amount : newBalance - amount;
|
||||
}
|
||||
else
|
||||
{
|
||||
newBalance = entryType == EntryType.Debit ? newBalance - amount : newBalance + amount;
|
||||
}
|
||||
|
||||
if (newBalance < 0 && AccountType == "Liability")
|
||||
{
|
||||
throw new InvalidOperationException("Insufficient funds.");
|
||||
}
|
||||
|
||||
return this with { Balance = newBalance };
|
||||
}
|
||||
|
||||
public Account Debit(decimal amount)
|
||||
{
|
||||
if (amount <= 0)
|
||||
{
|
||||
throw new ArgumentException("Debit amount must be positive.");
|
||||
}
|
||||
|
||||
if (Balance - amount < 0)
|
||||
{
|
||||
throw new InvalidOperationException("Insufficient funds.");
|
||||
}
|
||||
|
||||
return this with { Balance = Balance - amount };
|
||||
}
|
||||
|
||||
public Account Credit(decimal amount)
|
||||
{
|
||||
if (amount <= 0)
|
||||
{
|
||||
throw new ArgumentException("Credit amount must be positive.");
|
||||
}
|
||||
|
||||
return this with { Balance = Balance + amount };
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace FinancialApi.Domain.Entities;
|
||||
|
||||
public enum EntryType
|
||||
{
|
||||
Debit,
|
||||
Credit
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
namespace FinancialApi.Domain.Entities;
|
||||
|
||||
public record JournalEntry
|
||||
{
|
||||
public Guid Id { get; init; }
|
||||
public string Description { get; init; }
|
||||
public DateTimeOffset CreatedAt { get; init; }
|
||||
public List<JournalLine> Lines { get; init; } = [];
|
||||
|
||||
internal JournalEntry()
|
||||
{
|
||||
}
|
||||
|
||||
internal JournalEntry(Guid id, string description, DateTimeOffset createdAt, List<JournalLine> lines)
|
||||
{
|
||||
Lines = lines;
|
||||
Id = id;
|
||||
Description = description;
|
||||
CreatedAt = createdAt;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
namespace FinancialApi.Domain.Entities;
|
||||
|
||||
public record JournalLine(int AccountId, decimal Amount, EntryType Type);
|
||||
Reference in New Issue
Block a user