init ReadRecAction query
This commit is contained in:
@@ -1,9 +1,27 @@
|
||||
using MediatR;
|
||||
using ReC.Application.Dto;
|
||||
using DigitalData.Core.Abstraction.Application.Repository;
|
||||
using ReC.Domain.Entities;
|
||||
using AutoMapper;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using DigitalData.Core.Exceptions;
|
||||
|
||||
namespace ReC.Application.RecActions.Queries;
|
||||
|
||||
public class ReadRecActionQuery : IRequest<IEnumerable<RecActionDto>>
|
||||
{
|
||||
public int ProfileId { get; init; }
|
||||
}
|
||||
|
||||
public class ReadRecActionQueryHandler(IRepository<RecAction> repo, IMapper mapper) : IRequestHandler<ReadRecActionQuery, IEnumerable<RecActionDto>>
|
||||
{
|
||||
public async Task<IEnumerable<RecActionDto>> 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<IEnumerable<RecActionDto>>(actions);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user