| | | 1 | | using Elsa.Abstractions; |
| | | 2 | | using Elsa.Models; |
| | | 3 | | using Elsa.Workflows.Runtime; |
| | | 4 | | using Elsa.Workflows.Runtime.Filters; |
| | | 5 | | using JetBrains.Annotations; |
| | | 6 | | |
| | | 7 | | namespace Elsa.Workflows.Api.Endpoints.ActivityExecutions.Count; |
| | | 8 | | |
| | | 9 | | /// <summary> |
| | | 10 | | /// Counts the number of executions for a given activity. |
| | | 11 | | /// </summary> |
| | | 12 | | [PublicAPI] |
| | | 13 | | internal class Count : ElsaEndpoint<Request, CountResponse> |
| | | 14 | | { |
| | | 15 | | private readonly IActivityExecutionStore _store; |
| | | 16 | | |
| | | 17 | | /// <inheritdoc /> |
| | 1 | 18 | | public Count(IActivityExecutionStore store) |
| | | 19 | | { |
| | 1 | 20 | | _store = store; |
| | 1 | 21 | | } |
| | | 22 | | |
| | | 23 | | /// <inheritdoc /> |
| | | 24 | | public override void Configure() |
| | | 25 | | { |
| | 1 | 26 | | Get("/activity-executions/count"); |
| | 1 | 27 | | ConfigurePermissions("read:activity-execution"); |
| | 1 | 28 | | } |
| | | 29 | | |
| | | 30 | | /// <inheritdoc /> |
| | | 31 | | public override async Task<CountResponse> ExecuteAsync(Request request, CancellationToken cancellationToken) |
| | | 32 | | { |
| | 0 | 33 | | var filter = new ActivityExecutionRecordFilter |
| | 0 | 34 | | { |
| | 0 | 35 | | WorkflowInstanceId = request.WorkflowInstanceId, |
| | 0 | 36 | | ActivityId = request.ActivityId, |
| | 0 | 37 | | Completed = request.Completed |
| | 0 | 38 | | }; |
| | 0 | 39 | | var count = await _store.CountAsync(filter, cancellationToken); |
| | 0 | 40 | | return new CountResponse(count); |
| | 0 | 41 | | } |
| | | 42 | | } |