From 1d4d3ea10866541bc7fe94add04721032554f2da Mon Sep 17 00:00:00 2001 From: Raymond den Haan Date: Thu, 30 May 2024 16:21:15 +0200 Subject: [PATCH] Extend publish workflow response Added IsPublished property to response instead of sending separate message. --- .../Responses/SaveWorkflowDefinitionResponse.cs | 2 +- .../WorkflowDefinitions/Publish/Endpoint.cs | 14 +++++++------- .../WorkflowDefinitions/Publish/Models.cs | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/clients/Elsa.Api.Client/Resources/WorkflowDefinitions/Responses/SaveWorkflowDefinitionResponse.cs b/src/clients/Elsa.Api.Client/Resources/WorkflowDefinitions/Responses/SaveWorkflowDefinitionResponse.cs index 52fef142c..8ead87853 100644 --- a/src/clients/Elsa.Api.Client/Resources/WorkflowDefinitions/Responses/SaveWorkflowDefinitionResponse.cs +++ b/src/clients/Elsa.Api.Client/Resources/WorkflowDefinitions/Responses/SaveWorkflowDefinitionResponse.cs @@ -5,4 +5,4 @@ namespace Elsa.Api.Client.Resources.WorkflowDefinitions.Responses; /// /// Represents the response for saving a workflow definition. /// -public record SaveWorkflowDefinitionResponse(WorkflowDefinition WorkflowDefinition, int ConsumingWorkflowCount); \ No newline at end of file +public record SaveWorkflowDefinitionResponse(WorkflowDefinition WorkflowDefinition, bool AlreadyPublished, int ConsumingWorkflowCount); \ No newline at end of file diff --git a/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/Publish/Endpoint.cs b/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/Publish/Endpoint.cs index 2e46b8510..325664702 100644 --- a/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/Publish/Endpoint.cs +++ b/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/Publish/Endpoint.cs @@ -7,6 +7,7 @@ using Elsa.Workflows.Api.Requirements; using Elsa.Workflows.Contracts; using Elsa.Workflows.Management.Contracts; using Elsa.Workflows.Management.Filters; +using Elsa.Workflows.Management.Models; using Elsa.Workflows.Serialization.Converters; using JetBrains.Annotations; using Microsoft.AspNetCore.Authorization; @@ -48,16 +49,15 @@ internal class Publish(IWorkflowDefinitionStore store, IWorkflowDefinitionPublis return; } - if (definition.IsPublished) + PublishWorkflowDefinitionResult? result = null; + var isPublished = definition.IsPublished; + if (!isPublished) { - await SendStringAsync($"Workflow with id {request.DefinitionId} is already published"); - return; + result = await workflowDefinitionPublisher.PublishAsync(definition, cancellationToken); } - - var result = await workflowDefinitionPublisher.PublishAsync(definition, cancellationToken); - + var mappedDefinition = await linker.MapAsync(definition, cancellationToken); - var response = new Response(mappedDefinition, result.ConsumingWorkflows?.Count() ?? 0); + var response = new Response(mappedDefinition, isPublished, result?.ConsumingWorkflows?.Count() ?? 0); // We do not want to include composite root activities in the response. var serializerOptions = serializer.GetOptions().Clone(); diff --git a/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/Publish/Models.cs b/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/Publish/Models.cs index d16834475..a4ed95916 100644 --- a/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/Publish/Models.cs +++ b/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/Publish/Models.cs @@ -7,4 +7,4 @@ internal class Request public string DefinitionId { get; set; } = default!; } -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