| | | 1 | | using Elsa.Abstractions; |
| | | 2 | | using Elsa.Common.Entities; |
| | | 3 | | using Elsa.Common.Models; |
| | | 4 | | using Elsa.Workflows.Api.Models; |
| | | 5 | | using Elsa.Workflows.Runtime; |
| | | 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.List; |
| | | 11 | | |
| | | 12 | | /// <summary> |
| | | 13 | | /// Gets the journal for a workflow instance. |
| | | 14 | | /// </summary> |
| | | 15 | | [PublicAPI] |
| | | 16 | | internal class Get : ElsaEndpoint<Request, Response> |
| | | 17 | | { |
| | | 18 | | private readonly IWorkflowExecutionLogStore _store; |
| | | 19 | | |
| | | 20 | | /// <inheritdoc /> |
| | 1 | 21 | | public Get(IWorkflowExecutionLogStore store) |
| | | 22 | | { |
| | 1 | 23 | | _store = store; |
| | 1 | 24 | | } |
| | | 25 | | |
| | | 26 | | /// <inheritdoc /> |
| | | 27 | | public override void Configure() |
| | | 28 | | { |
| | 1 | 29 | | Get("/workflow-instances/{id}/journal"); |
| | 1 | 30 | | ConfigurePermissions("read:workflow-instances"); |
| | 1 | 31 | | } |
| | | 32 | | |
| | | 33 | | /// <inheritdoc /> |
| | | 34 | | public override async Task<Response> ExecuteAsync(Request request, CancellationToken cancellationToken) |
| | | 35 | | { |
| | 0 | 36 | | var pageArgs = PageArgs.From(request.Page, request.PageSize, request.Skip, request.Take); |
| | 0 | 37 | | var filter = new WorkflowExecutionLogRecordFilter { WorkflowInstanceId = request.WorkflowInstanceId }; |
| | 0 | 38 | | var order = new WorkflowExecutionLogRecordOrder<long>(x => x.Sequence, OrderDirection.Ascending); |
| | 0 | 39 | | var pageOfRecords = await _store.FindManyAsync(filter, pageArgs, order, cancellationToken); |
| | | 40 | | |
| | 0 | 41 | | var models = pageOfRecords.Items.Select(x => |
| | 0 | 42 | | new ExecutionLogRecord( |
| | 0 | 43 | | x.Id, |
| | 0 | 44 | | x.ActivityInstanceId, |
| | 0 | 45 | | x.ParentActivityInstanceId, |
| | 0 | 46 | | x.ActivityId, |
| | 0 | 47 | | x.ActivityType, |
| | 0 | 48 | | x.ActivityTypeVersion, |
| | 0 | 49 | | x.ActivityName, |
| | 0 | 50 | | x.ActivityNodeId, |
| | 0 | 51 | | x.Timestamp, |
| | 0 | 52 | | x.Sequence, |
| | 0 | 53 | | x.EventName, |
| | 0 | 54 | | x.Message, |
| | 0 | 55 | | x.Source, |
| | 0 | 56 | | x.ActivityState, |
| | 0 | 57 | | x.Payload)) |
| | 0 | 58 | | .ToList(); |
| | | 59 | | |
| | 0 | 60 | | return new(models, pageOfRecords.TotalCount); |
| | 0 | 61 | | } |
| | | 62 | | } |