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