feat: add Logs

This commit is contained in:
2026-09-20 16:21:15 +07:00
parent 637ca51f47
commit d3c3ecd5e6
62 changed files with 1577 additions and 66 deletions
+43
View File
@@ -0,0 +1,43 @@
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using mws.backend.dotnet.application.Audit;
using mws.backend.dotnet.application.Common;
namespace mws.backend.dotnet.api.Controllers;
[ApiController]
[Route("api/audit")]
[Authorize]
public class AuditController(ISender sender) : ControllerBase
{
[HttpGet("actions")]
public async Task<ActionResult<PagedResult<ActionLogDto>>> GetActions(
[FromQuery] DateTimeOffset? from,
[FromQuery] DateTimeOffset? to,
[FromQuery] string? actor,
[FromQuery] string? action,
[FromQuery] string? entityType,
[FromQuery] Guid? entityId,
[FromQuery] int page = 1,
[FromQuery] int pageSize = 20,
CancellationToken ct = default)
{
var filter = new ActionLogFilter(from, to, actor, action, entityType, entityId);
return Ok(await sender.Send(new GetActionLogsQuery(User.GetUserId(), filter, page, pageSize), ct));
}
[HttpGet("logins")]
public async Task<ActionResult<PagedResult<LoginLogDto>>> GetLogins(
[FromQuery] DateTimeOffset? from,
[FromQuery] DateTimeOffset? to,
[FromQuery] string? username,
[FromQuery] bool? success,
[FromQuery] int page = 1,
[FromQuery] int pageSize = 20,
CancellationToken ct = default)
{
var filter = new LoginLogFilter(from, to, username, success);
return Ok(await sender.Send(new GetLoginLogsQuery(User.GetUserId(), filter, page, pageSize), ct));
}
}