| | | 1 | | using Elsa.Abstractions; |
| | | 2 | | using Elsa.Workflows.Management; |
| | | 3 | | using Elsa.Workflows.Management.Filters; |
| | | 4 | | using JetBrains.Annotations; |
| | | 5 | | using Microsoft.AspNetCore.Builder; |
| | | 6 | | |
| | | 7 | | namespace Elsa.Workflows.Api.Endpoints.WorkflowDefinitions.GetById; |
| | | 8 | | |
| | | 9 | | [PublicAPI] |
| | 2 | 10 | | internal class GetById(IWorkflowDefinitionStore store, IWorkflowDefinitionLinker linker) : ElsaEndpoint<Request> |
| | | 11 | | { |
| | | 12 | | public override void Configure() |
| | | 13 | | { |
| | 1 | 14 | | Get("/workflow-definitions/by-id/{id}"); |
| | 1 | 15 | | ConfigurePermissions("read:workflow-definitions"); |
| | 2 | 16 | | Options(x => x.WithName("GetWorkflowDefinitionById")); |
| | 1 | 17 | | } |
| | | 18 | | |
| | | 19 | | public override async Task HandleAsync(Request request, CancellationToken cancellationToken) |
| | | 20 | | { |
| | 1 | 21 | | var filter = new WorkflowDefinitionFilter |
| | 1 | 22 | | { |
| | 1 | 23 | | Id = request.Id |
| | 1 | 24 | | }; |
| | | 25 | | |
| | 1 | 26 | | var definition = await store.FindAsync(filter, cancellationToken); |
| | | 27 | | |
| | 1 | 28 | | if (definition == null) |
| | | 29 | | { |
| | 0 | 30 | | await Send.NotFoundAsync(cancellationToken); |
| | 0 | 31 | | return; |
| | | 32 | | } |
| | | 33 | | |
| | 1 | 34 | | var model = await linker.MapAsync(definition, cancellationToken); |
| | 1 | 35 | | await Send.OkAsync(model, cancellationToken); |
| | 1 | 36 | | } |
| | | 37 | | } |