feat: add Node and Edge CRUD endpoints
This commit is contained in:
parent
1d5fd7449e
commit
293b23958f
@ -0,0 +1,42 @@
|
||||
using FastEndpoints;
|
||||
using MediatR;
|
||||
using Workflow.Application.Features.WorkflowDefinitions.Commands;
|
||||
using Workflow.Application.Features.WorkflowDefinitions.DTOs;
|
||||
using Workflow.Domain.Enums;
|
||||
|
||||
namespace Workflow.Api.Endpoints.WorkflowDefinition;
|
||||
|
||||
public class CreateEdgeEndpoint : Endpoint<CreateEdgeRequest, WorkflowEdgeDto>
|
||||
{
|
||||
private readonly IMediator _mediator;
|
||||
|
||||
public CreateEdgeEndpoint(IMediator mediator) => _mediator = mediator;
|
||||
|
||||
public override void Configure()
|
||||
{
|
||||
Post("/workflow-definitions/{DefinitionId}/edges");
|
||||
AllowAnonymous();
|
||||
Summary(s =>
|
||||
{
|
||||
s.Summary = "Create a new edge in a workflow definition";
|
||||
});
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(CreateEdgeRequest req, CancellationToken ct)
|
||||
{
|
||||
var command = new CreateEdgeCommand(req.DefinitionId, req.SourceNodeId, req.TargetNodeId, (EdgeType)req.EdgeType, req.Label, req.Condition, req.Order);
|
||||
var result = await _mediator.Send(command, ct);
|
||||
await Send.ResponseAsync(result, 201, ct);
|
||||
}
|
||||
}
|
||||
|
||||
public class CreateEdgeRequest
|
||||
{
|
||||
public Guid DefinitionId { get; set; }
|
||||
public Guid SourceNodeId { get; set; }
|
||||
public Guid TargetNodeId { get; set; }
|
||||
public int EdgeType { get; set; }
|
||||
public string? Label { get; set; }
|
||||
public string? Condition { get; set; }
|
||||
public int Order { get; set; }
|
||||
}
|
||||
@ -0,0 +1,41 @@
|
||||
using FastEndpoints;
|
||||
using MediatR;
|
||||
using Workflow.Application.Features.WorkflowDefinitions.Commands;
|
||||
using Workflow.Application.Features.WorkflowDefinitions.DTOs;
|
||||
using Workflow.Domain.Enums;
|
||||
|
||||
namespace Workflow.Api.Endpoints.WorkflowDefinition;
|
||||
|
||||
public class CreateNodeEndpoint : Endpoint<CreateNodeRequest, WorkflowNodeDto>
|
||||
{
|
||||
private readonly IMediator _mediator;
|
||||
|
||||
public CreateNodeEndpoint(IMediator mediator) => _mediator = mediator;
|
||||
|
||||
public override void Configure()
|
||||
{
|
||||
Post("/workflow-definitions/{DefinitionId}/nodes");
|
||||
AllowAnonymous();
|
||||
Summary(s =>
|
||||
{
|
||||
s.Summary = "Create a new node in a workflow definition";
|
||||
});
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(CreateNodeRequest req, CancellationToken ct)
|
||||
{
|
||||
var command = new CreateNodeCommand(req.DefinitionId, (NodeType)req.NodeType, req.Name, req.Config, req.PositionX, req.PositionY);
|
||||
var result = await _mediator.Send(command, ct);
|
||||
await Send.ResponseAsync(result, 201, ct);
|
||||
}
|
||||
}
|
||||
|
||||
public class CreateNodeRequest
|
||||
{
|
||||
public Guid DefinitionId { get; set; }
|
||||
public int NodeType { get; set; }
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public string? Config { get; set; }
|
||||
public int PositionX { get; set; }
|
||||
public int PositionY { get; set; }
|
||||
}
|
||||
@ -0,0 +1,35 @@
|
||||
using FastEndpoints;
|
||||
using MediatR;
|
||||
using Workflow.Application.Features.WorkflowDefinitions.Commands;
|
||||
|
||||
namespace Workflow.Api.Endpoints.WorkflowDefinition;
|
||||
|
||||
public class DeleteEdgeEndpoint : Endpoint<DeleteEdgeRequest>
|
||||
{
|
||||
private readonly IMediator _mediator;
|
||||
|
||||
public DeleteEdgeEndpoint(IMediator mediator) => _mediator = mediator;
|
||||
|
||||
public override void Configure()
|
||||
{
|
||||
Delete("/workflow-definitions/{DefinitionId}/edges/{EdgeId}");
|
||||
AllowAnonymous();
|
||||
Summary(s =>
|
||||
{
|
||||
s.Summary = "Delete an edge from a workflow definition";
|
||||
});
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(DeleteEdgeRequest req, CancellationToken ct)
|
||||
{
|
||||
var command = new DeleteEdgeCommand(req.EdgeId);
|
||||
await _mediator.Send(command, ct);
|
||||
await Send.OkAsync(ct);
|
||||
}
|
||||
}
|
||||
|
||||
public class DeleteEdgeRequest
|
||||
{
|
||||
public Guid DefinitionId { get; set; }
|
||||
public Guid EdgeId { get; set; }
|
||||
}
|
||||
@ -0,0 +1,35 @@
|
||||
using FastEndpoints;
|
||||
using MediatR;
|
||||
using Workflow.Application.Features.WorkflowDefinitions.Commands;
|
||||
|
||||
namespace Workflow.Api.Endpoints.WorkflowDefinition;
|
||||
|
||||
public class DeleteNodeEndpoint : Endpoint<DeleteNodeRequest>
|
||||
{
|
||||
private readonly IMediator _mediator;
|
||||
|
||||
public DeleteNodeEndpoint(IMediator mediator) => _mediator = mediator;
|
||||
|
||||
public override void Configure()
|
||||
{
|
||||
Delete("/workflow-definitions/{DefinitionId}/nodes/{NodeId}");
|
||||
AllowAnonymous();
|
||||
Summary(s =>
|
||||
{
|
||||
s.Summary = "Delete a node from a workflow definition";
|
||||
});
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(DeleteNodeRequest req, CancellationToken ct)
|
||||
{
|
||||
var command = new DeleteNodeCommand(req.NodeId);
|
||||
await _mediator.Send(command, ct);
|
||||
await Send.OkAsync(ct);
|
||||
}
|
||||
}
|
||||
|
||||
public class DeleteNodeRequest
|
||||
{
|
||||
public Guid DefinitionId { get; set; }
|
||||
public Guid NodeId { get; set; }
|
||||
}
|
||||
@ -0,0 +1,41 @@
|
||||
using FastEndpoints;
|
||||
using MediatR;
|
||||
using Workflow.Application.Features.WorkflowDefinitions.Commands;
|
||||
using Workflow.Application.Features.WorkflowDefinitions.DTOs;
|
||||
using Workflow.Domain.Enums;
|
||||
|
||||
namespace Workflow.Api.Endpoints.WorkflowDefinition;
|
||||
|
||||
public class UpdateEdgeEndpoint : Endpoint<UpdateEdgeRequest, WorkflowEdgeDto>
|
||||
{
|
||||
private readonly IMediator _mediator;
|
||||
|
||||
public UpdateEdgeEndpoint(IMediator mediator) => _mediator = mediator;
|
||||
|
||||
public override void Configure()
|
||||
{
|
||||
Put("/workflow-definitions/{DefinitionId}/edges/{EdgeId}");
|
||||
AllowAnonymous();
|
||||
Summary(s =>
|
||||
{
|
||||
s.Summary = "Update an edge in a workflow definition";
|
||||
});
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(UpdateEdgeRequest req, CancellationToken ct)
|
||||
{
|
||||
var command = new UpdateEdgeCommand(req.EdgeId, (EdgeType)req.EdgeType, req.Label, req.Condition, req.Order);
|
||||
var result = await _mediator.Send(command, ct);
|
||||
await Send.OkAsync(result, ct);
|
||||
}
|
||||
}
|
||||
|
||||
public class UpdateEdgeRequest
|
||||
{
|
||||
public Guid DefinitionId { get; set; }
|
||||
public Guid EdgeId { get; set; }
|
||||
public int EdgeType { get; set; }
|
||||
public string? Label { get; set; }
|
||||
public string? Condition { get; set; }
|
||||
public int Order { get; set; }
|
||||
}
|
||||
@ -0,0 +1,40 @@
|
||||
using FastEndpoints;
|
||||
using MediatR;
|
||||
using Workflow.Application.Features.WorkflowDefinitions.Commands;
|
||||
using Workflow.Application.Features.WorkflowDefinitions.DTOs;
|
||||
|
||||
namespace Workflow.Api.Endpoints.WorkflowDefinition;
|
||||
|
||||
public class UpdateNodeEndpoint : Endpoint<UpdateNodeRequest, WorkflowNodeDto>
|
||||
{
|
||||
private readonly IMediator _mediator;
|
||||
|
||||
public UpdateNodeEndpoint(IMediator mediator) => _mediator = mediator;
|
||||
|
||||
public override void Configure()
|
||||
{
|
||||
Put("/workflow-definitions/{DefinitionId}/nodes/{NodeId}");
|
||||
AllowAnonymous();
|
||||
Summary(s =>
|
||||
{
|
||||
s.Summary = "Update a node in a workflow definition";
|
||||
});
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(UpdateNodeRequest req, CancellationToken ct)
|
||||
{
|
||||
var command = new UpdateNodeCommand(req.NodeId, req.Name, req.Config, req.PositionX, req.PositionY);
|
||||
var result = await _mediator.Send(command, ct);
|
||||
await Send.OkAsync(result, ct);
|
||||
}
|
||||
}
|
||||
|
||||
public class UpdateNodeRequest
|
||||
{
|
||||
public Guid DefinitionId { get; set; }
|
||||
public Guid NodeId { get; set; }
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public string? Config { get; set; }
|
||||
public int PositionX { get; set; }
|
||||
public int PositionY { get; set; }
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user