Updated the `IEmailService` interface and related components to support multiple recipients in the `SendEmailAsync` method. - Replaced `Recipient` with `Recipients` in `SendEmailCommand`, `OutgoingEmailEvent`, and `EmailsController`. - Updated `SendEmailCommandValidator` to validate a collection of recipients, ensuring at least one valid email address. - Modified `LimilabsEmailService` to handle multiple recipients by iterating over the collection and adding each to the email. - Adjusted `OutgoingEmailConsumer` to process and log multiple recipients. - Updated logging and response structures to reflect the changes. These changes enable the system to handle emails with multiple recipients while maintaining proper validation and logging.
34 lines
1.1 KiB
C#
34 lines
1.1 KiB
C#
using DigitalData.MessagingService.Application.EmailSending.Commands;
|
|
using MediatR;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace DigitalData.MessagingService.API.Controllers;
|
|
|
|
/// <summary>
|
|
/// Email sending API controller
|
|
/// Enqueues outgoing emails to RabbitMQ for async processing
|
|
/// </summary>
|
|
[ApiController]
|
|
[Route("api/[controller]")]
|
|
public class EmailsController(IMediator mediator) : ControllerBase
|
|
{
|
|
/// <summary>
|
|
/// Send email (enqueue to RabbitMQ for background processing)
|
|
/// </summary>
|
|
/// <param name="command">Send email command</param>
|
|
/// <param name="cancellationToken">Cancellation token</param>
|
|
/// <returns>HTTP 202 Accepted (queued for processing)</returns>
|
|
[HttpPost("send")]
|
|
[ProducesResponseType(StatusCodes.Status202Accepted)]
|
|
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
|
public async Task<IActionResult> SendEmail([FromBody] SendEmailCommand command, CancellationToken cancellationToken)
|
|
{
|
|
var outgoingEmailEvent = await mediator.Send(command, cancellationToken);
|
|
|
|
return Accepted(new
|
|
{
|
|
outgoingEmailEvent.Id,
|
|
});
|
|
}
|
|
}
|