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
+36
View File
@@ -0,0 +1,36 @@
using MediatR;
using mws.backend.dotnet.application.Common;
using mws.backend.dotnet.application.Permissions;
namespace mws.backend.dotnet.application.Audit;
public record GetLoginLogsQuery(Guid ActorUserId, LoginLogFilter Filter, int Page, int PageSize)
: IRequest<PagedResult<LoginLogDto>>;
public class GetLoginLogsHandler(IUnitOfWork uow, IPermissionService permissions)
: IRequestHandler<GetLoginLogsQuery, PagedResult<LoginLogDto>>
{
public async Task<PagedResult<LoginLogDto>> Handle(GetLoginLogsQuery query, CancellationToken ct)
{
await permissions.EnsureAsync(query.ActorUserId, "loginlogs", PermissionAction.View, ct);
var page = await uow.LoginLogs.SearchAsync(query.Filter, query.Page, query.PageSize, ct);
return new PagedResult<LoginLogDto>
{
Items = page.Items.Select(x => new LoginLogDto
{
Id = x.Id,
Username = x.Username,
UserId = x.UserId,
Success = x.Success,
FailureReason = x.FailureReason,
IpAddress = x.IpAddress,
UserAgent = x.UserAgent,
CreatedAt = x.CreatedAt,
}).ToList(),
TotalCount = page.TotalCount,
Page = page.Page,
PageSize = page.PageSize,
};
}
}