diff --git a/structs/storage/article.go b/structs/storage/article.go index b2eeaee..31a9f58 100644 --- a/structs/storage/article.go +++ b/structs/storage/article.go @@ -111,8 +111,10 @@ func (f *FindArticleQuery) Scope(db *gorm.DB) *gorm.DB { if f.Available != nil { db = db.Where("available=?", *f.Available) } - if f.RateSort != "" { - db = db.Order("rate " + f.RateSort) + if f.RateSort == "descend" { + db = db.Order("rate desc") + } else if f.RateSort == "ascend" { + db = db.Order("rate asc") } return db }