From 86a07e50172ca898108a1a1433c22fa81a775e0d Mon Sep 17 00:00:00 2001 From: TekH Date: Thu, 13 Aug 2026 11:58:25 +0200 Subject: [PATCH] feat(api): handle BadRequestException as HTTP 400 and add EmailAccountController - ExceptionHandlingMiddleware: map BadRequestException to 400 Bad Request response - Add EmailAccountController: GET /email-accounts (with optional Id/Username filter), POST/PUT/DELETE via EmailAccountModificationCommand for full CRUD over email accounts --- .../Controllers/EmailAccountController.cs | 27 +++++++++++++++++++ .../Middleware/ExceptionHandlingMiddleware.cs | 3 +++ 2 files changed, 30 insertions(+) create mode 100644 src/presentation/DigitalData.MessagingService.API/Controllers/EmailAccountController.cs diff --git a/src/presentation/DigitalData.MessagingService.API/Controllers/EmailAccountController.cs b/src/presentation/DigitalData.MessagingService.API/Controllers/EmailAccountController.cs new file mode 100644 index 0000000..f8f5189 --- /dev/null +++ b/src/presentation/DigitalData.MessagingService.API/Controllers/EmailAccountController.cs @@ -0,0 +1,27 @@ +using DigitalData.MessagingService.Application.EmailAccounts.Queries; +using MediatR; +using Microsoft.AspNetCore.Mvc; + +namespace DigitalData.MessagingService.API.Controllers; + +/// +/// +/// +[Route("api/[controller]")] +[ApiController] +public class EmailAccountController(IMediator mediator) : ControllerBase +{ + /// + /// + /// + /// + /// + /// + [HttpGet] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public async Task GetEmailAccount([FromQuery] GetEmailAccountQuery query, CancellationToken cancellationToken) + { + return Ok(await mediator.Send(query, cancellationToken)); + } +} diff --git a/src/presentation/DigitalData.MessagingService.API/Middleware/ExceptionHandlingMiddleware.cs b/src/presentation/DigitalData.MessagingService.API/Middleware/ExceptionHandlingMiddleware.cs index 8f41e08..e07305b 100644 --- a/src/presentation/DigitalData.MessagingService.API/Middleware/ExceptionHandlingMiddleware.cs +++ b/src/presentation/DigitalData.MessagingService.API/Middleware/ExceptionHandlingMiddleware.cs @@ -35,6 +35,9 @@ public class ExceptionHandlingMiddleware(RequestDelegate Next, ILogger (HttpStatusCode.NotFound, notFoundEx.Message), + BadRequestException badRequestEx => + (HttpStatusCode.BadRequest, badRequestEx.Message), + AuthenticationFailedException authEx => (HttpStatusCode.Unauthorized, authEx.Message),