From 46da385b920f8b4386e99efdca6802d27a5ba4f0 Mon Sep 17 00:00:00 2001 From: TekH Date: Tue, 3 Nov 2026 20:57:45 +0100 Subject: [PATCH] Add CloseWorkflowCommandHandler for workflow closure Introduce CloseWorkflowCommandHandler class to handle the closure of workflows using the MediatR library. This class implements IRequestHandler and processes CloseWorkflowCommand requests, returning CloseWorkflowResult objects. It interacts with IWorkflowRepository to execute the CloseAsync method, validating the procedure result and throwing an exception if the result is invalid. Necessary using directives for DigitalData.TaskFlow.Application.Common.Interfaces and MediatR are also added. --- .../Commands/CloseWorkflowCommandHandler.cs | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/core/DigitalData.TaskFlow.Application/Features/Workflows/Commands/CloseWorkflowCommandHandler.cs diff --git a/src/core/DigitalData.TaskFlow.Application/Features/Workflows/Commands/CloseWorkflowCommandHandler.cs b/src/core/DigitalData.TaskFlow.Application/Features/Workflows/Commands/CloseWorkflowCommandHandler.cs new file mode 100644 index 0000000..9384e50 --- /dev/null +++ b/src/core/DigitalData.TaskFlow.Application/Features/Workflows/Commands/CloseWorkflowCommandHandler.cs @@ -0,0 +1,32 @@ +using DigitalData.TaskFlow.Application.Common.Interfaces; +using MediatR; + +namespace DigitalData.TaskFlow.Application.Features.Workflows.Commands; + +public sealed class CloseWorkflowCommandHandler(IWorkflowRepository repo) + : IRequestHandler +{ + public async Task Handle( + CloseWorkflowCommand request, + CancellationToken cancellationToken) + { + var procedureResult = await repo.CloseAsync( + userId: request.WisagId, + source: request.Source, + processId: request.ProcessId, + closingMethodId: request.ClosingMethodId, + comment: request.Comment, + rejectionReasonId: request.RejectionReasonId, + cancellationToken: cancellationToken); + + if (procedureResult?.Code is null) + { + throw new InvalidOperationException( + "Stored procedure returned an invalid close result."); + } + + return new CloseWorkflowResult( + ResultCode: procedureResult.Code.Value, + ResultMessage: procedureResult.Result ?? string.Empty); + } +}