From 7a4cdb3d1f894346478c88266c0bd229145524d3 Mon Sep 17 00:00:00 2001 From: TekH Date: Wed, 14 Jan 2026 16:30:41 +0100 Subject: [PATCH] Support querying multiple profile views in ReadProfileView Refactored ReadProfileViewQuery and handler to return multiple profiles as IEnumerable. Made Id parameter optional to allow fetching all profiles. Updated exception handling for empty results. --- .../Profile/Queries/ReadProfileViewQuery.cs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) 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