From 61130130ff72f570739257fe7661842287acb821 Mon Sep 17 00:00:00 2001 From: Anatolii Grynchuk Date: Sat, 2 May 2026 01:23:22 +0300 Subject: [PATCH] fix: always wrap responses in ApiResponse MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Success responses now use ApiResponse{ Success=true, Data=T } instead of returning raw T — consistent shape for all outcomes. Ref: IT-628 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../Controllers/ApiControllerBase.cs | 9 ++++++++- .../Controllers/EmailChannels/EmailChannelsController.cs | 4 +++- .../EmailTemplates/EmailTemplatesController.cs | 3 ++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/HrynCo.NotificationService.Api/Controllers/ApiControllerBase.cs b/HrynCo.NotificationService.Api/Controllers/ApiControllerBase.cs index aecb4a9..cfa4636 100644 --- a/HrynCo.NotificationService.Api/Controllers/ApiControllerBase.cs +++ b/HrynCo.NotificationService.Api/Controllers/ApiControllerBase.cs @@ -17,7 +17,14 @@ public abstract class ApiControllerBase : ControllerBase protected IMediator Mediator { get; } protected IActionResult FromServiceResult(ServiceResult result) => - result.IsSuccess ? Ok(result.Result) : MapServiceError(result.Error!); + result.IsSuccess + ? Ok(new ApiResponse { Success = true, Data = result.Result }) + : MapServiceError(result.Error!); + + protected IActionResult CreatedFromServiceResult(ServiceResult result, string actionName, Func routeValues) => + result.IsSuccess + ? CreatedAtAction(actionName, routeValues(result.Result), new ApiResponse { Success = true, Data = result.Result }) + : MapServiceError(result.Error!); protected IActionResult MapServiceError(ServiceError error) { diff --git a/HrynCo.NotificationService.Api/Controllers/EmailChannels/EmailChannelsController.cs b/HrynCo.NotificationService.Api/Controllers/EmailChannels/EmailChannelsController.cs index 3cab68f..2998e0f 100644 --- a/HrynCo.NotificationService.Api/Controllers/EmailChannels/EmailChannelsController.cs +++ b/HrynCo.NotificationService.Api/Controllers/EmailChannels/EmailChannelsController.cs @@ -1,3 +1,4 @@ +using HrynCo.NotificationService.Api.Infrastructure; using HrynCo.NotificationService.Services.EmailChannels.Create; using HrynCo.NotificationService.Services.EmailChannels.Delete; using HrynCo.NotificationService.Services.EmailChannels.Get; @@ -46,7 +47,8 @@ public sealed class EmailChannelsController : ApiControllerBase if (!result.IsSuccess) return MapServiceError(result.Error!); - return CreatedAtAction(nameof(Get), new { id = result.Result }, result.Result); + return CreatedAtAction(nameof(Get), new { id = result.Result }, + new ApiResponse { Success = true, Data = result.Result }); } [HttpPut("{id:guid}")] diff --git a/HrynCo.NotificationService.Api/Controllers/EmailTemplates/EmailTemplatesController.cs b/HrynCo.NotificationService.Api/Controllers/EmailTemplates/EmailTemplatesController.cs index 984752b..17a781c 100644 --- a/HrynCo.NotificationService.Api/Controllers/EmailTemplates/EmailTemplatesController.cs +++ b/HrynCo.NotificationService.Api/Controllers/EmailTemplates/EmailTemplatesController.cs @@ -1,3 +1,4 @@ +using HrynCo.NotificationService.Api.Infrastructure; using HrynCo.NotificationService.Services.EmailTemplates.Create; using HrynCo.NotificationService.Services.EmailTemplates.Delete; using HrynCo.NotificationService.Services.EmailTemplates.Get; @@ -48,7 +49,7 @@ public sealed class EmailTemplatesController : ApiControllerBase return CreatedAtAction( nameof(Get), new { serviceName = request.ServiceName, key = request.Key, languageCode = request.LanguageCode }, - result.Result + new ApiResponse { Success = true, Data = result.Result } ); }