Initial import
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using MinAttest.Contracts.Attests;
|
||||
using MinAttest.Contracts.Persons;
|
||||
using MinAttest.Application.Abstractions;
|
||||
|
||||
namespace MinAttest.Application.Features.Persons.Queries;
|
||||
|
||||
public record GetPersonQuery(Guid Id) : IRequest<PersonResponse?>;
|
||||
|
||||
public class GetPersonQueryHandler(IAppDbContext db) : IRequestHandler<GetPersonQuery, PersonResponse?>
|
||||
{
|
||||
public async Task<PersonResponse?> Handle(GetPersonQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var person = await db.Persons
|
||||
.Where(p => p.Id == request.Id)
|
||||
.Select(p => new PersonResponse(
|
||||
p.Id,
|
||||
p.NationalIdHash,
|
||||
p.Email,
|
||||
p.Phone,
|
||||
p.Attests
|
||||
.Select(a => new AttestSummary(
|
||||
a.Id,
|
||||
a.Employer != null ? a.Employer.Name : string.Empty,
|
||||
a.Title,
|
||||
a.From,
|
||||
a.To,
|
||||
a.Status == Domain.Entities.AttestStatus.Issued
|
||||
))
|
||||
.ToList()
|
||||
))
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
|
||||
return person;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user