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:
parent
35143d99ec
commit
551c91bb4f
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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);
|
||||
Loading…
Reference in a new issue