< Summary

Information
Class: Elsa.Workflows.Api.Endpoints.WorkflowDefinitions.List.List
Assembly: Elsa.Workflows.Api
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/List/Endpoint.cs
Line coverage
9%
Covered lines: 4
Uncovered lines: 39
Coverable lines: 43
Total lines: 87
Line coverage: 9.3%
Branch coverage
0%
Covered branches: 0
Total branches: 14
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
Configure()100%11100%
ExecuteAsync()100%210%
CreateFilter(...)0%2040%
FindAsync()0%110100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/List/Endpoint.cs

#LineLine coverage
 1using Elsa.Abstractions;
 2using Elsa.Common.Entities;
 3using Elsa.Common.Models;
 4using Elsa.Models;
 5using Elsa.Workflows.Api.Models;
 6using Elsa.Workflows.Management;
 7using Elsa.Workflows.Management.Filters;
 8using Elsa.Workflows.Management.Models;
 9using JetBrains.Annotations;
 10
 11namespace Elsa.Workflows.Api.Endpoints.WorkflowDefinitions.List;
 12
 13[PublicAPI]
 114internal class List(IWorkflowDefinitionStore store, IWorkflowDefinitionLinker linker) : ElsaEndpoint<Request, PagedListR
 15{
 16    public override void Configure()
 17    {
 118        Get("/workflow-definitions");
 119        ConfigurePermissions("read:workflow-definitions");
 120    }
 21
 22    public override async Task<PagedListResponse<LinkedWorkflowDefinitionSummary>> ExecuteAsync(Request request, Cancell
 23    {
 024        var pageArgs = PageArgs.FromPage(request.Page, request.PageSize);
 025        var filter = CreateFilter(request);
 026        var summaries = await FindAsync(request, filter, pageArgs, cancellationToken);
 027        var pagedList = new PagedListResponse<WorkflowDefinitionSummary>(summaries);
 028        var response = linker.MapAsync(pagedList);
 029        return response;
 030    }
 31
 32    private WorkflowDefinitionFilter CreateFilter(Request request)
 33    {
 034        var versionOptions = string.IsNullOrWhiteSpace(request.VersionOptions) ? default(VersionOptions?) : VersionOptio
 35
 036        return new()
 037        {
 038            IsSystem = request.IsSystem,
 039            VersionOptions = versionOptions,
 040            SearchTerm = request.SearchTerm?.Trim(),
 041            MaterializerName = request.MaterializerName,
 042            DefinitionIds = request.DefinitionIds,
 043            Ids = request.Ids
 044        };
 45    }
 46
 47    private async Task<Page<WorkflowDefinitionSummary>> FindAsync(Request request, WorkflowDefinitionFilter filter, Page
 48    {
 049        request.OrderBy ??= OrderByWorkflowDefinition.Name;
 50
 051        var direction = request.OrderBy == OrderByWorkflowDefinition.Name ? request.OrderDirection ?? OrderDirection.Asc
 52
 053        switch (request.OrderBy)
 54        {
 55            default:
 56                {
 057                    var order = new WorkflowDefinitionOrder<DateTimeOffset>
 058                    {
 059                        KeySelector = p => p.CreatedAt,
 060                        Direction = direction
 061                    };
 62
 063                    return await store.FindSummariesAsync(filter, order, pageArgs, cancellationToken);
 64                }
 65            case OrderByWorkflowDefinition.Name:
 66                {
 067                    var order = new WorkflowDefinitionOrder<string>
 068                    {
 069                        KeySelector = p => p.Name!,
 070                        Direction = direction
 071                    };
 72
 073                    return await store.FindSummariesAsync(filter, order, pageArgs, cancellationToken);
 74                }
 75            case OrderByWorkflowDefinition.Version:
 76                {
 077                    var order = new WorkflowDefinitionOrder<int>
 078                    {
 079                        KeySelector = p => p.Version,
 080                        Direction = direction
 081                    };
 82
 083                    return await store.FindSummariesAsync(filter, order, pageArgs, cancellationToken);
 84                }
 85        }
 086    }
 87}