26 lines
1.1 KiB
C#
26 lines
1.1 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 LoginLogRepository(AppDbContext db) : RepositoryBase<LoginLog>(db), ILoginLogRepository
|
|
{
|
|
public Task<PagedResult<LoginLog>> SearchAsync(LoginLogFilter 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.Username))
|
|
{
|
|
var lower = filter.Username.Trim().ToLower();
|
|
query = query.Where(x => x.Username.ToLower().Contains(lower));
|
|
}
|
|
if (filter.Success is { } success) query = query.Where(x => x.Success == success);
|
|
|
|
return query.OrderByDescending(x => x.CreatedAt).ToPagedResultAsync(page, pageSize, ct);
|
|
}
|
|
}
|