fix 修复排序bug

This commit is contained in:
timerzz 2024-09-13 20:11:00 +08:00
parent 3695565f76
commit f0a601466b

View File

@ -119,6 +119,8 @@ func (f *FindArticleQuery) SortScope(db *gorm.DB) *gorm.DB {
db = db.Order("rate desc") db = db.Order("rate desc")
} else if f.RateSort == "ascend" { } else if f.RateSort == "ascend" {
db = db.Order("rate asc") db = db.Order("rate asc")
} else {
db = db.Order("id desc")
} }
return db return db
} }
@ -132,7 +134,7 @@ func (a *articleApi) List(query PageListQuery, scopes ...func(db *gorm.DB) *gorm
if err != nil { if err != nil {
return return
} }
err = a.db.Scopes(query.Scope).Scopes(scopes...).Order("id").Find(&articles).Error err = a.db.Scopes(query.Scope).Scopes(scopes...).Find(&articles).Error
return return
} }