| | | 1 | | using Elsa.Abstractions; |
| | | 2 | | using Elsa.Alterations.Core.Contracts; |
| | | 3 | | using Elsa.Alterations.Core.Models; |
| | | 4 | | using JetBrains.Annotations; |
| | | 5 | | using Microsoft.AspNetCore.Http; |
| | | 6 | | |
| | | 7 | | namespace Elsa.Alterations.Endpoints.Alterations.DryRun; |
| | | 8 | | |
| | | 9 | | /// <summary> |
| | | 10 | | /// Determines which workflow instances a "Submit" request would target without actually running an alteration. |
| | | 11 | | /// </summary> |
| | | 12 | | [PublicAPI] |
| | 13 | 13 | | public class DryRun(IWorkflowInstanceFinder workflowInstanceFinder) : ElsaEndpoint<AlterationWorkflowInstanceFilter, Res |
| | | 14 | | { |
| | | 15 | | /// <inheritdoc /> |
| | | 16 | | public override void Configure() |
| | | 17 | | { |
| | 10 | 18 | | Post("/alterations/dry-run"); |
| | 10 | 19 | | ConfigurePermissions("run:alterations"); |
| | 10 | 20 | | } |
| | | 21 | | |
| | | 22 | | /// <inheritdoc /> |
| | | 23 | | public override async Task HandleAsync(AlterationWorkflowInstanceFilter filter, CancellationToken cancellationToken) |
| | | 24 | | { |
| | 3 | 25 | | if (!ValidateInput(filter)) |
| | | 26 | | { |
| | 3 | 27 | | await Send.ErrorsAsync(StatusCodes.Status400BadRequest, cancellationToken); |
| | 3 | 28 | | return; |
| | | 29 | | } |
| | | 30 | | |
| | 0 | 31 | | var workflowInstanceIds = await workflowInstanceFinder.FindAsync(filter, cancellationToken); |
| | 0 | 32 | | var response = new Response(workflowInstanceIds.ToList()); |
| | 0 | 33 | | await Send.OkAsync(response, cancellationToken); |
| | 3 | 34 | | } |
| | | 35 | | |
| | | 36 | | private bool ValidateInput(AlterationWorkflowInstanceFilter filter) |
| | | 37 | | { |
| | 7 | 38 | | return TimestampFilterValidation.Validate(filter.TimestampFilters, error => AddError(error)); |
| | | 39 | | } |
| | | 40 | | } |