update
This commit is contained in:
@ -10,6 +10,7 @@ type StreetSnapQuery struct {
|
||||
Page int
|
||||
Size int // 服务端固定为 StreetSnapFixedSize,不从 query 读取
|
||||
Year int // 单值年份,0 表示不过滤
|
||||
City string // 地区/城市(精确匹配 city 列),'' 表示不过滤
|
||||
Sort string // image_count(默认)/ year_desc / year_asc
|
||||
Images int // 服务端固定为 StreetSnapFixedImages,不从 query 读取
|
||||
Locale string
|
||||
|
||||
@ -30,6 +30,7 @@ func NewStreetSnapHandler(svc service.StreetSnapService) *StreetSnapHandler {
|
||||
// 查询参数:
|
||||
// - page 页码,默认 1(服务端固定每页 StreetSnapFixedSize=24 条)
|
||||
// - year 年份(整数),0 表示不过滤
|
||||
// - city 地区/城市(精确匹配 city 列),'' 表示不过滤
|
||||
// - sort image_count(默认,按图片数降序)/ year_desc / year_asc
|
||||
// - locale cn / en
|
||||
//
|
||||
@ -51,6 +52,7 @@ func (h *StreetSnapHandler) parseListQuery(c *gin.Context) dto.StreetSnapQuery {
|
||||
Page: queryInt(c, "page", 1),
|
||||
Size: dto.StreetSnapFixedSize, // 服务端固定,前端不传
|
||||
Year: queryInt(c, "year", 0),
|
||||
City: c.DefaultQuery("city", ""),
|
||||
Sort: c.DefaultQuery("sort", "image_count"),
|
||||
Images: dto.StreetSnapFixedImages, // 服务端固定,前端不传
|
||||
Locale: parseLocale(c),
|
||||
|
||||
@ -8,6 +8,7 @@ type StreetSnap struct {
|
||||
ID uint32 `gorm:"primaryKey;column:id" json:"id"`
|
||||
Title string `gorm:"column:title" json:"title"`
|
||||
Year uint16 `gorm:"column:year" json:"year"`
|
||||
City string `gorm:"column:city" json:"city"` // 地区/城市(从 title 第一段 \t 解析回填),'' 表示未归类
|
||||
Cover string `gorm:"column:cover" json:"cover"`
|
||||
SourceURL string `gorm:"column:source_url" json:"source_url"`
|
||||
ImageCount uint16 `gorm:"column:image_count" json:"image_count"`
|
||||
|
||||
@ -40,6 +40,9 @@ func snapFilterScope(q dto.StreetSnapQuery) func(*gorm.DB) *gorm.DB {
|
||||
if q.Year != 0 {
|
||||
db = db.Where("year = ?", q.Year)
|
||||
}
|
||||
if q.City != "" {
|
||||
db = db.Where("city = ?", q.City)
|
||||
}
|
||||
return db
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user