From 9c3026fff2a9251e9afbcdc6c17506e4a8df7fcf Mon Sep 17 00:00:00 2001 From: wucongxing8150 <815046773@qq.com> Date: Fri, 18 Oct 2024 09:36:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=97=AE=E7=AD=94=E9=A2=98?= =?UTF-8?q?=E5=BA=93=20=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/dao/QuestionQa.go | 16 ++++++++++++++++ api/requests/QuestionQa.go | 4 +++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/api/dao/QuestionQa.go b/api/dao/QuestionQa.go index 2e16c9c..6cdb9d3 100644 --- a/api/dao/QuestionQa.go +++ b/api/dao/QuestionQa.go @@ -165,6 +165,22 @@ func (r *QuestionQaDao) GetQuestionQaPageSearch(req requests.GetQuestionQaPage, // 排序 if req.Order != nil { + if req.Order.QaExpireTime != "" { + if req.Order.QaExpireTime != "desc" && req.Order.QaExpireTime != "asc" { + return nil, 0, errors.New("排序字段错误") + } + + query = query.Order("qa_expire_time " + req.Order.QaExpireTime) + } + + if req.Order.QaQuantity != "" { + if req.Order.QaQuantity != "desc" && req.Order.QaQuantity != "asc" { + return nil, 0, errors.New("排序字段错误") + } + + query = query.Order("qa_quantity " + req.Order.QaQuantity) + } + if req.Order.UpdatedAt != "" { if req.Order.UpdatedAt != "desc" && req.Order.UpdatedAt != "asc" { return nil, 0, errors.New("排序字段错误") diff --git a/api/requests/QuestionQa.go b/api/requests/QuestionQa.go index facc219..dd0f238 100644 --- a/api/requests/QuestionQa.go +++ b/api/requests/QuestionQa.go @@ -26,7 +26,9 @@ type GetQuestionQaPage struct { // GetQuestionQaPageOrder 获取题目列表-分页-排序条件 type GetQuestionQaPageOrder struct { - UpdatedAt string `json:"updated_at" form:"updated_at" label:"排序"` + UpdatedAt string `json:"updated_at" form:"updated_at" label:"排序"` + QaExpireTime string `json:"qa_expire_time" form:"qa_expire_time" label:"排序"` // 有效期 + QaQuantity string `json:"qa_quantity" form:"qa_quantity" label:"排序"` // 题数 } // AddQuestionQa 新增问答题库