| | | 1 | | using Elsa.Authorization; |
| | | 2 | | using Elsa.Abstractions; |
| | | 3 | | using Elsa.Extensions; |
| | | 4 | | using Elsa.Workflows.Management; |
| | | 5 | | using JetBrains.Annotations; |
| | | 6 | | |
| | | 7 | | namespace Elsa.Workflows.Api.Endpoints.WorkflowInstances.ExecutionState; |
| | | 8 | | |
| | | 9 | | /// <summary> |
| | | 10 | | /// Returns the execution state of the specified workflow instance. |
| | | 11 | | /// </summary> |
| | | 12 | | [PublicAPI] |
| | 3 | 13 | | internal class ExecutionState(IWorkflowInstanceStore store) : ElsaEndpoint<Request, Response> |
| | | 14 | | { |
| | | 15 | | /// <inheritdoc /> |
| | | 16 | | public override void Configure() |
| | | 17 | | { |
| | 3 | 18 | | Get("/workflow-instances/{id}/execution-state"); |
| | 3 | 19 | | RequirePermission(Elsa.Workflows.Api.Permissions.WorkflowPermissions.Instances, CoreVerbs.View); |
| | 3 | 20 | | } |
| | | 21 | | |
| | | 22 | | /// <inheritdoc /> |
| | | 23 | | public override async Task HandleAsync(Request request, CancellationToken cancellationToken) |
| | | 24 | | { |
| | 0 | 25 | | var workflowInstance = await store.FindAsync(request.WorkflowInstanceId, cancellationToken); |
| | | 26 | | |
| | 0 | 27 | | if (workflowInstance == null) |
| | | 28 | | { |
| | 0 | 29 | | await Send.NotFoundAsync(cancellationToken); |
| | 0 | 30 | | return; |
| | | 31 | | } |
| | | 32 | | |
| | 0 | 33 | | var response = new Response( |
| | 0 | 34 | | workflowInstance.Status, |
| | 0 | 35 | | workflowInstance.SubStatus, |
| | 0 | 36 | | workflowInstance.UpdatedAt); |
| | | 37 | | |
| | 0 | 38 | | await Send.OkAsync(response, cancellationToken); |
| | 0 | 39 | | } |
| | | 40 | | } |