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.
This commit is contained in:
@@ -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<CloseWorkflowCommand, CloseWorkflowResult>
|
||||
{
|
||||
public async Task<CloseWorkflowResult> 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user