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 } ); }