From 246d893b62214bb70f4d34c37f7533ac782ca8fc Mon Sep 17 00:00:00 2001 From: masoodafar-web Date: Tue, 30 Jun 2026 00:16:28 +0330 Subject: [PATCH] feat(discount): add InStock filter to discount product queries and mappings - Introduced InStock property to GetDiscountProductsQuery and GetCustomerProductsByFilterQuery for filtering based on product availability. - Updated query handlers to apply InStock filtering logic in both discount and customer product queries. - Enhanced mapping configurations to include InStock in the response DTOs. - Bumped Protobuf project version to reflect the addition of new features. --- .../Queries/GetDiscountProducts/GetDiscountProductsQuery.cs | 4 ++++ .../GetDiscountProducts/GetDiscountProductsQueryHandler.cs | 5 +++++ .../GetCustomerProductsByFilterQuery.cs | 4 ++++ .../GetCustomerProductsByFilterQueryHandler.cs | 5 +++++ src/CMSMicroservice.Protobuf/CMSMicroservice.Protobuf.csproj | 2 +- src/CMSMicroservice.Protobuf/Protos/products.proto | 1 + .../Common/Mappings/DiscountProductProfile.cs | 2 ++ src/CMSMicroservice.WebApi/Services/ProductsService.cs | 2 ++ 8 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/CMSMicroservice.Application/DiscountShopCQ/Queries/GetDiscountProducts/GetDiscountProductsQuery.cs b/src/CMSMicroservice.Application/DiscountShopCQ/Queries/GetDiscountProducts/GetDiscountProductsQuery.cs index 9064e73..93af30c 100644 --- a/src/CMSMicroservice.Application/DiscountShopCQ/Queries/GetDiscountProducts/GetDiscountProductsQuery.cs +++ b/src/CMSMicroservice.Application/DiscountShopCQ/Queries/GetDiscountProducts/GetDiscountProductsQuery.cs @@ -8,6 +8,10 @@ public class GetDiscountProductsQuery : IRequest public PaginationState? PaginationQuery { get; set; } public long? CategoryId { get; set; } public string? SearchTerm { get; set; } + /// + /// true = فقط موجود (RemainingCount > 0)، false = فقط ناموجود + /// + public bool? InStock { get; set; } public bool? IsActive { get; set; } public int? MinPrice { get; set; } public int? MaxPrice { get; set; } diff --git a/src/CMSMicroservice.Application/DiscountShopCQ/Queries/GetDiscountProducts/GetDiscountProductsQueryHandler.cs b/src/CMSMicroservice.Application/DiscountShopCQ/Queries/GetDiscountProducts/GetDiscountProductsQueryHandler.cs index c48bf54..f7e5c9b 100644 --- a/src/CMSMicroservice.Application/DiscountShopCQ/Queries/GetDiscountProducts/GetDiscountProductsQueryHandler.cs +++ b/src/CMSMicroservice.Application/DiscountShopCQ/Queries/GetDiscountProducts/GetDiscountProductsQueryHandler.cs @@ -42,6 +42,11 @@ public class GetDiscountProductsQueryHandler : IRequestHandler p.IsActive == request.IsActive.Value); } + if (request.InStock == true) + query = query.Where(p => p.RemainingCount > 0); + else if (request.InStock == false) + query = query.Where(p => p.RemainingCount <= 0); + if (request.MinPrice.HasValue) { query = query.Where(p => p.Price >= request.MinPrice.Value); diff --git a/src/CMSMicroservice.Application/ProductsCQ/Queries/GetCustomerProductsByFilter/GetCustomerProductsByFilterQuery.cs b/src/CMSMicroservice.Application/ProductsCQ/Queries/GetCustomerProductsByFilter/GetCustomerProductsByFilterQuery.cs index ed3763f..eb9170f 100644 --- a/src/CMSMicroservice.Application/ProductsCQ/Queries/GetCustomerProductsByFilter/GetCustomerProductsByFilterQuery.cs +++ b/src/CMSMicroservice.Application/ProductsCQ/Queries/GetCustomerProductsByFilter/GetCustomerProductsByFilterQuery.cs @@ -21,6 +21,10 @@ public class GetCustomerProductsByFilterQuery : IRequest + /// true = فقط موجود (RemainingCount > 0)، false = فقط ناموجود + /// + public bool? InStock { get; set; } public bool? IsActive { get; set; } public List? CategoryIds { get; set; } } diff --git a/src/CMSMicroservice.Application/ProductsCQ/Queries/GetCustomerProductsByFilter/GetCustomerProductsByFilterQueryHandler.cs b/src/CMSMicroservice.Application/ProductsCQ/Queries/GetCustomerProductsByFilter/GetCustomerProductsByFilterQueryHandler.cs index 9a1e371..669c9d4 100644 --- a/src/CMSMicroservice.Application/ProductsCQ/Queries/GetCustomerProductsByFilter/GetCustomerProductsByFilterQueryHandler.cs +++ b/src/CMSMicroservice.Application/ProductsCQ/Queries/GetCustomerProductsByFilter/GetCustomerProductsByFilterQueryHandler.cs @@ -56,6 +56,11 @@ public class GetCustomerProductsByFilterQueryHandler : IRequestHandler x.RemainingCount == request.RemainingCount.Value); + if (request.InStock == true) + query = query.Where(x => x.RemainingCount > 0); + else if (request.InStock == false) + query = query.Where(x => x.RemainingCount <= 0); + if (request.CategoryIds != null && request.CategoryIds.Any()) query = query.Where(x => x.ProductCategories.Any(pc => request.CategoryIds.Contains(pc.CategoryId))); diff --git a/src/CMSMicroservice.Protobuf/CMSMicroservice.Protobuf.csproj b/src/CMSMicroservice.Protobuf/CMSMicroservice.Protobuf.csproj index 911d4c6..cc8bf9d 100644 --- a/src/CMSMicroservice.Protobuf/CMSMicroservice.Protobuf.csproj +++ b/src/CMSMicroservice.Protobuf/CMSMicroservice.Protobuf.csproj @@ -3,7 +3,7 @@ net9.0 enable enable - 0.0.203 + 0.0.204 None False False diff --git a/src/CMSMicroservice.Protobuf/Protos/products.proto b/src/CMSMicroservice.Protobuf/Protos/products.proto index 9acbae2..210252a 100644 --- a/src/CMSMicroservice.Protobuf/Protos/products.proto +++ b/src/CMSMicroservice.Protobuf/Protos/products.proto @@ -229,6 +229,7 @@ message GetAllProductsByFilterFilter google.protobuf.Int32Value remaining_count = 13; google.protobuf.Int64Value category_id = 14; google.protobuf.BoolValue is_active = 15; + google.protobuf.BoolValue in_stock = 16; } message GetAllProductsByFilterResponse { diff --git a/src/CMSMicroservice.WebApi/Common/Mappings/DiscountProductProfile.cs b/src/CMSMicroservice.WebApi/Common/Mappings/DiscountProductProfile.cs index b695d95..8d3dab2 100644 --- a/src/CMSMicroservice.WebApi/Common/Mappings/DiscountProductProfile.cs +++ b/src/CMSMicroservice.WebApi/Common/Mappings/DiscountProductProfile.cs @@ -19,6 +19,8 @@ public class DiscountProductProfile : IRegister src => src.CategoryId != null ? src.CategoryId.Value : (long?)null) .Map(dest => dest.IsActive, src => src.IsActive != null ? src.IsActive.Value : (bool?)null) + .Map(dest => dest.InStock, + src => src.InStock != null ? src.InStock.Value : (bool?)null) .Map(dest => dest.MinPrice, src => src.MinPrice != null ? (int?)src.MinPrice.Value : null) .Map(dest => dest.MaxPrice, diff --git a/src/CMSMicroservice.WebApi/Services/ProductsService.cs b/src/CMSMicroservice.WebApi/Services/ProductsService.cs index 9d79a54..7b022cb 100644 --- a/src/CMSMicroservice.WebApi/Services/ProductsService.cs +++ b/src/CMSMicroservice.WebApi/Services/ProductsService.cs @@ -175,6 +175,7 @@ public class ProductsService : ProductsContract.ProductsContractBase SaleCount = request.Filter?.SaleCount, ViewCount = request.Filter?.ViewCount, RemainingCount = request.Filter?.RemainingCount, + InStock = request.Filter?.InStock, CategoryIds = request.Filter?.CategoryId.HasValue == true ? new List { request.Filter.CategoryId.Value } : new List(), @@ -567,6 +568,7 @@ public class ProductsService : ProductsContract.ProductsContractBase SaleCount = request.Filter?.SaleCount, ViewCount = request.Filter?.ViewCount, RemainingCount = request.Filter?.RemainingCount, + InStock = request.Filter?.InStock, CategoryIds = request.Filter?.CategoryId != null ? new List { request.Filter.CategoryId.Value } : null };