2026-07-22 19:54:55 +00:00
|
|
|
using Heimdall.Application.Audit.Queries.GetAuditLogs;
|
2026-07-20 10:30:01 +00:00
|
|
|
using Heimdall.Application.DTOs;
|
|
|
|
|
using Heimdall.Infrastructure.Security;
|
2026-07-22 19:54:55 +00:00
|
|
|
using MediatR;
|
2026-07-20 10:30:01 +00:00
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Microsoft.AspNetCore.RateLimiting;
|
|
|
|
|
|
|
|
|
|
namespace Heimdall.Api.Controllers;
|
|
|
|
|
|
|
|
|
|
[ApiController]
|
|
|
|
|
[Route("api/audit-logs")]
|
2026-08-11 08:32:41 +02:00
|
|
|
[Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.AdminManage)]
|
2026-07-20 10:30:01 +00:00
|
|
|
[EnableRateLimiting("Api")]
|
|
|
|
|
public class AuditLogsController : ControllerBase
|
|
|
|
|
{
|
2026-07-22 19:54:55 +00:00
|
|
|
private readonly IMediator _mediator;
|
2026-07-20 10:30:01 +00:00
|
|
|
|
2026-07-22 19:54:55 +00:00
|
|
|
public AuditLogsController(IMediator mediator) => _mediator = mediator;
|
2026-07-20 10:30:01 +00:00
|
|
|
|
|
|
|
|
/// <summary>List audit log entries with optional filtering.</summary>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
[ProducesResponseType(typeof(PagedResult<AuditLogResponse>), StatusCodes.Status200OK)]
|
|
|
|
|
[ProducesResponseType(typeof(void), StatusCodes.Status400BadRequest)]
|
|
|
|
|
public async Task<IActionResult> List(
|
|
|
|
|
[FromQuery] string? resourceType,
|
|
|
|
|
[FromQuery] string? action,
|
2026-08-27 18:56:57 +02:00
|
|
|
[FromQuery] string? search,
|
|
|
|
|
[FromQuery] string? userId,
|
|
|
|
|
[FromQuery] DateTime? fromDate,
|
|
|
|
|
[FromQuery] DateTime? toDate,
|
2026-07-20 10:30:01 +00:00
|
|
|
[FromQuery] int page = 1,
|
|
|
|
|
[FromQuery] int pageSize = 20,
|
|
|
|
|
CancellationToken ct = default)
|
|
|
|
|
{
|
2026-08-27 18:56:57 +02:00
|
|
|
var result = await _mediator.Send(new GetAuditLogsQuery(resourceType, action, page, pageSize, search, userId, fromDate, toDate), ct);
|
2026-07-20 10:30:01 +00:00
|
|
|
if (!result.IsSuccess)
|
|
|
|
|
return StatusCode(result.StatusCode ?? 400, new { error = result.Error });
|
|
|
|
|
return Ok(result.Data);
|
|
|
|
|
}
|
|
|
|
|
}
|