Re-layout source code to correct namespaces (handlers, commands, etc.)
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
namespace FinancialApi.Application.Commands;
|
||||
|
||||
public record ApplyFeeCommand(int AccountId, decimal Amount);
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
namespace FinancialApi.Application.Commands;
|
||||
|
||||
public record ReverseJournalCommand(Guid OriginalJournalId, string Reason);
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
namespace FinancialApi.Application.Commands;
|
||||
|
||||
public abstract record TransferFundsCommand(int SourceAccountId, int DestinationAccountId, decimal Amount);
|
||||
@@ -0,0 +1,3 @@
|
||||
namespace FinancialApi.Application.Events;
|
||||
|
||||
public record FeeAppliedEvent(int AccountId, decimal Amount);
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
namespace FinancialApi.Application.Events;
|
||||
|
||||
public record FundsTransferredEvent(int SourceAccountId, int DestinationAccountId, decimal Amount);
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
namespace FinancialApi.Application;
|
||||
namespace FinancialApi.Application.Events;
|
||||
|
||||
public interface IEventTracker
|
||||
{
|
||||
@@ -0,0 +1,3 @@
|
||||
namespace FinancialApi.Application.Events;
|
||||
|
||||
public record JournalReversedEvent(Guid OriginalJournalId, Guid ReversalJournalId);
|
||||
@@ -0,0 +1,5 @@
|
||||
using FinancialApi.Domain;
|
||||
|
||||
namespace FinancialApi.Application;
|
||||
|
||||
public record FeePair(Account Source, Account Destination, DateTimeOffset TimeStamp);
|
||||
+9
-11
@@ -1,16 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using FinancialApi.Application.Commands;
|
||||
using FinancialApi.Application.Events;
|
||||
using FinancialApi.Application.Queries;
|
||||
using FinancialApi.Domain;
|
||||
using Wolverine.Persistence;
|
||||
|
||||
namespace FinancialApi.Application;
|
||||
|
||||
public record ApplyFeeCommand(int AccountId, decimal Amount);
|
||||
|
||||
public record FeeAppliedEvent(int AccountId, decimal Amount);
|
||||
|
||||
public record FeePair(Account Source, Account Destination, DateTimeOffset TimeStamp);
|
||||
namespace FinancialApi.Application.Handlers;
|
||||
|
||||
public static class ApplyFeeHandler
|
||||
{
|
||||
@@ -41,11 +35,15 @@ public static class ApplyFeeHandler
|
||||
{
|
||||
var updatedSource = pair.Source.ApplyPosting(cmd.Amount, EntryType.Debit);
|
||||
var updatedRevenue = pair.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, EntryType.Credit)
|
||||
new(updatedRevenue.Id, cmd.Amount - serviceFee, EntryType.Credit),
|
||||
new(updatedRevenue.Id, serviceFee, EntryType.Credit)
|
||||
};
|
||||
|
||||
var journalEntry = BalancedJournal.Create(Guid.NewGuid(),
|
||||
$"Service Fee Applied: {cmd.Amount} to Account {cmd.AccountId}",
|
||||
pair.TimeStamp, lines);
|
||||
+2
-1
@@ -1,6 +1,7 @@
|
||||
using FinancialApi.Application.Events;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace FinancialApi.Application;
|
||||
namespace FinancialApi.Application.Handlers;
|
||||
|
||||
public static class FinancialEventHandler
|
||||
{
|
||||
+6
-15
@@ -1,26 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using FinancialApi.Application.Commands;
|
||||
using FinancialApi.Application.Events;
|
||||
using FinancialApi.Application.Queries;
|
||||
using FinancialApi.Domain;
|
||||
using Wolverine.Persistence;
|
||||
|
||||
namespace FinancialApi.Application;
|
||||
|
||||
public record ReverseJournalCommand(Guid OriginalJournalId, string Reason);
|
||||
|
||||
public record JournalReversedEvent(Guid OriginalJournalId, Guid ReversalJournalId);
|
||||
namespace FinancialApi.Application.Handlers;
|
||||
|
||||
public record ReversalData(
|
||||
JournalEntry OriginalJournalEntry,
|
||||
IReadOnlyList<Account> AffectedAccounts,
|
||||
DateTimeOffset TimeStamp);
|
||||
|
||||
public interface IReversalQuery
|
||||
{
|
||||
Task<ReversalData?> GetReversalDataAsync(Guid journalEntryId);
|
||||
}
|
||||
|
||||
public static class ReverseJournalHandler
|
||||
{
|
||||
public static async Task<ReversalData?> LoadAsync(ReverseJournalCommand cmd, IReversalQuery query,
|
||||
@@ -33,7 +23,8 @@ public static class ReverseJournalHandler
|
||||
public static (
|
||||
IStorageAction<JournalEntry> JournalWrite,
|
||||
UnitOfWork<Account> AccountWrites,
|
||||
JournalReversedEvent Event) Handle(ReverseJournalCommand cmd, ReversalData data)
|
||||
JournalReversedEvent Event)
|
||||
Handle(ReverseJournalCommand cmd, ReversalData data)
|
||||
{
|
||||
var reversalJournal =
|
||||
BalancedJournal.CreateReversal(data.OriginalJournalEntry, $"Reversal: {cmd.Reason}", data.TimeStamp);
|
||||
+4
-15
@@ -1,21 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using FinancialApi.Application.Commands;
|
||||
using FinancialApi.Application.Events;
|
||||
using FinancialApi.Application.Queries;
|
||||
using FinancialApi.Domain;
|
||||
using Wolverine.Persistence;
|
||||
|
||||
namespace FinancialApi.Application;
|
||||
|
||||
public interface IAccountQuery
|
||||
{
|
||||
Task<Account?> FindByIdAsync(int id);
|
||||
}
|
||||
|
||||
public record TransferFundsCommand(int SourceAccountId, int DestinationAccountId, decimal Amount);
|
||||
|
||||
public record FundsTransferredEvent(int SourceAccountId, int DestinationAccountId, decimal Amount);
|
||||
|
||||
public record TransferPair(Account Source, Account Destination, DateTimeOffset TimeStamp);
|
||||
namespace FinancialApi.Application.Handlers;
|
||||
|
||||
public static class TransferFundsHandler
|
||||
{
|
||||
@@ -0,0 +1,8 @@
|
||||
using FinancialApi.Domain;
|
||||
|
||||
namespace FinancialApi.Application.Queries;
|
||||
|
||||
public interface IAccountQuery
|
||||
{
|
||||
Task<Account?> FindByIdAsync(int id);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
using FinancialApi.Application.Handlers;
|
||||
|
||||
namespace FinancialApi.Application.Queries;
|
||||
|
||||
public interface IReversalQuery
|
||||
{
|
||||
Task<ReversalData?> GetReversalDataAsync(Guid journalEntryId);
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
using FinancialApi.Domain;
|
||||
|
||||
namespace FinancialApi.Application;
|
||||
|
||||
public record TransferPair(Account Source, Account Destination, DateTimeOffset TimeStamp);
|
||||
Reference in New Issue
Block a user