| | | 1 | | using Elsa.Authorization; |
| | | 2 | | using Elsa.Abstractions; |
| | | 3 | | using Elsa.Workflows.Runtime; |
| | | 4 | | using Elsa.Workflows.Runtime.Entities; |
| | | 5 | | using Elsa.Workflows.Runtime.Filters; |
| | | 6 | | using JetBrains.Annotations; |
| | | 7 | | |
| | | 8 | | namespace Elsa.Workflows.Api.Endpoints.ActivityExecutions.Get; |
| | | 9 | | |
| | | 10 | | /// <summary> |
| | | 11 | | /// Gets an individual execution for a given activity. |
| | | 12 | | /// </summary> |
| | | 13 | | [PublicAPI] |
| | 4 | 14 | | internal class Endpoint(IActivityExecutionStore store) : ElsaEndpointWithoutRequest<ActivityExecutionRecord> |
| | | 15 | | { |
| | | 16 | | /// <inheritdoc /> |
| | | 17 | | public override void Configure() |
| | | 18 | | { |
| | 4 | 19 | | Get("/activity-executions/{id}", "/activity-executions/{*id}", "/activity-executions/by-id"); |
| | 4 | 20 | | RequirePermission(Elsa.Workflows.Api.Permissions.WorkflowPermissions.ActivityExecutions, CoreVerbs.View); |
| | 4 | 21 | | } |
| | | 22 | | |
| | | 23 | | /// <inheritdoc /> |
| | | 24 | | public override async Task HandleAsync(CancellationToken cancellationToken) |
| | | 25 | | { |
| | 0 | 26 | | var id = Query<string>("id", false) ?? Route<string>("id", false); |
| | | 27 | | |
| | 0 | 28 | | if (string.IsNullOrWhiteSpace(id)) |
| | | 29 | | { |
| | 0 | 30 | | AddError("The activity execution ID is required."); |
| | 0 | 31 | | await Send.ErrorsAsync(cancellation: cancellationToken); |
| | 0 | 32 | | return; |
| | | 33 | | } |
| | | 34 | | |
| | 0 | 35 | | var filter = new ActivityExecutionRecordFilter |
| | 0 | 36 | | { |
| | 0 | 37 | | Id = id |
| | 0 | 38 | | }; |
| | | 39 | | |
| | 0 | 40 | | var record = await store.FindAsync(filter, cancellationToken); |
| | | 41 | | |
| | 0 | 42 | | if (record == null) |
| | | 43 | | { |
| | 0 | 44 | | await Send.NotFoundAsync(cancellationToken); |
| | 0 | 45 | | return; |
| | | 46 | | } |
| | | 47 | | |
| | 0 | 48 | | await Send.OkAsync(record, cancellationToken); |
| | 0 | 49 | | } |
| | | 50 | | } |