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