fix: always wrap responses in ApiResponse<T>
Success responses now use ApiResponse<T>{ 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>
This commit is contained in:
@@ -17,7 +17,14 @@ public abstract class ApiControllerBase : ControllerBase
|
||||
protected IMediator Mediator { get; }
|
||||
|
||||
protected IActionResult FromServiceResult<T>(ServiceResult<T> result) =>
|
||||
result.IsSuccess ? Ok(result.Result) : MapServiceError(result.Error!);
|
||||
result.IsSuccess
|
||||
? Ok(new ApiResponse<T> { Success = true, Data = result.Result })
|
||||
: MapServiceError(result.Error!);
|
||||
|
||||
protected IActionResult CreatedFromServiceResult<T>(ServiceResult<Guid> result, string actionName, Func<Guid, T> routeValues) =>
|
||||
result.IsSuccess
|
||||
? CreatedAtAction(actionName, routeValues(result.Result), new ApiResponse<Guid> { Success = true, Data = result.Result })
|
||||
: MapServiceError(result.Error!);
|
||||
|
||||
protected IActionResult MapServiceError(ServiceError error)
|
||||
{
|
||||
|
||||
@@ -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<Guid> { Success = true, Data = result.Result });
|
||||
}
|
||||
|
||||
[HttpPut("{id:guid}")]
|
||||
|
||||
+2
-1
@@ -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<Guid> { Success = true, Data = result.Result }
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user