From 683ed370b5e1d123202538e9734d8bec9479db7f Mon Sep 17 00:00:00 2001 From: masoodafar-web Date: Wed, 13 May 2026 19:47:56 +0330 Subject: [PATCH 1/3] feat: extend discount product gRPC API with sort_by and sale_count - Add sort_by (StringValue) to GetDiscountProductsRequest proto to enable dynamic sorting - Add sale_count (int32) to DiscountProductDto proto for top-seller exposure - Update GetDiscountProductsQuery with SortBy property - Update GetDiscountProductsQueryHandler to use ApplyOrder(SortBy) with fallback to Created desc; project SaleCount in SELECT - Add SortBy and SaleCount Mapster mappings in DiscountProductProfile - Bump CMSMicroservice.Protobuf version to 0.0.196 Co-authored-by: Cursor --- .../GetDiscountProducts/GetDiscountProductsQuery.cs | 1 + .../GetDiscountProductsQueryHandler.cs | 10 +++++++--- .../CMSMicroservice.Protobuf.csproj | 2 +- .../Protos/discountproduct.proto | 2 ++ .../Common/Mappings/DiscountProductProfile.cs | 3 +++ 5 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/CMSMicroservice.Application/DiscountShopCQ/Queries/GetDiscountProducts/GetDiscountProductsQuery.cs b/src/CMSMicroservice.Application/DiscountShopCQ/Queries/GetDiscountProducts/GetDiscountProductsQuery.cs index e094519..9064e73 100644 --- a/src/CMSMicroservice.Application/DiscountShopCQ/Queries/GetDiscountProducts/GetDiscountProductsQuery.cs +++ b/src/CMSMicroservice.Application/DiscountShopCQ/Queries/GetDiscountProducts/GetDiscountProductsQuery.cs @@ -11,6 +11,7 @@ public class GetDiscountProductsQuery : IRequest public bool? IsActive { get; set; } public int? MinPrice { get; set; } public int? MaxPrice { get; set; } + public string? SortBy { get; set; } } public class GetDiscountProductsResponseDto diff --git a/src/CMSMicroservice.Application/DiscountShopCQ/Queries/GetDiscountProducts/GetDiscountProductsQueryHandler.cs b/src/CMSMicroservice.Application/DiscountShopCQ/Queries/GetDiscountProducts/GetDiscountProductsQueryHandler.cs index 6b3f7c7..c48bf54 100644 --- a/src/CMSMicroservice.Application/DiscountShopCQ/Queries/GetDiscountProducts/GetDiscountProductsQueryHandler.cs +++ b/src/CMSMicroservice.Application/DiscountShopCQ/Queries/GetDiscountProducts/GetDiscountProductsQueryHandler.cs @@ -1,3 +1,4 @@ +using CMSMicroservice.Application.Common.Extensions; using CMSMicroservice.Application.Common.Interfaces; using CMSMicroservice.Application.Common.Models; using MediatR; @@ -51,13 +52,16 @@ public class GetDiscountProductsQueryHandler : IRequestHandler p.Price <= request.MaxPrice.Value); } + if (!string.IsNullOrEmpty(request.SortBy)) + query = query.ApplyOrder(request.SortBy); + else + query = query.OrderByDescending(p => p.Created); + var totalCount = await query.CountAsync(cancellationToken); - // Apply pagination var pagination = request.PaginationQuery ?? new PaginationState { PageNumber = 1, PageSize = 10 }; - + var products = await query - .OrderByDescending(p => p.Created) .Skip((pagination.PageNumber - 1) * pagination.PageSize) .Take(pagination.PageSize) .Select(p => new DiscountProductDto diff --git a/src/CMSMicroservice.Protobuf/CMSMicroservice.Protobuf.csproj b/src/CMSMicroservice.Protobuf/CMSMicroservice.Protobuf.csproj index f857e88..d6e0aa8 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.195 + 0.0.196 None False False diff --git a/src/CMSMicroservice.Protobuf/Protos/discountproduct.proto b/src/CMSMicroservice.Protobuf/Protos/discountproduct.proto index c549fba..4eaaa19 100644 --- a/src/CMSMicroservice.Protobuf/Protos/discountproduct.proto +++ b/src/CMSMicroservice.Protobuf/Protos/discountproduct.proto @@ -163,6 +163,7 @@ message GetDiscountProductsRequest google.protobuf.BoolValue in_stock = 6; int32 page_number = 7; int32 page_size = 8; + google.protobuf.StringValue sort_by = 9; } message GetDiscountProductsResponse @@ -184,6 +185,7 @@ message DiscountProductDto int32 view_count = 9; bool is_active = 10; google.protobuf.Timestamp created = 11; + int32 sale_count = 12; } // ===== Product Image Gallery Messages ===== diff --git a/src/CMSMicroservice.WebApi/Common/Mappings/DiscountProductProfile.cs b/src/CMSMicroservice.WebApi/Common/Mappings/DiscountProductProfile.cs index d80be07..b695d95 100644 --- a/src/CMSMicroservice.WebApi/Common/Mappings/DiscountProductProfile.cs +++ b/src/CMSMicroservice.WebApi/Common/Mappings/DiscountProductProfile.cs @@ -23,6 +23,8 @@ public class DiscountProductProfile : IRegister src => src.MinPrice != null ? (int?)src.MinPrice.Value : null) .Map(dest => dest.MaxPrice, src => src.MaxPrice != null ? (int?)src.MaxPrice.Value : null) + .Map(dest => dest.SortBy, + src => string.IsNullOrEmpty(src.SortBy) ? null : src.SortBy) .Map(dest => dest.PaginationQuery, src => new PaginationState { PageNumber = src.PageNumber > 0 ? src.PageNumber : 1, @@ -64,6 +66,7 @@ public class DiscountProductProfile : IRegister ThumbnailPath = p.ThumbnailPath ?? string.Empty, RemainingCount = p.RemainingCount, ViewCount = p.ViewCount, + SaleCount = p.SaleCount, IsActive = p.IsActive, Created = Timestamp.FromDateTime(DateTime.UtcNow) }); From fd8b37a6b14a58682114eb6f7a6ac4ba9de5a4fd Mon Sep 17 00:00:00 2001 From: masoodafar-web Date: Wed, 13 May 2026 22:05:26 +0330 Subject: [PATCH 2/3] docs: add note on TLS certificate requirements for cms-tls in Ingress configuration --- k8s/staging/cms-deployment.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/k8s/staging/cms-deployment.yaml b/k8s/staging/cms-deployment.yaml index b5797a4..f54219b 100644 --- a/k8s/staging/cms-deployment.yaml +++ b/k8s/staging/cms-deployment.yaml @@ -101,6 +101,8 @@ spec: --- # CMS Ingress +# If clients report TLS PartialChain, the tls secret (cms-tls) tls.crt must include the full chain +# (leaf + intermediates). cert-manager ACME usually provides this; manual certs need fullchain.pem in tls.crt. apiVersion: networking.k8s.io/v1 kind: Ingress metadata: From 6e60ca7c251327d191d733d43a65e87648e9a881 Mon Sep 17 00:00:00 2001 From: masoodafar-web Date: Wed, 13 May 2026 22:21:22 +0330 Subject: [PATCH 3/3] chore: bump CMSMicroservice.Protobuf version to 0.0.197 --- src/CMSMicroservice.Protobuf/CMSMicroservice.Protobuf.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CMSMicroservice.Protobuf/CMSMicroservice.Protobuf.csproj b/src/CMSMicroservice.Protobuf/CMSMicroservice.Protobuf.csproj index d6e0aa8..2f94a67 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.196 + 0.0.197 None False False