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