forked from sanchezvem/PyroFetes
Added endpoint to get products under their limit
This commit is contained in:
@@ -0,0 +1,21 @@
|
|||||||
|
using AutoMapper;
|
||||||
|
using FastEndpoints;
|
||||||
|
using PyroFetes.DTO.Product.Response;
|
||||||
|
using PyroFetes.Repositories;
|
||||||
|
using PyroFetes.Specifications.Products;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.Products;
|
||||||
|
|
||||||
|
public class GetAllProductsUnderLimitEndpoint(ProductsRepository productsRepository) : EndpointWithoutRequest<List<GetProductDto>>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Get("/products/underLimit");
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(CancellationToken ct)
|
||||||
|
{
|
||||||
|
await Send.OkAsync(await productsRepository.ProjectToListAsync<GetProductDto>(new GetProductsUnderLimitSpec(), ct), ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
using Ardalis.Specification;
|
||||||
|
using PyroFetes.Models;
|
||||||
|
|
||||||
|
namespace PyroFetes.Specifications.Products;
|
||||||
|
|
||||||
|
public sealed class GetProductsUnderLimitSpec : Specification<Product>
|
||||||
|
{
|
||||||
|
public GetProductsUnderLimitSpec()
|
||||||
|
{
|
||||||
|
Query
|
||||||
|
.Include(p => p.QuotationProducts)
|
||||||
|
.Where(p => p.QuotationProducts.Any(q => q.Quantity < p.MinimalQuantity));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user