Re-layout source code to correct namespaces (handlers, commands, etc.)
This commit is contained in:
+50
@@ -0,0 +1,50 @@
|
||||
using FinancialApi.Application.Commands;
|
||||
using FinancialApi.Application.Events;
|
||||
using FinancialApi.Application.Queries;
|
||||
using FinancialApi.Domain;
|
||||
using Wolverine.Persistence;
|
||||
|
||||
namespace FinancialApi.Application.Handlers;
|
||||
|
||||
public record ReversalData(
|
||||
JournalEntry OriginalJournalEntry,
|
||||
IReadOnlyList<Account> AffectedAccounts,
|
||||
DateTimeOffset TimeStamp);
|
||||
|
||||
public static class ReverseJournalHandler
|
||||
{
|
||||
public static async Task<ReversalData?> LoadAsync(ReverseJournalCommand cmd, IReversalQuery query,
|
||||
TimeProvider timeProvider)
|
||||
{
|
||||
var data = await query.GetReversalDataAsync(cmd.OriginalJournalId);
|
||||
return data ?? throw new InvalidOperationException($"Journal Entry {cmd.OriginalJournalId} does not exist");
|
||||
}
|
||||
|
||||
public static (
|
||||
IStorageAction<JournalEntry> JournalWrite,
|
||||
UnitOfWork<Account> AccountWrites,
|
||||
JournalReversedEvent Event)
|
||||
Handle(ReverseJournalCommand cmd, ReversalData data)
|
||||
{
|
||||
var reversalJournal =
|
||||
BalancedJournal.CreateReversal(data.OriginalJournalEntry, $"Reversal: {cmd.Reason}", data.TimeStamp);
|
||||
var accountState = data.AffectedAccounts.ToDictionary(a => a.Id);
|
||||
|
||||
reversalJournal.Entry.Lines.ForEach(l =>
|
||||
{
|
||||
var currentAccount = accountState[l.AccountId];
|
||||
accountState[l.AccountId] = currentAccount.ApplyPosting(l.Amount, l.Type);
|
||||
});
|
||||
var accountUow = new UnitOfWork<Account>();
|
||||
foreach (var account in accountState.Values)
|
||||
{
|
||||
accountUow.Update(account);
|
||||
}
|
||||
|
||||
return (
|
||||
Storage.Insert(reversalJournal.Entry),
|
||||
accountUow,
|
||||
new JournalReversedEvent(cmd.OriginalJournalId, reversalJournal.Entry.Id)
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user