fix
This commit is contained in:
@@ -56,6 +56,7 @@ func NewProductHandler(
|
||||
// @Param is_enabled query bool false "是否启用"
|
||||
// @Param is_visible query bool false "是否可见"
|
||||
// @Param is_package query bool false "是否组合包"
|
||||
// @Param is_subscribed query bool false "是否已订阅(需要认证)"
|
||||
// @Param sort_by query string false "排序字段"
|
||||
// @Param sort_order query string false "排序方向" Enums(asc, desc)
|
||||
// @Success 200 {object} responses.ProductListResponse "获取产品列表成功"
|
||||
@@ -63,6 +64,9 @@ func NewProductHandler(
|
||||
// @Failure 500 {object} map[string]interface{} "服务器内部错误"
|
||||
// @Router /api/v1/products [get]
|
||||
func (h *ProductHandler) ListProducts(c *gin.Context) {
|
||||
// 获取当前用户ID(可选认证)
|
||||
userID := h.getCurrentUserID(c)
|
||||
|
||||
// 解析查询参数
|
||||
page := h.getIntQuery(c, "page", 1)
|
||||
pageSize := h.getIntQuery(c, "page_size", 10)
|
||||
@@ -101,6 +105,17 @@ func (h *ProductHandler) ListProducts(c *gin.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
// 订阅状态筛选(需要认证)
|
||||
if userID != "" {
|
||||
if isSubscribed := c.Query("is_subscribed"); isSubscribed != "" {
|
||||
if subscribed, err := strconv.ParseBool(isSubscribed); err == nil {
|
||||
filters["is_subscribed"] = subscribed
|
||||
}
|
||||
}
|
||||
// 添加用户ID到筛选条件
|
||||
filters["user_id"] = userID
|
||||
}
|
||||
|
||||
// 排序字段
|
||||
sortBy := c.Query("sort_by")
|
||||
if sortBy == "" {
|
||||
@@ -141,6 +156,16 @@ func (h *ProductHandler) getIntQuery(c *gin.Context, key string, defaultValue in
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
// getCurrentUserID 获取当前用户ID
|
||||
func (h *ProductHandler) getCurrentUserID(c *gin.Context) string {
|
||||
if userID, exists := c.Get("user_id"); exists {
|
||||
if id, ok := userID.(string); ok {
|
||||
return id
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// GetProductDetail 获取产品详情
|
||||
// @Summary 获取产品详情
|
||||
// @Description 根据产品ID获取产品详细信息
|
||||
|
||||
Reference in New Issue
Block a user