| | | 1 | | using Elsa.Abstractions; |
| | | 2 | | using Elsa.Models; |
| | | 3 | | using Elsa.Workflows.Management; |
| | | 4 | | using JetBrains.Annotations; |
| | | 5 | | using Microsoft.AspNetCore.Http; |
| | | 6 | | using Open.Linq.AsyncExtensions; |
| | | 7 | | |
| | | 8 | | namespace Elsa.Workflows.Api.Endpoints.WorkflowInstances.Variables.Post; |
| | | 9 | | |
| | | 10 | | [UsedImplicitly] |
| | 1 | 11 | | internal class List(IWorkflowInstanceVariableManager workflowInstanceVariableManager) : ElsaEndpoint<Request, ListRespon |
| | | 12 | | { |
| | | 13 | | public override void Configure() |
| | | 14 | | { |
| | 1 | 15 | | Post("/workflow-instances/{id}/variables"); |
| | 1 | 16 | | ConfigurePermissions("write:workflow-instances"); |
| | 1 | 17 | | } |
| | | 18 | | |
| | | 19 | | public override async Task HandleAsync(Request request, CancellationToken cancellationToken) |
| | | 20 | | { |
| | 0 | 21 | | var workflowInstanceId = Route<string>("id"); |
| | | 22 | | |
| | 0 | 23 | | if (string.IsNullOrWhiteSpace(workflowInstanceId)) |
| | | 24 | | { |
| | 0 | 25 | | AddError("The workflow instance ID is required."); |
| | 0 | 26 | | await Send.ErrorsAsync(StatusCodes.Status400BadRequest, cancellationToken); |
| | 0 | 27 | | return; |
| | | 28 | | } |
| | | 29 | | |
| | 0 | 30 | | var resolvedVariables = await workflowInstanceVariableManager.SetVariablesAsync(workflowInstanceId, request.Vari |
| | 0 | 31 | | var variableModels = resolvedVariables.Select(x => new ResolvedVariableModel(x.Variable.Id, x.Variable.Name, x.V |
| | 0 | 32 | | var response = new ListResponse<ResolvedVariableModel>(variableModels); |
| | 0 | 33 | | await Send.OkAsync(response, cancellationToken); |
| | 0 | 34 | | } |
| | | 35 | | } |
| | | 36 | | |
| | | 37 | | internal class Request |
| | | 38 | | { |
| | | 39 | | public ICollection<VariableUpdateValue> Variables { get; set; } = null!; |
| | | 40 | | } |
| | | 41 | | |
| | | 42 | | internal record ResolvedVariableModel(string Id, string Name, object? Value); |