Files
DigitalData.MessagingService/src/DigitalData.EmailProfiler.API/Controllers/EmailsController.cs
TekH 958352a720 feat: Add domain constants, API infrastructure, and configuration
Domain Layer:
- Add DomainConstants for email, attachment, and process constants

API Layer:
- Add EmailsController (minimal REST API endpoints)
- Add ExceptionHandlingMiddleware for global exception handling
- Update Program.cs:
  * Add EmailProfilerDbContext registration (SQL Server)
  * Add Generic Repository<T> scoped registration
  * Add ExceptionHandlingMiddleware to pipeline
  * Add EmailSenderWorker as hosted service
  * Configure Serilog file logging
  * Add Scalar OpenAPI documentation

Configuration:
- Add EmailAccount section in appsettings.json (SMTP credentials)
- Add RabbitMq section (message queue configuration)
- Add Serilog file sink configuration
- Update .csproj with required NuGet packages
- Update solution file

This commit completes the basic API infrastructure setup.
2026-07-22 11:50:17 +02:00

38 lines
1.3 KiB
C#

using DigitalData.EmailProfiler.Application.EmailSending.Commands;
using MediatR;
using Microsoft.AspNetCore.Mvc;
namespace DigitalData.EmailProfiler.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 emailOutboxId = await mediator.Send(command, cancellationToken);
return Accepted(new
{
Message = "Email queued for sending",
EmailOutboxId = emailOutboxId,
To = command.Recipient,
command.Subject,
QueuedAt = DateTime.Now
});
}
}