| | | 1 | | using Elsa.Labels.Contracts; |
| | | 2 | | using Elsa.Workflows.Management; |
| | | 3 | | using Elsa.Workflows.Management.Filters; |
| | | 4 | | using FastEndpoints; |
| | | 5 | | using JetBrains.Annotations; |
| | | 6 | | using Open.Linq.AsyncExtensions; |
| | | 7 | | |
| | | 8 | | namespace Elsa.Labels.Endpoints.WorkflowDefinitionLabels.List; |
| | | 9 | | |
| | | 10 | | [PublicAPI] |
| | | 11 | | internal class List : Endpoint<Request, Response> |
| | | 12 | | { |
| | | 13 | | private readonly IWorkflowDefinitionStore _workflowDefinitionStore; |
| | | 14 | | private readonly IWorkflowDefinitionLabelStore _workflowDefinitionLabelStore; |
| | | 15 | | |
| | 0 | 16 | | public List( |
| | 0 | 17 | | IWorkflowDefinitionStore workflowDefinitionStore, |
| | 0 | 18 | | IWorkflowDefinitionLabelStore workflowDefinitionLabelStore) |
| | | 19 | | { |
| | 0 | 20 | | _workflowDefinitionStore = workflowDefinitionStore; |
| | 0 | 21 | | _workflowDefinitionLabelStore = workflowDefinitionLabelStore; |
| | 0 | 22 | | } |
| | | 23 | | |
| | | 24 | | public override void Configure() |
| | | 25 | | { |
| | 0 | 26 | | Get("/workflow-definitions/{id}/labels"); |
| | 0 | 27 | | Policies(Constants.PolicyName); |
| | 0 | 28 | | } |
| | | 29 | | |
| | | 30 | | public override async Task HandleAsync(Request request, CancellationToken cancellationToken) |
| | | 31 | | { |
| | 0 | 32 | | var workflowDefinition = await _workflowDefinitionStore.FindAsync(new WorkflowDefinitionFilter { Id = request.Id |
| | | 33 | | |
| | 0 | 34 | | if (workflowDefinition == null) |
| | | 35 | | { |
| | 0 | 36 | | await Send.NotFoundAsync(cancellationToken); |
| | 0 | 37 | | return; |
| | | 38 | | } |
| | | 39 | | |
| | 0 | 40 | | var currentLabels = await _workflowDefinitionLabelStore.FindByWorkflowDefinitionVersionIdAsync(request.Id, cance |
| | | 41 | | |
| | 0 | 42 | | var response = new Response |
| | 0 | 43 | | { |
| | 0 | 44 | | Items = currentLabels.ToList() |
| | 0 | 45 | | }; |
| | | 46 | | |
| | 0 | 47 | | await Send.OkAsync(response, cancellationToken); |
| | 0 | 48 | | } |
| | | 49 | | } |