36 lines
1.5 KiB
C#
36 lines
1.5 KiB
C#
using mws.backend.dotnet.application.Audit;
|
|
using mws.backend.dotnet.application.Common;
|
|
using mws.backend.dotnet.application.Common.Repositories;
|
|
using mws.backend.dotnet.domain.Audit;
|
|
|
|
namespace mws.backend.dotnet.infrastructure.Persistence.Repositories;
|
|
|
|
public class ActionLogRepository(AppDbContext db) : RepositoryBase<ActionLog>(db), IActionLogRepository
|
|
{
|
|
public Task<PagedResult<ActionLog>> SearchAsync(ActionLogFilter filter, int page, int pageSize, CancellationToken ct = default)
|
|
{
|
|
var query = Set.AsQueryable();
|
|
|
|
if (filter.From is { } from) query = query.Where(x => x.CreatedAt >= from);
|
|
if (filter.To is { } to) query = query.Where(x => x.CreatedAt <= to);
|
|
if (!string.IsNullOrWhiteSpace(filter.Actor))
|
|
{
|
|
var lower = filter.Actor.Trim().ToLower();
|
|
query = query.Where(x => x.ActorUsername.ToLower().Contains(lower));
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(filter.Action))
|
|
{
|
|
var lower = filter.Action.Trim().ToLower();
|
|
query = query.Where(x => x.Action.ToLower().Contains(lower));
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(filter.EntityType))
|
|
{
|
|
var lower = filter.EntityType.Trim().ToLower();
|
|
query = query.Where(x => x.EntityType.ToLower().Contains(lower));
|
|
}
|
|
if (filter.EntityId is { } entityId) query = query.Where(x => x.EntityId == entityId);
|
|
|
|
return query.OrderByDescending(x => x.CreatedAt).ToPagedResultAsync(page, pageSize, ct);
|
|
}
|
|
}
|