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