| | | 1 | | using Elsa.Authorization; |
| | | 2 | | using Elsa.Abstractions; |
| | | 3 | | using Elsa.Common.Entities; |
| | | 4 | | using Elsa.Workflows.Runtime; |
| | | 5 | | using Elsa.Workflows.Runtime.Entities; |
| | | 6 | | using Elsa.Workflows.Runtime.Filters; |
| | | 7 | | using Elsa.Workflows.Runtime.OrderDefinitions; |
| | | 8 | | using JetBrains.Annotations; |
| | | 9 | | |
| | | 10 | | namespace 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] |
| | 3 | 16 | | public class Get(IWorkflowExecutionLogStore store) : ElsaEndpoint<Request, WorkflowExecutionLogRecord> |
| | | 17 | | { |
| | | 18 | | /// <inheritdoc /> |
| | | 19 | | public override void Configure() |
| | | 20 | | { |
| | 3 | 21 | | Get("/workflow-instances/{workflowInstanceId}/journal/{activityId}"); |
| | 3 | 22 | | RequirePermission(Elsa.Workflows.Api.Permissions.WorkflowPermissions.Instances, CoreVerbs.View); |
| | 3 | 23 | | } |
| | | 24 | | |
| | | 25 | | /// <inheritdoc /> |
| | | 26 | | public override async Task HandleAsync(Request request, CancellationToken cancellationToken) |
| | | 27 | | { |
| | 0 | 28 | | var filter = new WorkflowExecutionLogRecordFilter |
| | 0 | 29 | | { |
| | 0 | 30 | | WorkflowInstanceId = request.WorkflowInstanceId, |
| | 0 | 31 | | ActivityId = request.ActivityId, |
| | 0 | 32 | | EventNames = ["Started", "Completed", "Faulted"] |
| | 0 | 33 | | }; |
| | | 34 | | |
| | 0 | 35 | | var sort = new WorkflowExecutionLogRecordOrder<DateTimeOffset>( |
| | 0 | 36 | | x => x.Timestamp, |
| | 0 | 37 | | OrderDirection.Descending |
| | 0 | 38 | | ); |
| | | 39 | | |
| | 0 | 40 | | var entry = await store.FindAsync(filter, sort, cancellationToken); |
| | | 41 | | |
| | 0 | 42 | | if (entry == null) |
| | | 43 | | { |
| | 0 | 44 | | await Send.NotFoundAsync(cancellationToken); |
| | 0 | 45 | | return; |
| | | 46 | | } |
| | | 47 | | |
| | 0 | 48 | | await Send.OkAsync(entry, cancellationToken); |
| | 0 | 49 | | } |
| | | 50 | | } |