< 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: 52
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.Authorization;
 2using Elsa.Abstractions;
 3using Elsa.Common.Entities;
 4using Elsa.Workflows.Runtime;
 5using Elsa.Workflows.Runtime.Entities;
 6using Elsa.Workflows.Runtime.Filters;
 7using Elsa.Workflows.Runtime.OrderDefinitions;
 8using JetBrains.Annotations;
 9
 10namespace Elsa.Workflows.Api.Endpoints.WorkflowInstances.Journal.GetLastEntry;
 11
 12/// <summary>
 13/// Return the last log entry for the specified workflow instance and activity ID.
 14/// </summary>
 15[PublicAPI]
 316public class Get(IWorkflowExecutionLogStore store) : ElsaEndpoint<Request, WorkflowExecutionLogRecord>
 17{
 18    /// <inheritdoc />
 19    public override void Configure()
 20    {
 321        Get("/workflow-instances/{workflowInstanceId}/journal/{activityId}");
 322        RequirePermission(Elsa.Workflows.Api.Permissions.WorkflowPermissions.Instances, CoreVerbs.View);
 323    }
 24
 25    /// <inheritdoc />
 26    public override async Task HandleAsync(Request request, CancellationToken cancellationToken)
 27    {
 028        var filter = new WorkflowExecutionLogRecordFilter
 029        {
 030            WorkflowInstanceId = request.WorkflowInstanceId,
 031            ActivityId = request.ActivityId,
 032            EventNames = ["Started", "Completed", "Faulted"]
 033        };
 34
 35        // Sequence is the instance-monotonic event cursor. Same-timestamp batches must not
 36        // pick an arbitrary "last" entry when only Timestamp descending is applied.
 037        var sort = new WorkflowExecutionLogRecordOrder<long>(
 038            x => x.Sequence,
 039            OrderDirection.Descending
 040        );
 41
 042        var entry = await store.FindAsync(filter, sort, cancellationToken);
 43
 044        if (entry == null)
 45        {
 046            await Send.NotFoundAsync(cancellationToken);
 047            return;
 48        }
 49
 050        await Send.OkAsync(entry, cancellationToken);
 051    }
 52}