Fix IO poison in handlers (UtcNow instead of a passed in date time).
This commit is contained in:
@@ -13,18 +13,19 @@ public record TransferFundsCommand(int SourceAccountId, int DestinationAccountId
|
||||
|
||||
public record FundsTransferredEvent(int SourceAccountId, int DestinationAccountId, decimal Amount);
|
||||
|
||||
public record TransferPair(Account Source, Account Destination);
|
||||
public record TransferPair(Account Source, Account Destination, DateTimeOffset TimeStamp);
|
||||
|
||||
public static class TransferFundsHandler
|
||||
{
|
||||
public static async Task<TransferPair?> LoadAsync(TransferFundsCommand cmd, IAccountQuery query)
|
||||
public static async Task<TransferPair?> LoadAsync(TransferFundsCommand cmd, IAccountQuery query,
|
||||
TimeProvider timeProvider)
|
||||
{
|
||||
var source = await query.FindByIdAsync(cmd.SourceAccountId);
|
||||
var dest = await query.FindByIdAsync(cmd.DestinationAccountId);
|
||||
|
||||
if (source == null || dest == null) return null;
|
||||
|
||||
return new TransferPair(source, dest);
|
||||
return new TransferPair(source, dest, timeProvider.GetUtcNow());
|
||||
}
|
||||
|
||||
public static (
|
||||
@@ -39,14 +40,14 @@ public static class TransferFundsHandler
|
||||
|
||||
var lines = new List<JournalLine>
|
||||
{
|
||||
new (pair.Source.Id, cmd.Amount, EntryType.Debit),
|
||||
new (pair.Destination.Id, cmd.Amount, EntryType.Credit)
|
||||
new(pair.Source.Id, cmd.Amount, EntryType.Debit),
|
||||
new(pair.Destination.Id, cmd.Amount, EntryType.Credit)
|
||||
};
|
||||
|
||||
var journalEntry =
|
||||
BalancedJournal.Create(Guid.NewGuid(),
|
||||
$"Transfer: {cmd.Amount} from {cmd.SourceAccountId} to {cmd.DestinationAccountId}",
|
||||
DateTimeOffset.UtcNow, lines);
|
||||
pair.TimeStamp, lines);
|
||||
|
||||
var @event = new FundsTransferredEvent(cmd.SourceAccountId, cmd.DestinationAccountId, cmd.Amount);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user