using Netina.Domain.Entities.Warehouses;

namespace Netina.Repository.Handlers.Warehouses;

public class GetShippingsQueryHandler(IRepositoryWrapper repositoryWrapper)
    : IRequestHandler<GetShippingsQuery, List<ShippingSDto>>
{
    public async Task<List<ShippingSDto>> Handle(GetShippingsQuery request, CancellationToken cancellationToken)
    {
        return await repositoryWrapper
            .SetRepository<Shipping>()
            .TableNoTracking.OrderByDescending(b => b.CreatedAt)
            .Skip(request.Page * 20)
            .Take(20)
            .Select(ShippingMapper.ProjectToSDto)
            .ToListAsync(cancellationToken);
    }
}