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); + } +}