Files
backend_v2/internal/dto/brand.go
toom1996 9c3403a903 update
2026-08-30 10:45:34 +08:00

72 lines
2.8 KiB
Go
Raw 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 dto
// ---------- 请求 ----------
// BrandQuery 品牌列表查询条件。
type BrandQuery struct {
Letter string // A-Z 字母索引;OTHER 表示中文分桶;空表示全部拉丁字母
Keyword string
Page int
Size int // 每页条数,已写死 brandDefaultSize(30),前端不传
// Featured 仅保留"代表品牌"精选集合(按指标排名的前 N 个)。
Featured bool
Metric string // images(默认)| shows
Limit int // 精选集合大小,默认 200
// Locale 语言:cn | en。空时由 service 回落默认 en。
// 决定 name / show_name 出参选取 name_en 还是 name_cn。
Locale string
}
// 品牌列表分页与精选集合的边界,与原项目保持一致。
const (
brandDefaultSize = 30
brandMaxSize = 500
featuredDefaultLimit = 200
featuredMaxLimit = 500
)
// Normalize 校正分页与精选集合参数。
func (q *BrandQuery) Normalize() {
if q.Page < 1 {
q.Page = 1
}
if q.Size < 1 || q.Size > brandMaxSize {
q.Size = brandDefaultSize
}
if q.Metric != "shows" {
q.Metric = "images"
}
if q.Limit < 1 || q.Limit > featuredMaxLimit {
q.Limit = featuredDefaultLimit
}
}
// Offset 返回 SQL 偏移量。
func (q BrandQuery) Offset() int { return (q.Page - 1) * q.Size }
// ---------- 响应 ----------
// PublicBrand 对外展示用的精简品牌结构,剔除 created_at / updated_at / is_deleted。
// 注意:对外只暴露编码后的 UID(非自增主键),防止顺序枚举。
// article_count(各品牌档案数)前端从不展示,已移除,故不再额外查一次分组计数。
type PublicBrand struct {
UID string `json:"id"` // 编码后的品牌 id(无序串),对外唯一标识
Name string `json:"name"` // 按 locale 选列(cn→name_cn,en→name_en)
NameEn string `json:"name_en"` // 英文规范名(始终返回,供前端组合双语展示)
NameCn string `json:"name_cn"` // 中文名(可能为空,供前端组合双语展示)
}
// PopularBrand 首页"热门品牌"区块所需结构。
//
// 与 PublicBrand 不同:这里要带上"代表走秀"的封面与标题,供 SSG 在构建期直接渲染卡片,
// 前端无需再逐篇请求详情。字段对齐需求:id(品牌 id 编码串)/ brand(品牌名)/ cover(封面图)/ title(代表走秀标题)/ article_id(代表走秀 id 编码串,用于跳转到详情页)。
type PopularBrand struct {
UID string `json:"id"` // 编码后的品牌 id(无序串)
ArticleUID string `json:"article_id"` // 编码后的代表走秀 id(无序串)
Brand string `json:"brand"` // 品牌名称
Cover string `json:"cover"` // 代表走秀封面图(相对路径,前端 toAbs 拼 base 后访问)
Title string `json:"title"` // 代表走秀标题
}