From 551c91bb4f1c73dad0806b50ab389bae7f2ee60b Mon Sep 17 00:00:00 2001 From: Sipke Schoorstra Date: Fri, 7 Jun 2024 18:24:20 +0200 Subject: [PATCH] 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. --- .../Endpoints/WorkflowDefinitions/Post/Endpoint.cs | 10 ++-------- .../Endpoints/WorkflowDefinitions/Post/Models.cs | 2 +- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/Post/Endpoint.cs b/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/Post/Endpoint.cs index 75d4ad93b..1897b8cb1 100644 --- a/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/Post/Endpoint.cs +++ b/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/Post/Endpoint.cs @@ -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(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); } } \ No newline at end of file diff --git a/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/Post/Models.cs b/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/Post/Models.cs index b41310a68..baceba1df 100644 --- a/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/Post/Models.cs +++ b/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/Post/Models.cs @@ -2,4 +2,4 @@ using Elsa.Workflows.Api.Models; namespace Elsa.Workflows.Api.Endpoints.WorkflowDefinitions.Post; -internal record Response(LinkedWorkflowDefinitionModel WorkflowDefinition, int ConsumingWorkflowCount); \ No newline at end of file +internal record Response(LinkedWorkflowDefinitionModel WorkflowDefinition, bool AlreadyPublished, int ConsumingWorkflowCount); \ No newline at end of file