Adjust location of classes further.
This commit is contained in:
+12
-9
@@ -1,14 +1,17 @@
|
||||
using FinancialApi.Application.Commands;
|
||||
using FinancialApi.Application.Events;
|
||||
using FinancialApi.Application.Queries;
|
||||
using FinancialApi.Application.Interfaces;
|
||||
using FinancialApi.Application.Models;
|
||||
using FinancialApi.Domain;
|
||||
using FinancialApi.Domain.Aggregates;
|
||||
using FinancialApi.Domain.Entities;
|
||||
using Wolverine.Persistence;
|
||||
|
||||
namespace FinancialApi.Application.Handlers;
|
||||
|
||||
public static class TransferFundsHandler
|
||||
{
|
||||
public static async Task<TransferPair?> LoadAsync(TransferFundsCommand cmd, IAccountQuery query,
|
||||
public static async Task<TransferContext?> LoadAsync(TransferFundsCommand cmd, IAccountQuery query,
|
||||
TimeProvider timeProvider)
|
||||
{
|
||||
var source = await query.FindByIdAsync(cmd.SourceAccountId);
|
||||
@@ -16,7 +19,7 @@ public static class TransferFundsHandler
|
||||
|
||||
if (source == null || dest == null) return null;
|
||||
|
||||
return new TransferPair(source, dest, timeProvider.GetUtcNow());
|
||||
return new TransferContext(source, dest, timeProvider.GetUtcNow());
|
||||
}
|
||||
|
||||
public static (
|
||||
@@ -24,21 +27,21 @@ public static class TransferFundsHandler
|
||||
IStorageAction<Account> DestWrite,
|
||||
IStorageAction<JournalEntry> JournalWrite,
|
||||
FundsTransferredEvent Event
|
||||
) Handle(TransferFundsCommand cmd, TransferPair pair)
|
||||
) Handle(TransferFundsCommand cmd, TransferContext context)
|
||||
{
|
||||
var updatedSource = pair.Source.Debit(cmd.Amount);
|
||||
var updatedDest = pair.Destination.Credit(cmd.Amount);
|
||||
var updatedSource = context.Source.Debit(cmd.Amount);
|
||||
var updatedDest = context.Destination.Credit(cmd.Amount);
|
||||
|
||||
var lines = new List<JournalLine>
|
||||
{
|
||||
new(pair.Source.Id, cmd.Amount, EntryType.Debit),
|
||||
new(pair.Destination.Id, cmd.Amount, EntryType.Credit)
|
||||
new(context.Source.Id, cmd.Amount, EntryType.Debit),
|
||||
new(context.Destination.Id, cmd.Amount, EntryType.Credit)
|
||||
};
|
||||
|
||||
var journalEntry =
|
||||
BalancedJournal.Create(Guid.NewGuid(),
|
||||
$"Transfer: {cmd.Amount} from {cmd.SourceAccountId} to {cmd.DestinationAccountId}",
|
||||
pair.TimeStamp, lines);
|
||||
context.TimeStamp, lines);
|
||||
|
||||
var @event = new FundsTransferredEvent(cmd.SourceAccountId, cmd.DestinationAccountId, cmd.Amount);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user