< 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: 50
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
 035        var sort = new WorkflowExecutionLogRecordOrder<DateTimeOffset>(
 036            x => x.Timestamp,
 037            OrderDirection.Descending
 038        );
 39
 040        var entry = await store.FindAsync(filter, sort, cancellationToken);
 41
 042        if (entry == null)
 43        {
 044            await Send.NotFoundAsync(cancellationToken);
 045            return;
 46        }
 47
 048        await Send.OkAsync(entry, cancellationToken);
 049    }
 50}