From a3cc2126cf6c3ac6e28607a14946d1a63fa18834 Mon Sep 17 00:00:00 2001
From: Mostafa Jafari <36862442+ArtisticProgramming@users.noreply.github.com>
Date: Mon, 27 Jul 2026 19:33:44 +0330
Subject: [PATCH] feat(financial-reporting): add CreateGeneralLedger command
and event handler
- Add CreateGeneralLedgerCommand and its Handler in Application layer
- Add JournalMappingExtensions for mapping journal data to GL
- Handle JournalPostedIntegrationHandler to trigger GL creation
- Update Application and RequestResponse project files
---
...FinancialReporting.Core.Application.csproj | 1 +
.../CreateGeneralLedgerCommandHandler.cs | 22 +++++++++++++
.../JournalPostedIntegrationHandler.cs | 16 ++++++----
.../Mappings/JournalMappingExtensions.cs | 32 +++++++++++++++++++
...ncialReporting.Core.RequestResponse.csproj | 5 +++
.../Commands/CreateGeneralLedgerCommand.cs | 23 +++++++++++++
6 files changed, 92 insertions(+), 7 deletions(-)
create mode 100644 src/services/financialreporting/1.core/FinancialReporting.Core.Application/Journals/Commands/CreateGeneralLedger/CreateGeneralLedgerCommandHandler.cs
create mode 100644 src/services/financialreporting/1.core/FinancialReporting.Core.Application/Mappings/JournalMappingExtensions.cs
create mode 100644 src/services/financialreporting/1.core/FinancialReporting.Core.RequestResponse/Journals/Commands/CreateGeneralLedgerCommand.cs
diff --git a/src/services/financialreporting/1.core/FinancialReporting.Core.Application/FinancialReporting.Core.Application.csproj b/src/services/financialreporting/1.core/FinancialReporting.Core.Application/FinancialReporting.Core.Application.csproj
index b84b5c7..54312a4 100644
--- a/src/services/financialreporting/1.core/FinancialReporting.Core.Application/FinancialReporting.Core.Application.csproj
+++ b/src/services/financialreporting/1.core/FinancialReporting.Core.Application/FinancialReporting.Core.Application.csproj
@@ -10,6 +10,7 @@
+
diff --git a/src/services/financialreporting/1.core/FinancialReporting.Core.Application/Journals/Commands/CreateGeneralLedger/CreateGeneralLedgerCommandHandler.cs b/src/services/financialreporting/1.core/FinancialReporting.Core.Application/Journals/Commands/CreateGeneralLedger/CreateGeneralLedgerCommandHandler.cs
new file mode 100644
index 0000000..762970a
--- /dev/null
+++ b/src/services/financialreporting/1.core/FinancialReporting.Core.Application/Journals/Commands/CreateGeneralLedger/CreateGeneralLedgerCommandHandler.cs
@@ -0,0 +1,22 @@
+using BuildingBlocks.Application.Common;
+using BuildingBlocks.Application.CQRS.Commands;
+using BuildingBlocks.Common;
+using FinancialReporting.Core.RequestResponse.Journals.Commands;
+using Microsoft.Extensions.Logging;
+
+namespace FinancialReporting.Core.Application.Journals.Commands.CreateGeneralLedger;
+
+public class CreateGeneralLedgerCommandHandler(
+ ILogger logger
+ ) :
+ BaseCommandHandler(logger)
+{
+ protected override async Task> HandleAsync(
+ CreateGeneralLedgerCommand command,
+ CancellationToken cancellationToken)
+ {
+
+
+ return Result.Success(Unit.Value);
+ }
+}
diff --git a/src/services/financialreporting/1.core/FinancialReporting.Core.Application/Journals/EventHandlers/JournalPostedIntegrationHandler.cs b/src/services/financialreporting/1.core/FinancialReporting.Core.Application/Journals/EventHandlers/JournalPostedIntegrationHandler.cs
index 60cf1a9..982f682 100644
--- a/src/services/financialreporting/1.core/FinancialReporting.Core.Application/Journals/EventHandlers/JournalPostedIntegrationHandler.cs
+++ b/src/services/financialreporting/1.core/FinancialReporting.Core.Application/Journals/EventHandlers/JournalPostedIntegrationHandler.cs
@@ -1,9 +1,10 @@
-using BuildingBlocks.Application.CQRS.Events;
+using BuildingBlocks.Application.Common;
+using BuildingBlocks.Application.CQRS.Events;
+using BuildingBlocks.Integrations.Wolverine;
+using FinancialReporting.Core.Application.Mappings;
using FinancialReporting.Core.Contracts.Journals.IntegrationEvents;
+using FinancialReporting.Core.RequestResponse.Journals.Commands;
using Microsoft.Extensions.Logging;
-using System;
-using System.Collections.Generic;
-using System.Text;
using Wolverine;
namespace FinancialReporting.Core.Application.Journals.EventHandlers;
@@ -13,9 +14,10 @@ public class JournalPostedIntegrationHandler(
: BaseIntegrationEventHandler(logger)
{
protected override async Task HandleAsync(
- JournalEntryPostedIntegrationEvent domainEvent,
+ JournalEntryPostedIntegrationEvent integrationEvent,
CancellationToken cancellationToken)
{
-
+ await _bus.SendCommandAsync(integrationEvent.MapToCreateCommand());
}
-}
\ No newline at end of file
+}
+
diff --git a/src/services/financialreporting/1.core/FinancialReporting.Core.Application/Mappings/JournalMappingExtensions.cs b/src/services/financialreporting/1.core/FinancialReporting.Core.Application/Mappings/JournalMappingExtensions.cs
new file mode 100644
index 0000000..eac9664
--- /dev/null
+++ b/src/services/financialreporting/1.core/FinancialReporting.Core.Application/Mappings/JournalMappingExtensions.cs
@@ -0,0 +1,32 @@
+using FinancialReporting.Core.Contracts.Journals.IntegrationEvents;
+using FinancialReporting.Core.RequestResponse.Journals.Commands;
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace FinancialReporting.Core.Application.Mappings;
+
+internal static class JournalMappingExtensions
+{
+ public static CreateGeneralLedgerCommand MapToCreateCommand(this JournalEntryPostedIntegrationEvent @event)
+ {
+ if (@event == null)
+ return null;
+
+ var mappedLines = @event.Lines?.Select(line => new JournalLineCommand(
+ line.LineId,
+ line.AccountId,
+ line.Debit,
+ line.Credit
+ )).ToList() ?? new();
+
+ return new CreateGeneralLedgerCommand(
+ @event.JournalEntryId,
+ @event.Date,
+ @event.Description,
+ @event.JournalTypeId,
+ @event.JournalTypeName,
+ mappedLines
+ );
+ }
+}
diff --git a/src/services/financialreporting/1.core/FinancialReporting.Core.RequestResponse/FinancialReporting.Core.RequestResponse.csproj b/src/services/financialreporting/1.core/FinancialReporting.Core.RequestResponse/FinancialReporting.Core.RequestResponse.csproj
index b760144..8fcc104 100644
--- a/src/services/financialreporting/1.core/FinancialReporting.Core.RequestResponse/FinancialReporting.Core.RequestResponse.csproj
+++ b/src/services/financialreporting/1.core/FinancialReporting.Core.RequestResponse/FinancialReporting.Core.RequestResponse.csproj
@@ -6,4 +6,9 @@
enable
+
+
+
+
+
diff --git a/src/services/financialreporting/1.core/FinancialReporting.Core.RequestResponse/Journals/Commands/CreateGeneralLedgerCommand.cs b/src/services/financialreporting/1.core/FinancialReporting.Core.RequestResponse/Journals/Commands/CreateGeneralLedgerCommand.cs
new file mode 100644
index 0000000..75c6f01
--- /dev/null
+++ b/src/services/financialreporting/1.core/FinancialReporting.Core.RequestResponse/Journals/Commands/CreateGeneralLedgerCommand.cs
@@ -0,0 +1,23 @@
+using BuildingBlocks.Application.Common;
+using BuildingBlocks.Contracts.Application.CQRS.Commands;
+
+namespace FinancialReporting.Core.RequestResponse.Journals.Commands;
+
+public class CreateGeneralLedgerCommand
+(
+ Guid JournalEntryId,
+ DateOnly Date,
+ string Description,
+ int JournalTypeId,
+ string JournalTypeName,
+ List Lines) : ICommand
+{
+ public Guid Id { get; } = Guid.NewGuid();
+ public DateTime HappenedAt { get; } = DateTime.Now;
+}
+
+public record JournalLineCommand(
+ Guid LineId,
+ Guid AccountId,
+ decimal Debit,
+ decimal Credit);
\ No newline at end of file