diff --git a/src/modules/Elsa.Expressions.JavaScript/Endpoints/TypeDefinitions/Endpoint.cs b/src/modules/Elsa.Expressions.JavaScript/Endpoints/TypeDefinitions/Endpoint.cs index 66f61eaf20..caf9dd2a11 100644 --- a/src/modules/Elsa.Expressions.JavaScript/Endpoints/TypeDefinitions/Endpoint.cs +++ b/src/modules/Elsa.Expressions.JavaScript/Endpoints/TypeDefinitions/Endpoint.cs @@ -56,11 +56,4 @@ public override async Task HandleAsync(Request request, CancellationToken cancel { return await _workflowDefinitionService.FindWorkflowGraphAsync(workflowDefinitionId, VersionOptions.Latest, cancellationToken); } -} - -internal record Request(string WorkflowDefinitionId, string? ActivityTypeName, string? PropertyName) -{ - public Request() : this(default!, default!, default) - { - } } \ No newline at end of file diff --git a/src/modules/Elsa.Expressions.JavaScript/Endpoints/TypeDefinitions/Models.cs b/src/modules/Elsa.Expressions.JavaScript/Endpoints/TypeDefinitions/Models.cs new file mode 100644 index 0000000000..944b551361 --- /dev/null +++ b/src/modules/Elsa.Expressions.JavaScript/Endpoints/TypeDefinitions/Models.cs @@ -0,0 +1,8 @@ +namespace Elsa.Expressions.JavaScript.Endpoints.TypeDefinitions; + +internal record Request(string WorkflowDefinitionId, string? ActivityTypeName, string? PropertyName) +{ + public Request() : this(default!, default!, default) + { + } +} \ No newline at end of file diff --git a/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/GetByDefinitionId/Endpoint.cs b/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/GetByDefinitionId/Endpoint.cs index 4b2fbe9e7b..c87e63b53c 100644 --- a/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/GetByDefinitionId/Endpoint.cs +++ b/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/GetByDefinitionId/Endpoint.cs @@ -1,5 +1,6 @@ using Elsa.Abstractions; using Elsa.Common.Models; +using Elsa.Workflows.Api.Models; using Elsa.Workflows.Management; using Elsa.Workflows.Models; using JetBrains.Annotations; @@ -7,7 +8,7 @@ namespace Elsa.Workflows.Api.Endpoints.WorkflowDefinitions.GetByDefinitionId; [PublicAPI] -internal class GetByDefinitionId(IWorkflowDefinitionStore store, IWorkflowDefinitionLinker linker) : ElsaEndpoint +internal class GetByDefinitionId(IWorkflowDefinitionStore store, IWorkflowDefinitionLinker linker) : ElsaEndpoint { public override void Configure() { @@ -15,7 +16,7 @@ public override void Configure() ConfigurePermissions("read:workflow-definitions"); } - public override async Task HandleAsync(Request request, CancellationToken cancellationToken) + public override async Task ExecuteAsync(Request request, CancellationToken cancellationToken) { var versionOptions = request.VersionOptions != null ? VersionOptions.FromString(request.VersionOptions) : VersionOptions.Latest; var filter = WorkflowDefinitionHandle.ByDefinitionId(request.DefinitionId, versionOptions).ToFilter(); @@ -24,10 +25,10 @@ public override async Task HandleAsync(Request request, CancellationToken cancel if (definition == null) { await SendNotFoundAsync(cancellationToken); - return; + return null!; } var model = await linker.MapAsync(definition, cancellationToken); - await SendOkAsync(model, cancellationToken); + return model; } } \ No newline at end of file diff --git a/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/GetById/Endpoint.cs b/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/GetById/Endpoint.cs index 24cf2baf47..c20478d33a 100644 --- a/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/GetById/Endpoint.cs +++ b/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/GetById/Endpoint.cs @@ -1,4 +1,5 @@ using Elsa.Abstractions; +using Elsa.Workflows.Api.Models; using Elsa.Workflows.Management; using Elsa.Workflows.Management.Filters; using JetBrains.Annotations; @@ -7,7 +8,7 @@ namespace Elsa.Workflows.Api.Endpoints.WorkflowDefinitions.GetById; [PublicAPI] -internal class GetById(IWorkflowDefinitionStore store, IWorkflowDefinitionLinker linker) : ElsaEndpoint +internal class GetById(IWorkflowDefinitionStore store, IWorkflowDefinitionLinker linker) : ElsaEndpoint { public override void Configure() { @@ -16,7 +17,7 @@ public override void Configure() Options(x => x.WithName("GetWorkflowDefinitionById")); } - public override async Task HandleAsync(Request request, CancellationToken cancellationToken) + public override async Task ExecuteAsync(Request request, CancellationToken cancellationToken) { var filter = new WorkflowDefinitionFilter { @@ -28,10 +29,10 @@ public override async Task HandleAsync(Request request, CancellationToken cancel if (definition == null) { await SendNotFoundAsync(cancellationToken); - return; + return null!; } var model = await linker.MapAsync(definition, cancellationToken); - await SendOkAsync(model, cancellationToken); + return model; } } \ No newline at end of file diff --git a/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/GetManyById/Endpoint.cs b/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/GetManyById/Endpoint.cs index 75899b710c..a1ba60e65c 100644 --- a/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/GetManyById/Endpoint.cs +++ b/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/GetManyById/Endpoint.cs @@ -8,7 +8,7 @@ namespace Elsa.Workflows.Api.Endpoints.WorkflowDefinitions.GetManyById; [PublicAPI] -internal class GetManyById(IWorkflowDefinitionStore store, IWorkflowDefinitionLinker linker) : ElsaEndpoint +internal class GetManyById(IWorkflowDefinitionStore store, IWorkflowDefinitionLinker linker) : ElsaEndpoint> { public override void Configure() { @@ -16,7 +16,7 @@ public override void Configure() ConfigurePermissions("read:workflow-definitions"); } - public override async Task HandleAsync(Request request, CancellationToken cancellationToken) + public override async Task> ExecuteAsync(Request request, CancellationToken cancellationToken) { var filter = new WorkflowDefinitionFilter { @@ -26,6 +26,6 @@ public override async Task HandleAsync(Request request, CancellationToken cancel var definitions = (await store.FindManyAsync(filter, cancellationToken)).ToList(); var models = await linker.MapAsync(definitions, cancellationToken); var response = new ListResponse(models); - await SendOkAsync(response, cancellationToken); + return response; } } \ No newline at end of file diff --git a/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/Graph/Endpoint.cs b/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/Graph/Endpoint.cs index 5462fb2fc3..7fbe9a2885 100644 --- a/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/Graph/Endpoint.cs +++ b/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/Graph/Endpoint.cs @@ -1,6 +1,7 @@ using Elsa.Abstractions; using Elsa.Extensions; using Elsa.Workflows.Management; +using Elsa.Workflows.Models; using Elsa.Workflows.Serialization.Converters; using Elsa.Workflows.Serialization.Helpers; using JetBrains.Annotations; @@ -9,7 +10,7 @@ namespace Elsa.Workflows.Api.Endpoints.WorkflowDefinitions.Graph; [PublicAPI] -internal class Graph(IWorkflowDefinitionService workflowDefinitionService, IApiSerializer apiSerializer, ActivityWriter activityWriter) : ElsaEndpoint +internal class Graph(IWorkflowDefinitionService workflowDefinitionService, IApiSerializer apiSerializer, ActivityWriter activityWriter) : ElsaEndpoint { public override void Configure() { diff --git a/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/Graph/Segments/Endpoint.cs b/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/Graph/Segments/Endpoint.cs index c4d6a3e74f..606476e2b7 100644 --- a/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/Graph/Segments/Endpoint.cs +++ b/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/Graph/Segments/Endpoint.cs @@ -12,7 +12,7 @@ namespace Elsa.Workflows.Api.Endpoints.WorkflowDefinitions.Graph.Segments; [PublicAPI] -internal class Nodes(IWorkflowDefinitionService workflowDefinitionService, IApiSerializer apiSerializer, ActivityWriter activityWriter) : ElsaEndpoint +internal class Nodes(IWorkflowDefinitionService workflowDefinitionService, IApiSerializer apiSerializer, ActivityWriter activityWriter) : ElsaEndpoint { public override void Configure() { diff --git a/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/Import/Endpoint.cs b/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/Import/Endpoint.cs index 72e792c173..f09403c624 100644 --- a/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/Import/Endpoint.cs +++ b/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/Import/Endpoint.cs @@ -1,5 +1,6 @@ using Elsa.Abstractions; using Elsa.Workflows.Api.Constants; +using Elsa.Workflows.Api.Models; using Elsa.Workflows.Api.Requirements; using Elsa.Workflows.Management; using Elsa.Workflows.Management.Models; @@ -12,7 +13,7 @@ namespace Elsa.Workflows.Api.Endpoints.WorkflowDefinitions.Import; /// Imports JSON and/or ZIP files containing a workflow definitions. /// [PublicAPI] -internal class Import : ElsaEndpoint +internal class Import : ElsaEndpoint { private readonly IWorkflowDefinitionImporter _workflowDefinitionImporter; private readonly IWorkflowDefinitionLinker _linker; @@ -38,7 +39,7 @@ public override void Configure() } /// - public override async Task HandleAsync(WorkflowDefinitionModel model, CancellationToken cancellationToken) + public override async Task ExecuteAsync(WorkflowDefinitionModel model, CancellationToken cancellationToken) { var definitionId = model.DefinitionId; var isNew = string.IsNullOrWhiteSpace(definitionId); @@ -50,7 +51,7 @@ public override async Task HandleAsync(WorkflowDefinitionModel model, Cancellati if (!authorizationResult.Succeeded) { await SendForbiddenAsync(cancellationToken); - return; + return null!; } var updatedModel = await _linker.MapAsync(definition, cancellationToken); @@ -59,12 +60,12 @@ public override async Task HandleAsync(WorkflowDefinitionModel model, Cancellati { if (isNew) await SendCreatedAtAsync(new { DefinitionId = definitionId }, updatedModel, cancellation: cancellationToken); - else - await SendOkAsync(updatedModel, cancellationToken); + return updatedModel; } if (ValidationFailed) await SendErrorsAsync(400, cancellationToken); + return null!; } private async Task ImportSingleWorkflowDefinitionAsync(WorkflowDefinitionModel model, CancellationToken cancellationToken) diff --git a/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/ImportFiles/Endpoint.cs b/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/ImportFiles/Endpoint.cs index f0d0eee818..13737cd103 100644 --- a/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/ImportFiles/Endpoint.cs +++ b/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/ImportFiles/Endpoint.cs @@ -15,7 +15,7 @@ namespace Elsa.Workflows.Api.Endpoints.WorkflowDefinitions.ImportFiles; /// Imports JSON and/or ZIP files containing a workflow definitions. /// [PublicAPI] -internal class ImportFiles : ElsaEndpoint +internal class ImportFiles : ElsaEndpoint { private readonly IWorkflowDefinitionService _workflowDefinitionService; private readonly IWorkflowDefinitionImporter _workflowDefinitionImporter; @@ -47,14 +47,14 @@ public override void Configure() } /// - public override async Task HandleAsync(WorkflowDefinitionModel model, CancellationToken cancellationToken) + public override async Task ExecuteAsync(WorkflowDefinitionModel model, CancellationToken cancellationToken) { var authorizationResult = await _authorizationService.AuthorizeAsync(User, new NotReadOnlyResource(), AuthorizationPolicies.NotReadOnlyPolicy); if (!authorizationResult.Succeeded) { await SendForbiddenAsync(cancellationToken); - return; + return null!; } if (Files.Any()) @@ -62,11 +62,12 @@ public override async Task HandleAsync(WorkflowDefinitionModel model, Cancellati var count = await ImportFilesAsync(Files, cancellationToken); if (!ValidationFailed) - await SendOkAsync(new { Count = count }, cancellationToken); + return new Response(count); } if (ValidationFailed) await SendErrorsAsync(400, cancellationToken); + return null!; } private async Task ImportFilesAsync(IFormFileCollection files, CancellationToken cancellationToken) diff --git a/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/ImportFiles/Models.cs b/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/ImportFiles/Models.cs new file mode 100644 index 0000000000..4a1bef320b --- /dev/null +++ b/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/ImportFiles/Models.cs @@ -0,0 +1,8 @@ +using System.Text.Json.Serialization; + +namespace Elsa.Workflows.Api.Endpoints.WorkflowDefinitions.ImportFiles; + +internal class Response(long importedCount) +{ + [JsonPropertyName("imported")] public long ImportedCount { get; } = importedCount; +} \ No newline at end of file diff --git a/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/IsNameUnique/Endpoint.cs b/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/IsNameUnique/Endpoint.cs index 4c76d0b49b..948b6b08fd 100644 --- a/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/IsNameUnique/Endpoint.cs +++ b/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/IsNameUnique/Endpoint.cs @@ -8,7 +8,7 @@ namespace Elsa.Workflows.Api.Endpoints.WorkflowDefinitions.IsNameUnique; /// Checks if a workflow definition name is unique. /// [PublicAPI] -internal class IsNameUnique(IWorkflowDefinitionStore store) : ElsaEndpoint +internal class IsNameUnique(IWorkflowDefinitionStore store) : ElsaEndpoint { public override void Configure() { @@ -16,11 +16,11 @@ public override void Configure() ConfigurePermissions("read:workflow-definitions"); } - public override async Task HandleAsync(Request request, CancellationToken cancellationToken) + public override async Task ExecuteAsync(Request request, CancellationToken cancellationToken) { var isUnique = await store.GetIsNameUnique(request.Name.Trim(), request.DefinitionId, cancellationToken); var response = new Response(isUnique); - await SendOkAsync(response, cancellationToken); + return response; } } \ No newline at end of file diff --git a/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/Refresh/Endpoint.cs b/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/Refresh/Endpoint.cs index 7dc056b45f..a008a1d108 100644 --- a/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/Refresh/Endpoint.cs +++ b/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/Refresh/Endpoint.cs @@ -7,7 +7,7 @@ namespace Elsa.Workflows.Api.Endpoints.WorkflowDefinitions.Refresh; [PublicAPI] -internal class Refresh(IWorkflowDefinitionsRefresher workflowDefinitionsRefresher) : ElsaEndpoint +internal class Refresh(IWorkflowDefinitionsRefresher workflowDefinitionsRefresher) : ElsaEndpoint { private const int BatchSize = 10; @@ -17,10 +17,10 @@ public override void Configure() ConfigurePermissions("actions:workflow-definitions:refresh"); } - public override async Task HandleAsync(Request request, CancellationToken cancellationToken) + public override async Task ExecuteAsync(Request request, CancellationToken cancellationToken) { var result = await RefreshWorkflowDefinitionsAsync(request.DefinitionIds, cancellationToken); - await SendOkAsync(new Response(result.Refreshed, result.NotFound), cancellationToken); + return new Response(result.Refreshed, result.NotFound); } private async Task RefreshWorkflowDefinitionsAsync(ICollection? definitionIds, CancellationToken cancellationToken)