Extend publish workflow response

Added IsPublished property to response instead of sending separate message.
This commit is contained in:
Raymond den Haan 2024-05-30 16:21:15 +02:00 committed by raymonddenhaan
parent b05449c031
commit 1d4d3ea108
3 changed files with 9 additions and 9 deletions

View file

@ -5,4 +5,4 @@ namespace Elsa.Api.Client.Resources.WorkflowDefinitions.Responses;
/// <summary>
/// Represents the response for saving a workflow definition.
/// </summary>
public record SaveWorkflowDefinitionResponse(WorkflowDefinition WorkflowDefinition, int ConsumingWorkflowCount);
public record SaveWorkflowDefinitionResponse(WorkflowDefinition WorkflowDefinition, bool AlreadyPublished, int ConsumingWorkflowCount);

View file

@ -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();

View file

@ -7,4 +7,4 @@ internal class Request
public string DefinitionId { get; set; } = default!;
}
internal record Response(LinkedWorkflowDefinitionModel WorkflowDefinition, int ConsumingWorkflowCount);
internal record Response(LinkedWorkflowDefinitionModel WorkflowDefinition, bool AlreadyPublished, int ConsumingWorkflowCount);