From 4f8a99010a6f0412d7cabaec4db38e98113378e6 Mon Sep 17 00:00:00 2001 From: BXY <103352887+BXY0414@users.noreply.github.com> Date: Wed, 23 Sep 2026 14:18:26 +0800 Subject: [PATCH] feat: update ListCategoryProducts to support target node type for category and group --- internal/repository/product_repository.go | 10 ++++++---- internal/server/product_server.go | 10 +++++++++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/internal/repository/product_repository.go b/internal/repository/product_repository.go index d986442..e76c494 100644 --- a/internal/repository/product_repository.go +++ b/internal/repository/product_repository.go @@ -2540,8 +2540,8 @@ WHERE store_id = $1 return &counts, nil } -// ListCategoryProducts loads paginated product summaries for a category ID. -func (r *ProductRepository) ListCategoryProducts(ctx context.Context, categoryID string, page, pageSize int32, onlyVisible bool, scope StoreScope) ([]*CategoryProductRecord, int64, error) { +// ListCategoryProducts loads paginated product summaries for a category or group node. +func (r *ProductRepository) ListCategoryProducts(ctx context.Context, categoryID string, page, pageSize int32, onlyVisible bool, targetNodeType int32, scope StoreScope) ([]*CategoryProductRecord, int64, error) { if err := requireWriteScope(scope); err != nil { return nil, 0, err } @@ -2567,8 +2567,9 @@ WHERE b.category_id = $1 AND p.deleted_at IS NULL AND p.store_id = $5 AND c.store_id = $5 + AND c.node_type = $6 AND ($2 = FALSE OR p.status IN ($3, $4)) -`, parsedCategoryID, onlyVisible, statusToDB(productv1.ProductStatus_PRODUCT_STATUS_ON_SALE), statusToDB(productv1.ProductStatus_PRODUCT_STATUS_OFF_SALE), scope.StoreID).Scan(&total); err != nil { +`, parsedCategoryID, onlyVisible, statusToDB(productv1.ProductStatus_PRODUCT_STATUS_ON_SALE), statusToDB(productv1.ProductStatus_PRODUCT_STATUS_OFF_SALE), scope.StoreID, targetNodeType).Scan(&total); err != nil { return nil, 0, fmt.Errorf("count category products: %w", err) } if total == 0 { @@ -2606,10 +2607,11 @@ WHERE b.category_id = $1 AND p.deleted_at IS NULL AND p.store_id = $7 AND c.store_id = $7 + AND c.node_type = $8 AND ($2 = FALSE OR p.status IN ($5, $6)) ORDER BY p.created_at DESC, p.id DESC LIMIT $3 OFFSET $4 -`, parsedCategoryID, onlyVisible, pageSize, offset, statusToDB(productv1.ProductStatus_PRODUCT_STATUS_ON_SALE), statusToDB(productv1.ProductStatus_PRODUCT_STATUS_OFF_SALE), scope.StoreID) +`, parsedCategoryID, onlyVisible, pageSize, offset, statusToDB(productv1.ProductStatus_PRODUCT_STATUS_ON_SALE), statusToDB(productv1.ProductStatus_PRODUCT_STATUS_OFF_SALE), scope.StoreID, targetNodeType) if err != nil { return nil, 0, fmt.Errorf("query category products: %w", err) } diff --git a/internal/server/product_server.go b/internal/server/product_server.go index e1aa4ec..c0c9b37 100644 --- a/internal/server/product_server.go +++ b/internal/server/product_server.go @@ -554,17 +554,25 @@ func (s *ProductServer) ListCategoryProducts(ctx context.Context, req *productv1 if err != nil || categoryID <= 0 { return nil, status.Error(codes.InvalidArgument, "category_id must be a positive snowflake id") } + targetNodeType := req.GetTargetNodeType() + if targetNodeType == 0 { + targetNodeType = 1 + } + if targetNodeType != 1 && targetNodeType != 2 { + return nil, status.Error(codes.InvalidArgument, "target_node_type must be category (1) or group (2)") + } page, pageSize := normalizedPage(req.GetPage(), req.GetPageSize()) dbCtx, dbSpan := s.observer.Tracer().Start(ctx, "product.list_by_category", trace.WithAttributes( attribute.String("category.id", req.GetCategoryId()), + attribute.Int("category.node_type", int(targetNodeType)), attribute.Int("page", int(page)), attribute.Int("page_size", int(pageSize)), )) defer dbSpan.End() - products, total, err := s.repo.ListCategoryProducts(dbCtx, req.GetCategoryId(), page, pageSize, req.GetOnlyVisible(), scope) + products, total, err := s.repo.ListCategoryProducts(dbCtx, req.GetCategoryId(), page, pageSize, req.GetOnlyVisible(), targetNodeType, scope) if err != nil { dbSpan.RecordError(err) dbSpan.SetStatus(otelcodes.Error, err.Error())