Files
DigitalData.MessagingService/src/presentation/DigitalData.MessagingService.API/Controllers/EmailsController.cs
TekH 78c82bf129 Refactor solution structure and add RabbitMQ config
Reorganized the solution structure to align with a layered architecture:
- Replaced `src` folder with `core`, `infrastructure`, and `presentation`.
- Moved projects to their respective folders.
- Added `DigitalData.MessagingService.Publisher.Abstraction` project.
- Removed `DigitalData.MessagingService.Client` project.

Updated project configurations and nesting in the solution file.

Added `appsettings.Secrets.json` with RabbitMQ and email account settings:
- RabbitMQ configuration includes hostname, port, credentials, and queue/exchange details.
- Email configuration includes SMTP server details and credentials.
2026-07-28 10:26:15 +02:00

37 lines
1.3 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
{
CommandId = outgoingEmailEvent.Id,
To = outgoingEmailEvent.Recipient,
outgoingEmailEvent.Subject,
outgoingEmailEvent.QueuedAt
});
}
}