using DigitalData.EmailProfiler.Application.Common.Dtos.EmailHistories; using DigitalData.EmailProfiler.Application.EmailHistories.Queries; using MediatR; using Microsoft.AspNetCore.Mvc; namespace DigitalData.EmailProfiler.API.Controllers; /// /// Email history API controller (read-only) /// [ApiController] [Route("api/[controller]")] public class EmailHistoryController(IMediator mediator) : ControllerBase { /// /// Get email history by profile ID with pagination /// [HttpGet("profile/{profileId:int}")] [ProducesResponseType(typeof(IEnumerable), StatusCodes.Status200OK)] public async Task GetByProfile( int profileId, [FromQuery] int pageNumber = 1, [FromQuery] int pageSize = 50, CancellationToken cancellationToken = default) { var query = new GetEmailHistoryByProfileQuery(profileId, pageNumber, pageSize); var result = await mediator.Send(query, cancellationToken); return Ok(new { ProfileId = profileId, PageNumber = pageNumber, PageSize = pageSize, Data = result }); } /// /// Get email history by ID /// [HttpGet("{id:int}")] [ProducesResponseType(typeof(EmailHistoryDto), StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] public async Task GetById(int id, CancellationToken cancellationToken) { var query = new GetEmailHistoryByIdQuery(id); var result = await mediator.Send(query, cancellationToken); if (result == null) return NotFound(new { Message = $"Email history with ID {id} not found" }); return Ok(result); } // Note: Email history is typically managed by ProcessEmailCommand // No direct CREATE/UPDATE/DELETE endpoints needed }