Reformat all code as per my preferred formatting.
This commit is contained in:
+12
-20
@@ -11,9 +11,7 @@ namespace FinancialApi.Application.Handlers;
|
||||
|
||||
public static class ApplyFeeHandler
|
||||
{
|
||||
public static async Task<FeeContext> LoadAsync(
|
||||
ApplyFeeCommand cmd,
|
||||
IAccountQuery query, TimeProvider timeProvider)
|
||||
public static async Task<FeeContext> LoadAsync(ApplyFeeCommand cmd, IAccountQuery query, TimeProvider timeProvider)
|
||||
{
|
||||
var source = await query.FindByIdAsync(cmd.AccountId);
|
||||
var dest = await query.FindByIdAsync(99999);
|
||||
@@ -25,13 +23,8 @@ public static class ApplyFeeHandler
|
||||
return new FeeContext(source, dest, timeProvider.GetUtcNow());
|
||||
}
|
||||
|
||||
public static (
|
||||
IStorageAction<Account> CustomerWrite,
|
||||
IStorageAction<Account> RevenueWrite,
|
||||
IStorageAction<JournalEntry> JournalWrite,
|
||||
FeeAppliedEvent Event
|
||||
)
|
||||
Handle(
|
||||
public static ( IStorageAction<Account> CustomerWrite, IStorageAction<Account> RevenueWrite,
|
||||
IStorageAction<JournalEntry> JournalWrite, FeeAppliedEvent Event ) Handle(
|
||||
ApplyFeeCommand cmd,
|
||||
FeeContext context
|
||||
)
|
||||
@@ -39,25 +32,24 @@ public static class ApplyFeeHandler
|
||||
var updatedSource = context.Source.ApplyPosting(cmd.Amount, EntryType.Debit);
|
||||
var updatedRevenue = context.Destination.ApplyPosting(cmd.Amount, EntryType.Credit);
|
||||
var serviceFee = 0.5m;
|
||||
|
||||
|
||||
var lines = new List<JournalLine>
|
||||
{
|
||||
new(updatedSource.Id, cmd.Amount, EntryType.Debit),
|
||||
new(updatedRevenue.Id, cmd.Amount - serviceFee, EntryType.Credit),
|
||||
new(updatedRevenue.Id, serviceFee, EntryType.Credit)
|
||||
};
|
||||
|
||||
var journalEntry = BalancedJournal.Create(Guid.NewGuid(),
|
||||
|
||||
var journalEntry = BalancedJournal.Create(
|
||||
Guid.NewGuid(),
|
||||
$"Service Fee Applied: {cmd.Amount} to Account {cmd.AccountId}",
|
||||
context.TimeStamp, lines);
|
||||
context.TimeStamp,
|
||||
lines
|
||||
);
|
||||
|
||||
var @event = new FeeAppliedEvent(cmd.AccountId, cmd.Amount);
|
||||
|
||||
return (
|
||||
Storage.Update(updatedSource),
|
||||
Storage.Update(updatedRevenue),
|
||||
Storage.Insert(journalEntry.Entry),
|
||||
@event
|
||||
);
|
||||
return (Storage.Update(updatedSource), Storage.Update(updatedRevenue), Storage.Insert(journalEntry.Entry),
|
||||
@event);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user