28 lines
1.0 KiB
C#
28 lines
1.0 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using Netina.Domain.CommandQueries.Queries;
|
|
using Netina.Domain.Dtos.SmallDtos;
|
|
using Netina.Domain.Entities.Users;
|
|
using Netina.Repository.Repositories.Base.Contracts;
|
|
|
|
namespace Netina.Repository.Handlers.Newsletters;
|
|
|
|
public class GetNewsletterMembersQueryHandler : IRequestHandler<GetNewsletterMembersQuery,List<NewsletterMemberSDto>>
|
|
{
|
|
private readonly IRepositoryWrapper _repositoryWrapper;
|
|
|
|
public GetNewsletterMembersQueryHandler(IRepositoryWrapper repositoryWrapper)
|
|
{
|
|
_repositoryWrapper = repositoryWrapper;
|
|
}
|
|
public async Task<List<NewsletterMemberSDto>> Handle(GetNewsletterMembersQuery request, CancellationToken cancellationToken)
|
|
{
|
|
var dtos = await _repositoryWrapper.SetRepository<NewsletterMember>()
|
|
.TableNoTracking
|
|
.OrderByDescending(n => n.CreatedAt)
|
|
.Select(NewsletterMemberMapper.ProjectToSDto)
|
|
.Skip(request.Page * 20)
|
|
.Take(20)
|
|
.ToListAsync(cancellationToken);
|
|
return dtos;
|
|
}
|
|
} |