43 lines
1.3 KiB
C#
43 lines
1.3 KiB
C#
using MediatR;
|
|
using Workflow.Application.Features.WorkflowDefinitions.DTOs;
|
|
using Workflow.Domain.Enums;
|
|
using Workflow.Domain.Exceptions;
|
|
using Workflow.Infrastructure.Persistence;
|
|
|
|
namespace Workflow.Application.Features.WorkflowDefinitions.Commands;
|
|
|
|
public record UpdateEdgeCommand(
|
|
Guid EdgeId,
|
|
EdgeType EdgeType,
|
|
string? Label,
|
|
string? Condition,
|
|
int Order
|
|
) : IRequest<WorkflowEdgeDto>;
|
|
|
|
public class UpdateEdgeCommandHandler(WorkflowDbContext db)
|
|
: IRequestHandler<UpdateEdgeCommand, WorkflowEdgeDto>
|
|
{
|
|
public async Task<WorkflowEdgeDto> Handle(UpdateEdgeCommand request, CancellationToken cancellationToken)
|
|
{
|
|
var entity = await db.WorkflowEdges.FindAsync([request.EdgeId], cancellationToken)
|
|
?? throw new NotFoundException($"Workflow edge '{request.EdgeId}' not found.");
|
|
|
|
entity.EdgeType = request.EdgeType;
|
|
entity.Label = request.Label;
|
|
entity.Condition = request.Condition;
|
|
entity.Order = request.Order;
|
|
|
|
await db.SaveChangesAsync(cancellationToken);
|
|
|
|
return new WorkflowEdgeDto(
|
|
entity.Id,
|
|
entity.SourceNodeId,
|
|
entity.TargetNodeId,
|
|
entity.EdgeType,
|
|
entity.Label,
|
|
entity.Condition,
|
|
entity.Order
|
|
);
|
|
}
|
|
}
|