58 lines
1.9 KiB
C#
58 lines
1.9 KiB
C#
using DigitalData.EmailProfiler.Application.Common.Dtos.EmailHistories;
|
|
using DigitalData.EmailProfiler.Application.EmailHistories.Queries;
|
|
using MediatR;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace DigitalData.EmailProfiler.API.Controllers;
|
|
|
|
/// <summary>
|
|
/// Email history API controller (read-only)
|
|
/// </summary>
|
|
[ApiController]
|
|
[Route("api/[controller]")]
|
|
public class EmailHistoryController(IMediator mediator) : ControllerBase
|
|
{
|
|
/// <summary>
|
|
/// Get email history by profile ID with pagination
|
|
/// </summary>
|
|
[HttpGet("profile/{profileId:int}")]
|
|
[ProducesResponseType(typeof(IEnumerable<EmailHistoryDto>), StatusCodes.Status200OK)]
|
|
public async Task<IActionResult> 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
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get email history by ID
|
|
/// </summary>
|
|
[HttpGet("{id:int}")]
|
|
[ProducesResponseType(typeof(EmailHistoryDto), StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
|
public async Task<IActionResult> 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
|
|
}
|