From bd2b5ff62f881c4c8a14129a4879ae4d0185df2f Mon Sep 17 00:00:00 2001 From: TekH Date: Wed, 14 Jan 2026 16:12:54 +0100 Subject: [PATCH] Add ReadProfileViewQuery and handler for profile views Introduce CQRS/MediatR query and handler to fetch ProfileView by Id, optionally including related Actions. Uses repository and AutoMapper, throws NotFoundException if profile is missing, and returns ProfileViewDto. --- .../Profile/Queries/ReadProfileViewQuery.cs | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/ReC.Application/Profile/Queries/ReadProfileViewQuery.cs diff --git a/src/ReC.Application/Profile/Queries/ReadProfileViewQuery.cs b/src/ReC.Application/Profile/Queries/ReadProfileViewQuery.cs new file mode 100644 index 0000000..8cfde42 --- /dev/null +++ b/src/ReC.Application/Profile/Queries/ReadProfileViewQuery.cs @@ -0,0 +1,33 @@ +using AutoMapper; +using DigitalData.Core.Abstraction.Application.Repository; +using DigitalData.Core.Exceptions; +using MediatR; +using Microsoft.EntityFrameworkCore; +using ReC.Application.Common.Dto; +using ReC.Domain.Views; + +namespace ReC.Application.Profile.Queries; + +public record ReadProfileViewQuery : IRequest +{ + public long Id { get; init; } + + public bool IncludeActions { get; init; } = true; +} + +public class ReadProfileViewQueryHandler(IRepository repo, IMapper mapper) + : IRequestHandler +{ + 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); + + return profile is null + ? throw new NotFoundException($"Profile {request.Id} not found.") + : mapper.Map(profile); + } +} \ No newline at end of file