Refactor response handling in workflow API

Simplified the response creation and sending in the `Post` endpoint of `WorkflowDefinitions` in the `Elsa.Workflows.Api` module. Previous logic was replaced with a streamlined approach of creating and sending the JSON response. Additionally, `Response` data model in the same endpoint has been updated to include an `AlreadyPublished` field.
This commit is contained in:
Sipke Schoorstra 2024-06-07 18:24:20 +02:00
parent 35143d99ec
commit 551c91bb4f
2 changed files with 3 additions and 9 deletions

View file

@ -113,13 +113,7 @@ internal class Post(
}
var mappedDefinition = await linker.MapAsync(draft, cancellationToken);
var response = new Response(mappedDefinition, result?.ConsumingWorkflows?.Count() ?? 0);
if (isNew)
await SendCreatedAtAsync<GetByDefinitionId.GetByDefinitionId>(new { definitionId }, mappedDefinition, cancellation: cancellationToken);
else
{
await HttpContext.Response.WriteAsJsonAsync(response, serializerOptions, cancellationToken);
}
var response = new Response(mappedDefinition, false, result?.ConsumingWorkflows?.Count() ?? 0);
await HttpContext.Response.WriteAsJsonAsync(response, serializerOptions, cancellationToken);
}
}

View file

@ -2,4 +2,4 @@ using Elsa.Workflows.Api.Models;
namespace Elsa.Workflows.Api.Endpoints.WorkflowDefinitions.Post;
internal record Response(LinkedWorkflowDefinitionModel WorkflowDefinition, int ConsumingWorkflowCount);
internal record Response(LinkedWorkflowDefinitionModel WorkflowDefinition, bool AlreadyPublished, int ConsumingWorkflowCount);