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>; public class GetLoginLogsHandler(IUnitOfWork uow, IPermissionService permissions) : IRequestHandler> { public async Task> 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 { 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, }; } }