< Summary

Information
Class: Elsa.Workflows.Api.Endpoints.WorkflowInstances.Journal.GetLastEntry.Get
Assembly: Elsa.Workflows.Api
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowInstances/Journal/GetLastEntry/Endpoint.cs
Line coverage
20%
Covered lines: 4
Uncovered lines: 16
Coverable lines: 20
Total lines: 49
Line coverage: 20%
Branch coverage
0%
Covered branches: 0
Total branches: 2
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%
HandleAsync()0%620%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowInstances/Journal/GetLastEntry/Endpoint.cs

#LineLine coverage
 1using Elsa.Abstractions;
 2using Elsa.Common.Entities;
 3using Elsa.Workflows.Runtime;
 4using Elsa.Workflows.Runtime.Entities;
 5using Elsa.Workflows.Runtime.Filters;
 6using Elsa.Workflows.Runtime.OrderDefinitions;
 7using JetBrains.Annotations;
 8
 9namespace Elsa.Workflows.Api.Endpoints.WorkflowInstances.Journal.GetLastEntry;
 10
 11/// <summary>
 12/// Return the last log entry for the specified workflow instance and activity ID.
 13/// </summary>
 14[PublicAPI]
 115public class Get(IWorkflowExecutionLogStore store) : ElsaEndpoint<Request, WorkflowExecutionLogRecord>
 16{
 17    /// <inheritdoc />
 18    public override void Configure()
 19    {
 120        Get("/workflow-instances/{workflowInstanceId}/journal/{activityId}");
 121        ConfigurePermissions("read:workflow-instances");
 122    }
 23
 24    /// <inheritdoc />
 25    public override async Task HandleAsync(Request request, CancellationToken cancellationToken)
 26    {
 027        var filter = new WorkflowExecutionLogRecordFilter
 028        {
 029            WorkflowInstanceId = request.WorkflowInstanceId,
 030            ActivityId = request.ActivityId,
 031            EventNames = ["Started", "Completed", "Faulted"]
 032        };
 33
 034        var sort = new WorkflowExecutionLogRecordOrder<DateTimeOffset>(
 035            x => x.Timestamp,
 036            OrderDirection.Descending
 037        );
 38
 039        var entry = await store.FindAsync(filter, sort, cancellationToken);
 40
 041        if (entry == null)
 42        {
 043            await Send.NotFoundAsync(cancellationToken);
 044            return;
 45        }
 46
 047        await Send.OkAsync(entry, cancellationToken);
 048    }
 49}