using MediatR; using DigitalData.Core.Abstraction.Application.Repository; using ReC.Domain.Entities; using AutoMapper; using Microsoft.EntityFrameworkCore; using DigitalData.Core.Exceptions; using ReC.Application.Common.Dto; namespace ReC.Application.RecActions.Queries; public record ReadRecActionQueryBase { public int ProfileId { get; init; } public ReadRecActionQuery ToReadQuery() => new(this); } public record ReadRecActionQuery(ReadRecActionQueryBase Root) : ReadRecActionQueryBase(Root), IRequest>; public class ReadRecActionQueryHandler(IRepository repo, IMapper mapper) : IRequestHandler> { public async Task> Handle(ReadRecActionQuery request, CancellationToken cancel) { var actions = await repo.Where(x => x.ProfileId == request.ProfileId).ToListAsync(cancel); if(actions.Count != 0) throw new NotFoundException($"No actions found for the profile {request.ProfileId}."); return mapper.Map>(actions); } }