From 3487baad8725e7d221417844b7b055150d0fbc7c Mon Sep 17 00:00:00 2001 From: Cristiano Date: Thu, 18 Dec 2025 14:41:45 +0100 Subject: [PATCH] Added endpoint to get products under their limit --- .../GetAllProductsUnderLimitEndpoint.cs | 21 +++++++++++++++++++ .../Products/GetProductsUnderLimitSpec.cs | 14 +++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 PyroFetes/Endpoints/Products/GetAllProductsUnderLimitEndpoint.cs create mode 100644 PyroFetes/Specifications/Products/GetProductsUnderLimitSpec.cs diff --git a/PyroFetes/Endpoints/Products/GetAllProductsUnderLimitEndpoint.cs b/PyroFetes/Endpoints/Products/GetAllProductsUnderLimitEndpoint.cs new file mode 100644 index 0000000..2057c35 --- /dev/null +++ b/PyroFetes/Endpoints/Products/GetAllProductsUnderLimitEndpoint.cs @@ -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> +{ + public override void Configure() + { + Get("/products/underLimit"); + AllowAnonymous(); + } + + public override async Task HandleAsync(CancellationToken ct) + { + await Send.OkAsync(await productsRepository.ProjectToListAsync(new GetProductsUnderLimitSpec(), ct), ct); + } +} \ No newline at end of file diff --git a/PyroFetes/Specifications/Products/GetProductsUnderLimitSpec.cs b/PyroFetes/Specifications/Products/GetProductsUnderLimitSpec.cs new file mode 100644 index 0000000..26c8d12 --- /dev/null +++ b/PyroFetes/Specifications/Products/GetProductsUnderLimitSpec.cs @@ -0,0 +1,14 @@ +using Ardalis.Specification; +using PyroFetes.Models; + +namespace PyroFetes.Specifications.Products; + +public sealed class GetProductsUnderLimitSpec : Specification +{ + public GetProductsUnderLimitSpec() + { + Query + .Include(p => p.QuotationProducts) + .Where(p => p.QuotationProducts.Any(q => q.Quantity < p.MinimalQuantity)); + } +} \ No newline at end of file