Refactor: move RecActionViewQuery and MappingProfile

Moved ReadRecActionViewQuery and MappingProfile from RecActionViews to RecActions namespace. Updated all references and using directives accordingly. This organizational change consolidates related queries and mapping profiles for improved clarity and maintainability.
This commit is contained in:
2026-01-12 11:27:51 +01:00
parent 9d5334e7dc
commit 5245cd04ff
4 changed files with 4 additions and 4 deletions

View File

@@ -1,5 +1,5 @@
using MediatR;
using ReC.Application.RecActionViews.Queries;
using ReC.Application.RecActions.Queries;
using ReC.Domain.Constants;
namespace ReC.Application.RecActions.Commands;

View File

@@ -0,0 +1,17 @@
using ReC.Application.Common.Dto;
using ReC.Application.RecActions.Commands;
namespace ReC.Application.RecActions;
// TODO: update to inject AddedWho from the current host/user contex
public class MappingProfile : AutoMapper.Profile
{
[Obsolete("Use the related procedure or view.")]
public MappingProfile()
{
CreateMap<CreateRecActionCommand, RecActionDto>()
.ForMember(e => e.Active, exp => exp.MapFrom(cmd => true))
.ForMember(e => e.AddedWhen, exp => exp.MapFrom(cmd => DateTime.UtcNow))
.ForMember(e => e.AddedWho, exp => exp.MapFrom(cmd => "ReC.API"));
}
}

View File

@@ -0,0 +1,37 @@
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.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<RecActionViewDto>>(actions);
}
}