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.
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
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
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user