From de9650b26b97a3ef70efcb1e3e890717d3c0c325 Mon Sep 17 00:00:00 2001 From: timerzz Date: Thu, 12 Sep 2024 20:16:40 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E4=BF=AE=E5=A4=8D=E6=8E=92=E5=BA=8Fbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- structs/storage/article.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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 }