using MediatR; using Microsoft.EntityFrameworkCore; using MinAttest.Application.Abstractions; using MinAttest.Contracts.Attests; using MinAttest.Domain.Entities; namespace MinAttest.Application.Features.Attests.Queries; public record ListPersonAttestsQuery(Guid PersonId, int? Take) : IRequest>; public class ListPersonAttestsQueryHandler(IAppDbContext db) : IRequestHandler> { public async Task> Handle(ListPersonAttestsQuery request, CancellationToken cancellationToken) { return await db.Attests.AsNoTracking().Include(a => a.Employer) .Where(a => a.PersonId == request.PersonId) .OrderByDescending(a => a.IssuedAt) .Take(Math.Clamp(request.Take ?? 50, 1, 200)) .Select(a => new AttestSummary(a.Id, (a.Employer != null ? a.Employer.Name : string.Empty), a.Title, a.From, a.To, a.Status == AttestStatus.Issued)) .ToListAsync(cancellationToken); } }