Reordered using directives in DtoMappingProfile.cs. Added AutoMapper mapping for OutRes to OutResDto. Modified ReadOutResQuery to return IEnumerable<OutResDto>. Updated ReadOutResHandler to handle collection results: - Changed Handle method to return IEnumerable<OutResDto>. - Updated mapper.Map to map to a collection of OutResDto.
37 lines
1.1 KiB
C#
37 lines
1.1 KiB
C#
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.Entities;
|
|
|
|
namespace ReC.Application.OutResults.Queries;
|
|
|
|
public record ReadOutResQuery : IRequest<IEnumerable<OutResDto>>
|
|
{
|
|
public long? ProfileId { get; init; }
|
|
|
|
public long? ActionId { get; init; }
|
|
}
|
|
|
|
public class ReadOutResHandler(IRepository<OutRes> repo, IMapper mapper) : IRequestHandler<ReadOutResQuery, IEnumerable<OutResDto>>
|
|
{
|
|
public async Task<IEnumerable<OutResDto>> Handle(ReadOutResQuery request, CancellationToken cancel)
|
|
{
|
|
var q = repo.Query;
|
|
|
|
if(request.ActionId is long actionId)
|
|
q = q.Where(res => res.ActionId == actionId);
|
|
|
|
if(request.ProfileId is long profileId)
|
|
q = q.Where(res => res.Action!.ProfileId == profileId);
|
|
|
|
var resList = await q.ToListAsync(cancel);
|
|
|
|
if (resList.Count == 0)
|
|
throw new NotFoundException();
|
|
|
|
return mapper.Map<IEnumerable<OutResDto>>(resList);
|
|
}
|
|
} |