feat: add Logs
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
using MediatR;
|
||||
using mws.backend.dotnet.application.Common;
|
||||
using mws.backend.dotnet.application.Permissions;
|
||||
|
||||
namespace mws.backend.dotnet.application.Audit;
|
||||
|
||||
public record GetActionLogsQuery(Guid ActorUserId, ActionLogFilter Filter, int Page, int PageSize)
|
||||
: IRequest<PagedResult<ActionLogDto>>;
|
||||
|
||||
public class GetActionLogsHandler(IUnitOfWork uow, IPermissionService permissions)
|
||||
: IRequestHandler<GetActionLogsQuery, PagedResult<ActionLogDto>>
|
||||
{
|
||||
public async Task<PagedResult<ActionLogDto>> Handle(GetActionLogsQuery query, CancellationToken ct)
|
||||
{
|
||||
await permissions.EnsureAsync(query.ActorUserId, "actionlogs", PermissionAction.View, ct);
|
||||
|
||||
var page = await uow.ActionLogs.SearchAsync(query.Filter, query.Page, query.PageSize, ct);
|
||||
return new PagedResult<ActionLogDto>
|
||||
{
|
||||
Items = page.Items.Select(x => new ActionLogDto
|
||||
{
|
||||
Id = x.Id,
|
||||
ActorUserId = x.ActorUserId,
|
||||
ActorUsername = x.ActorUsername,
|
||||
Action = x.Action,
|
||||
EntityType = x.EntityType,
|
||||
EntityId = x.EntityId,
|
||||
EntityName = x.EntityName,
|
||||
IpAddress = x.IpAddress,
|
||||
UserAgent = x.UserAgent,
|
||||
CreatedAt = x.CreatedAt,
|
||||
}).ToList(),
|
||||
TotalCount = page.TotalCount,
|
||||
Page = page.Page,
|
||||
PageSize = page.PageSize,
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user