| | | 1 | | using Elsa.Abstractions; |
| | | 2 | | using Elsa.Common.Entities; |
| | | 3 | | using Elsa.Common.Models; |
| | | 4 | | using Elsa.Workflows.Management; |
| | | 5 | | using Elsa.Workflows.Management.Filters; |
| | | 6 | | using JetBrains.Annotations; |
| | | 7 | | using Microsoft.AspNetCore.Http; |
| | | 8 | | |
| | | 9 | | namespace Elsa.Workflows.Api.Endpoints.WorkflowDefinitions.Version; |
| | | 10 | | |
| | | 11 | | [PublicAPI] |
| | 1 | 12 | | internal class ListVersions(IWorkflowDefinitionStore store) : ElsaEndpointWithoutRequest |
| | | 13 | | { |
| | | 14 | | public override void Configure() |
| | | 15 | | { |
| | 1 | 16 | | Get("workflow-definitions/{definitionId}/versions"); |
| | 1 | 17 | | ConfigurePermissions("read:workflow-definitions"); |
| | 1 | 18 | | } |
| | | 19 | | |
| | | 20 | | public override async Task HandleAsync(CancellationToken cancellationToken) |
| | | 21 | | { |
| | 0 | 22 | | var definitionId = Route<string>("definitionId")!; |
| | | 23 | | |
| | 0 | 24 | | var filter = new WorkflowDefinitionFilter |
| | 0 | 25 | | { |
| | 0 | 26 | | DefinitionId = definitionId, |
| | 0 | 27 | | VersionOptions = VersionOptions.All |
| | 0 | 28 | | }; |
| | | 29 | | |
| | 0 | 30 | | var orderBy = new WorkflowDefinitionOrder<int>(x => x.Version, OrderDirection.Descending); |
| | 0 | 31 | | var definitions = await store.FindManyAsync(filter, orderBy, cancellationToken); |
| | | 32 | | |
| | 0 | 33 | | if (!definitions.Any()) |
| | | 34 | | { |
| | 0 | 35 | | await Send.NotFoundAsync(cancellationToken); |
| | 0 | 36 | | return; |
| | | 37 | | } |
| | | 38 | | |
| | 0 | 39 | | await Send.OkAsync(definitions, cancellationToken); |
| | 0 | 40 | | } |
| | | 41 | | } |