using DigitalData.MessagingService.Application.EmailSending.Commands;
using MediatR;
using Microsoft.AspNetCore.Mvc;
namespace DigitalData.MessagingService.API.Controllers;
///
/// Email sending API controller
/// Enqueues outgoing emails to RabbitMQ for async processing
///
[ApiController]
[Route("api/[controller]")]
public class EmailsController(IMediator mediator) : ControllerBase
{
///
/// Send email (enqueue to RabbitMQ for background processing)
///
/// Send email command
/// Cancellation token
/// HTTP 202 Accepted (queued for processing)
[HttpPost("send")]
[ProducesResponseType(StatusCodes.Status202Accepted)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task SendEmail([FromBody] SendEmailCommand command, CancellationToken cancellationToken)
{
var outgoingEmailEvent = await mediator.Send(command, cancellationToken);
return Accepted(new
{
CommandId = outgoingEmailEvent.Id,
To = outgoingEmailEvent.Recipient,
outgoingEmailEvent.Subject,
outgoingEmailEvent.QueuedAt
});
}
}