| | | 1 | | using Elsa.Abstractions; |
| | | 2 | | using Elsa.Common.Entities; |
| | | 3 | | using Elsa.Common.Models; |
| | | 4 | | using Elsa.Models; |
| | | 5 | | using Elsa.Workflows.Api.Models; |
| | | 6 | | using Elsa.Workflows.Management; |
| | | 7 | | using Elsa.Workflows.Management.Filters; |
| | | 8 | | using Elsa.Workflows.Management.Models; |
| | | 9 | | using JetBrains.Annotations; |
| | | 10 | | |
| | | 11 | | namespace Elsa.Workflows.Api.Endpoints.WorkflowDefinitions.List; |
| | | 12 | | |
| | | 13 | | [PublicAPI] |
| | 1 | 14 | | internal class List(IWorkflowDefinitionStore store, IWorkflowDefinitionLinker linker) : ElsaEndpoint<Request, PagedListR |
| | | 15 | | { |
| | | 16 | | public override void Configure() |
| | | 17 | | { |
| | 1 | 18 | | Get("/workflow-definitions"); |
| | 1 | 19 | | ConfigurePermissions("read:workflow-definitions"); |
| | 1 | 20 | | } |
| | | 21 | | |
| | | 22 | | public override async Task<PagedListResponse<LinkedWorkflowDefinitionSummary>> ExecuteAsync(Request request, Cancell |
| | | 23 | | { |
| | 0 | 24 | | var pageArgs = PageArgs.FromPage(request.Page, request.PageSize); |
| | 0 | 25 | | var filter = CreateFilter(request); |
| | 0 | 26 | | var summaries = await FindAsync(request, filter, pageArgs, cancellationToken); |
| | 0 | 27 | | var pagedList = new PagedListResponse<WorkflowDefinitionSummary>(summaries); |
| | 0 | 28 | | var response = linker.MapAsync(pagedList); |
| | 0 | 29 | | return response; |
| | 0 | 30 | | } |
| | | 31 | | |
| | | 32 | | private WorkflowDefinitionFilter CreateFilter(Request request) |
| | | 33 | | { |
| | 0 | 34 | | var versionOptions = string.IsNullOrWhiteSpace(request.VersionOptions) ? default(VersionOptions?) : VersionOptio |
| | | 35 | | |
| | 0 | 36 | | return new() |
| | 0 | 37 | | { |
| | 0 | 38 | | IsSystem = request.IsSystem, |
| | 0 | 39 | | VersionOptions = versionOptions, |
| | 0 | 40 | | SearchTerm = request.SearchTerm?.Trim(), |
| | 0 | 41 | | MaterializerName = request.MaterializerName, |
| | 0 | 42 | | DefinitionIds = request.DefinitionIds, |
| | 0 | 43 | | Ids = request.Ids |
| | 0 | 44 | | }; |
| | | 45 | | } |
| | | 46 | | |
| | | 47 | | private async Task<Page<WorkflowDefinitionSummary>> FindAsync(Request request, WorkflowDefinitionFilter filter, Page |
| | | 48 | | { |
| | 0 | 49 | | request.OrderBy ??= OrderByWorkflowDefinition.Name; |
| | | 50 | | |
| | 0 | 51 | | var direction = request.OrderBy == OrderByWorkflowDefinition.Name ? request.OrderDirection ?? OrderDirection.Asc |
| | | 52 | | |
| | 0 | 53 | | switch (request.OrderBy) |
| | | 54 | | { |
| | | 55 | | default: |
| | | 56 | | { |
| | 0 | 57 | | var order = new WorkflowDefinitionOrder<DateTimeOffset> |
| | 0 | 58 | | { |
| | 0 | 59 | | KeySelector = p => p.CreatedAt, |
| | 0 | 60 | | Direction = direction |
| | 0 | 61 | | }; |
| | | 62 | | |
| | 0 | 63 | | return await store.FindSummariesAsync(filter, order, pageArgs, cancellationToken); |
| | | 64 | | } |
| | | 65 | | case OrderByWorkflowDefinition.Name: |
| | | 66 | | { |
| | 0 | 67 | | var order = new WorkflowDefinitionOrder<string> |
| | 0 | 68 | | { |
| | 0 | 69 | | KeySelector = p => p.Name!, |
| | 0 | 70 | | Direction = direction |
| | 0 | 71 | | }; |
| | | 72 | | |
| | 0 | 73 | | return await store.FindSummariesAsync(filter, order, pageArgs, cancellationToken); |
| | | 74 | | } |
| | | 75 | | case OrderByWorkflowDefinition.Version: |
| | | 76 | | { |
| | 0 | 77 | | var order = new WorkflowDefinitionOrder<int> |
| | 0 | 78 | | { |
| | 0 | 79 | | KeySelector = p => p.Version, |
| | 0 | 80 | | Direction = direction |
| | 0 | 81 | | }; |
| | | 82 | | |
| | 0 | 83 | | return await store.FindSummariesAsync(filter, order, pageArgs, cancellationToken); |
| | | 84 | | } |
| | | 85 | | } |
| | 0 | 86 | | } |
| | | 87 | | } |