Files
backend_v2/internal/handler/brand_handler.go
2026-09-20 01:06:13 +08:00

57 lines
1.7 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package handler
import (
"net/http"
"strings"
"fashionapi/internal/dto"
"fashionapi/internal/pkg/response"
"fashionapi/internal/service"
"github.com/gin-gonic/gin"
)
// BrandHandler 对外公开的品牌接口。
type BrandHandler struct {
brands service.BrandService
}
// NewBrandHandler 创建品牌 handler。
func NewBrandHandler(brands service.BrandService) *BrandHandler {
return &BrandHandler{brands: brands}
}
// List 品牌列表(A-Z 字母索引 / 搜索 / 分页)。
//
// GET /api/v1/public/brands
//
// 查询参数:
// - letter A-Z 字母;other 表示中文分桶;缺省返回全部拉丁字母开头的品牌
// - keyword 品牌名 / 展示名模糊搜索(不过滤"必须有走秀档案")
// - page 页码(size 已写死 30,前端不传)
// - featured 传 1 时只返回"代表品牌"精选集合
// - metric 精选排名指标:images(默认)/ shows
// - limit 精选集合大小,默认 200、上限 500
//
// 注:原 only_with_articles 参数已删除——字母索引始终只返回有走秀档案的品牌,
// 该过滤不再可由调用方关闭。
func (h *BrandHandler) List(c *gin.Context) {
q := dto.BrandQuery{
Letter: strings.ToUpper(strings.TrimSpace(c.Query("letter"))),
Keyword: strings.TrimSpace(c.Query("keyword")),
Page: queryInt(c, "page", 1),
Featured: queryBool(c, "featured", false),
Metric: strings.ToLower(strings.TrimSpace(c.Query("metric"))),
Limit: queryInt(c, "limit", 200),
Locale: parseLocale(c),
}
q.Normalize()
list, total, err := h.brands.List(c.Request.Context(), q)
if err != nil {
fail(c, err)
return
}
response.Page(c, http.StatusOK, list, total, q.Size)
}