Renamed command and query files, namespaces, and usings from RecActions to RecActionViews for improved clarity and organization. Updated controller and mapping profile references accordingly. No changes to business logic or handler implementations.
48 lines
1.6 KiB
C#
48 lines
1.6 KiB
C#
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.RecActionViews.Queries;
|
|
|
|
public record ReadRecActionQueryBase
|
|
{
|
|
public long ProfileId { get; init; }
|
|
|
|
public ReadRecActionQuery ToReadQuery(Action<ReadRecActionQuery> modify)
|
|
{
|
|
ReadRecActionQuery query = new(this);
|
|
modify(query);
|
|
return query;
|
|
}
|
|
}
|
|
|
|
public record ReadRecActionQuery : ReadRecActionQueryBase, IRequest<IEnumerable<RecActionDto>>
|
|
{
|
|
public ReadRecActionQuery(ReadRecActionQueryBase root) : base(root) { }
|
|
|
|
public bool? Invoked { get; set; } = null;
|
|
|
|
public ReadRecActionQuery() { }
|
|
}
|
|
|
|
public class ReadRecActionQueryHandler(IRepository<RecActionView> repo, IMapper mapper) : IRequestHandler<ReadRecActionQuery, IEnumerable<RecActionDto>>
|
|
{
|
|
public async Task<IEnumerable<RecActionDto>> Handle(ReadRecActionQuery request, CancellationToken cancel)
|
|
{
|
|
var query = repo.Where(act => act.ProfileId == request.ProfileId);
|
|
|
|
if (request.Invoked is bool invoked)
|
|
query = invoked ? query.Where(act => act.Root!.OutRes != null) : query.Where(act => act.Root!.OutRes == null);
|
|
|
|
var actions = await query.Include(act => act.EndpointAuth).ToListAsync(cancel);
|
|
|
|
if (actions.Count == 0)
|
|
throw new NotFoundException($"No actions found for the profile {request.ProfileId}.");
|
|
|
|
return mapper.Map<IEnumerable<RecActionDto>>(actions);
|
|
}
|
|
} |