37 lines
1.3 KiB
C#
37 lines
1.3 KiB
C#
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,
|
|
};
|
|
}
|
|
}
|