feat(product): update product status handling and enhance category tree response logging

This commit is contained in:
robinj0726 2026-08-31 15:01:56 +08:00
parent 891bae4742
commit ba95c9079f

View File

@ -468,9 +468,16 @@ func (s *ProductServer) ListCategoryTree(ctx context.Context, req *productv1.Lis
dbSpan.SetAttributes(attribute.Int("category.result_count", len(categories)))
observability.IncCategoryTreeLists()
return &productv1.ListCategoryTreeResponse{
resp := &productv1.ListCategoryTreeResponse{
Categories: buildCategoryTree(categories),
}, nil
}
if payload, marshalErr := (protojson.MarshalOptions{UseProtoNames: true, EmitUnpopulated: true}).Marshal(resp); marshalErr != nil {
s.observer.Logger(ctx).Warn("marshal category tree response for logging failed", zap.Error(marshalErr))
} else {
s.observer.Logger(ctx).Info("list category tree response", zap.ByteString("response", payload))
}
return resp, nil
}
// CreateCategoryTree creates a top-level category and optional second-level categories.
@ -1094,6 +1101,9 @@ func productFromCreateRequest(req *productv1.CreateProductRequest) (repository.P
}
statusValue := req.GetStatus()
if statusValue == productv1.ProductStatus_PRODUCT_STATUS_NOT_FOUND {
statusValue = productv1.ProductStatus_PRODUCT_STATUS_INVENTORY
}
if statusValue != productv1.ProductStatus_PRODUCT_STATUS_INVENTORY &&
statusValue != productv1.ProductStatus_PRODUCT_STATUS_ON_SALE &&
statusValue != productv1.ProductStatus_PRODUCT_STATUS_OFF_SALE {