diff --git a/src/ReC.Application/Profile/Queries/ReadProfileViewQuery.cs b/src/ReC.Application/Profile/Queries/ReadProfileViewQuery.cs index 8cfde42..a762d33 100644 --- a/src/ReC.Application/Profile/Queries/ReadProfileViewQuery.cs +++ b/src/ReC.Application/Profile/Queries/ReadProfileViewQuery.cs @@ -8,26 +8,29 @@ using ReC.Domain.Views; namespace ReC.Application.Profile.Queries; -public record ReadProfileViewQuery : IRequest +public record ReadProfileViewQuery : IRequest> { - public long Id { get; init; } + public long? Id { get; init; } = null; public bool IncludeActions { get; init; } = true; } public class ReadProfileViewQueryHandler(IRepository repo, IMapper mapper) - : IRequestHandler + : IRequestHandler> { - public async Task Handle(ReadProfileViewQuery request, CancellationToken cancel) + public async Task> Handle(ReadProfileViewQuery request, CancellationToken cancel) { var query = request.IncludeActions ? repo.Query.Include(p => p.Actions) : repo.Query; - var profile = await query.SingleOrDefaultAsync(p => p.Id == request.Id, cancel); + if (request.Id is long id) + query = query.Where(p => p.Id == id); - return profile is null + var profiles = await query.ToListAsync(cancel); + + return profiles is null || profiles.Count == 0 ? throw new NotFoundException($"Profile {request.Id} not found.") - : mapper.Map(profile); + : mapper.Map>(profiles); } } \ No newline at end of file