update
This commit is contained in:
56
internal/handler/brand_handler.go
Normal file
56
internal/handler/brand_handler.go
Normal file
@ -0,0 +1,56 @@
|
||||
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/public/brands
|
||||
//
|
||||
// 查询参数:
|
||||
// - letter A-Z 字母;other 表示中文分桶;缺省返回全部拉丁字母开头的品牌
|
||||
// - keyword 品牌名 / 展示名模糊搜索
|
||||
// - page / size 分页,size 默认 200、上限 500
|
||||
// - only_with_articles 默认 1,只返回有走秀档案的品牌;传 0 返回全部
|
||||
// - featured 传 1 时只返回"代表品牌"精选集合
|
||||
// - metric 精选排名指标:images(默认)/ shows
|
||||
// - limit 精选集合大小,默认 200、上限 500
|
||||
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),
|
||||
Size: queryInt(c, "size", 200),
|
||||
OnlyWithArticles: queryBool(c, "only_with_articles", true),
|
||||
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.Page, q.Size)
|
||||
}
|
||||
Reference in New Issue
Block a user