From 794a35dd766ec31be953caad37f970b9f94296a4 Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Mon, 9 Mar 2026 09:17:28 +0100 Subject: [PATCH] refactor: extract shared shell reload response models and address review feedback (#7355) * feat: add specification and quality checklist for Shell Reload API endpoints * feat: implement Shell Reload API endpoints and associated documentation * feat: enhance Shell Reload API documentation and add tasks for implementation phases * feat: implement Shell Reload API features with endpoints, interface contracts, models, and component tests * feat: update Shell Reload API responses and tests to reflect changes in error handling and response structure * Fix shell reload follow-up review issues (#7354) * Initial plan * Address shell reload review feedback Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com> * Dispose shell reload semaphore Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com> * Harden shell reload follow-up fixes Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com> * Update src/modules/Elsa.Workflows.Api/Endpoints/Shells/Reload/Endpoint.cs Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> * Potential fix for pull request finding 'Missed opportunity to use Where' Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com> * Update src/modules/Elsa.Workflows.Api/Endpoints/Shells/Reload/Endpoint.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Initial plan * Extract shared ShellsResponseModels.cs to eliminate Response/ShellResponse duplication and null! vs default! inconsistency Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com> * Merge origin/main - resolve add/add conflicts in shell reload endpoints (fix missing trailing newline) Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com> --------- Co-authored-by: Sipke Schoorstra Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com> Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com> Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .../Endpoints/Shells/Reload/Endpoint.cs | 5 +-- .../Endpoints/Shells/Reload/Models.cs | 34 +------------------ .../Endpoints/Shells/ReloadAll/Endpoint.cs | 3 +- .../Endpoints/Shells/ReloadAll/Models.cs | 34 +------------------ .../Endpoints/Shells/ShellsResponseModels.cs | 33 ++++++++++++++++++ 5 files changed, 40 insertions(+), 69 deletions(-) create mode 100644 src/modules/Elsa.Workflows.Api/Endpoints/Shells/ShellsResponseModels.cs diff --git a/src/modules/Elsa.Workflows.Api/Endpoints/Shells/Reload/Endpoint.cs b/src/modules/Elsa.Workflows.Api/Endpoints/Shells/Reload/Endpoint.cs index 835bc448e..69219c56b 100644 --- a/src/modules/Elsa.Workflows.Api/Endpoints/Shells/Reload/Endpoint.cs +++ b/src/modules/Elsa.Workflows.Api/Endpoints/Shells/Reload/Endpoint.cs @@ -1,5 +1,6 @@ using Elsa.Abstractions; using Elsa.Workflows.Api.Contracts; +using Elsa.Workflows.Api.Endpoints.Shells; using JetBrains.Annotations; using Microsoft.AspNetCore.Http; using Elsa.Workflows; @@ -27,7 +28,7 @@ internal class Reload(IShellReloadOrchestrator shellReloadOrchestrator, IApiSeri } var serializerOptions = apiSerializer.GetOptions(); - var response = Elsa.Workflows.Api.Endpoints.Shells.Reload.Response.FromResult(result); + var response = ShellReloadResponse.FromResult(result); var statusCode = result.Status switch { ShellReloadStatus.Busy => StatusCodes.Status409Conflict, @@ -39,7 +40,7 @@ internal class Reload(IShellReloadOrchestrator shellReloadOrchestrator, IApiSeri await SendJsonAsync(response, statusCode, serializerOptions, cancellationToken); } - private async Task SendJsonAsync(Response response, int statusCode, System.Text.Json.JsonSerializerOptions serializerOptions, CancellationToken cancellationToken) + private async Task SendJsonAsync(ShellReloadResponse response, int statusCode, System.Text.Json.JsonSerializerOptions serializerOptions, CancellationToken cancellationToken) { HttpContext.Response.StatusCode = statusCode; await HttpContext.Response.WriteAsJsonAsync(response, serializerOptions, cancellationToken); diff --git a/src/modules/Elsa.Workflows.Api/Endpoints/Shells/Reload/Models.cs b/src/modules/Elsa.Workflows.Api/Endpoints/Shells/Reload/Models.cs index 371dd113d..3559f5d7b 100644 --- a/src/modules/Elsa.Workflows.Api/Endpoints/Shells/Reload/Models.cs +++ b/src/modules/Elsa.Workflows.Api/Endpoints/Shells/Reload/Models.cs @@ -1,33 +1 @@ -using Elsa.Workflows.Api.Contracts; - -namespace Elsa.Workflows.Api.Endpoints.Shells.Reload; - -internal class Response -{ - public ShellReloadStatus Status { get; init; } - public string? RequestedShellId { get; init; } - public DateTimeOffset ReloadedAt { get; init; } - public IReadOnlyCollection Shells { get; init; } = []; - - public static Response FromResult(ShellReloadResult result) => new() - { - Status = result.Status, - RequestedShellId = result.RequestedShellId, - ReloadedAt = result.ReloadedAt, - Shells = result.Shells.Select(x => new ShellResponse - { - ShellId = x.ShellId, - Outcome = x.Outcome, - Requested = x.Requested, - Message = x.Message - }).ToArray() - }; -} - -internal class ShellResponse -{ - public string ShellId { get; init; } = null!; - public ShellReloadItemOutcome Outcome { get; init; } - public bool Requested { get; init; } - public string? Message { get; init; } -} \ No newline at end of file +// Response models for this endpoint are defined in the shared ShellsResponseModels.cs file. diff --git a/src/modules/Elsa.Workflows.Api/Endpoints/Shells/ReloadAll/Endpoint.cs b/src/modules/Elsa.Workflows.Api/Endpoints/Shells/ReloadAll/Endpoint.cs index f1d86dd6a..0da719c5f 100644 --- a/src/modules/Elsa.Workflows.Api/Endpoints/Shells/ReloadAll/Endpoint.cs +++ b/src/modules/Elsa.Workflows.Api/Endpoints/Shells/ReloadAll/Endpoint.cs @@ -1,5 +1,6 @@ using Elsa.Abstractions; using Elsa.Workflows.Api.Contracts; +using Elsa.Workflows.Api.Endpoints.Shells; using JetBrains.Annotations; using Microsoft.AspNetCore.Http; @@ -17,7 +18,7 @@ internal class ReloadAll(IShellReloadOrchestrator shellReloadOrchestrator) : Els public override async Task HandleAsync(CancellationToken cancellationToken) { var result = await shellReloadOrchestrator.ReloadAllAsync(cancellationToken); - var response = Elsa.Workflows.Api.Endpoints.Shells.ReloadAll.Response.FromResult(result); + var response = ShellReloadResponse.FromResult(result); switch (result.Status) { diff --git a/src/modules/Elsa.Workflows.Api/Endpoints/Shells/ReloadAll/Models.cs b/src/modules/Elsa.Workflows.Api/Endpoints/Shells/ReloadAll/Models.cs index 714bf48b0..6b426610c 100644 --- a/src/modules/Elsa.Workflows.Api/Endpoints/Shells/ReloadAll/Models.cs +++ b/src/modules/Elsa.Workflows.Api/Endpoints/Shells/ReloadAll/Models.cs @@ -1,33 +1 @@ -using Elsa.Workflows.Api.Contracts; - -namespace Elsa.Workflows.Api.Endpoints.Shells.ReloadAll; - -internal class Response -{ - public ShellReloadStatus Status { get; init; } - public string? RequestedShellId { get; init; } - public DateTimeOffset ReloadedAt { get; init; } - public IReadOnlyCollection Shells { get; init; } = []; - - public static Response FromResult(ShellReloadResult result) => new() - { - Status = result.Status, - RequestedShellId = result.RequestedShellId, - ReloadedAt = result.ReloadedAt, - Shells = result.Shells.Select(x => new ShellResponse - { - ShellId = x.ShellId, - Outcome = x.Outcome, - Requested = x.Requested, - Message = x.Message - }).ToArray() - }; -} - -internal class ShellResponse -{ - public string ShellId { get; init; } = default!; - public ShellReloadItemOutcome Outcome { get; init; } - public bool Requested { get; init; } - public string? Message { get; init; } -} \ No newline at end of file +// Response models for this endpoint are defined in the shared ShellsResponseModels.cs file. \ No newline at end of file diff --git a/src/modules/Elsa.Workflows.Api/Endpoints/Shells/ShellsResponseModels.cs b/src/modules/Elsa.Workflows.Api/Endpoints/Shells/ShellsResponseModels.cs new file mode 100644 index 000000000..df85bbb98 --- /dev/null +++ b/src/modules/Elsa.Workflows.Api/Endpoints/Shells/ShellsResponseModels.cs @@ -0,0 +1,33 @@ +using Elsa.Workflows.Api.Contracts; + +namespace Elsa.Workflows.Api.Endpoints.Shells; + +internal class ShellReloadResponse +{ + public ShellReloadStatus Status { get; init; } + public string? RequestedShellId { get; init; } + public DateTimeOffset ReloadedAt { get; init; } + public IReadOnlyCollection Shells { get; init; } = []; + + public static ShellReloadResponse FromResult(ShellReloadResult result) => new() + { + Status = result.Status, + RequestedShellId = result.RequestedShellId, + ReloadedAt = result.ReloadedAt, + Shells = result.Shells.Select(x => new ShellReloadItemResponse + { + ShellId = x.ShellId, + Outcome = x.Outcome, + Requested = x.Requested, + Message = x.Message + }).ToArray() + }; +} + +internal class ShellReloadItemResponse +{ + public string ShellId { get; init; } = default!; + public ShellReloadItemOutcome Outcome { get; init; } + public bool Requested { get; init; } + public string? Message { get; init; } +}