Changed invocation filter to use Results.Any() instead of Root.OutRes. Removed eager loading of EndpointAuth from the query.
39 lines
1.3 KiB
C#
39 lines
1.3 KiB
C#
using MediatR;
|
|
using DigitalData.Core.Abstraction.Application.Repository;
|
|
using AutoMapper;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using DigitalData.Core.Exceptions;
|
|
using ReC.Application.Common.Dto;
|
|
using ReC.Domain.Views;
|
|
|
|
namespace ReC.Application.RecActions.Queries;
|
|
|
|
public record ReadRecActionViewQuery : IRequest<IEnumerable<RecActionViewDto>>
|
|
{
|
|
public long? ProfileId { get; init; } = null;
|
|
|
|
public bool? Invoked { get; set; } = null;
|
|
}
|
|
|
|
public class ReadRecActionViewQueryHandler(IRepository<RecActionView> repo, IMapper mapper) : IRequestHandler<ReadRecActionViewQuery, IEnumerable<RecActionViewDto>>
|
|
{
|
|
public async Task<IEnumerable<RecActionViewDto>> Handle(ReadRecActionViewQuery request, CancellationToken cancel)
|
|
{
|
|
var query = repo.Query;
|
|
|
|
if (request.ProfileId is long profileId)
|
|
query = repo.Where(act => act.ProfileId == profileId);
|
|
|
|
if (request.Invoked is bool invoked)
|
|
query = invoked
|
|
? query.Where(act => act.Results!.Any())
|
|
: query.Where(act => !act.Results!.Any());
|
|
|
|
var actions = await query.ToListAsync(cancel);
|
|
|
|
if (actions.Count == 0)
|
|
throw new NotFoundException($"No actions found for the profile {request.ProfileId}.");
|
|
|
|
return mapper.Map<IEnumerable<RecActionViewDto>>(actions);
|
|
}
|
|
} |