From c6d703321fc32ca8218759b533e39890e31e9860 Mon Sep 17 00:00:00 2001 From: kumfo Date: Tue, 1 Nov 2022 18:15:18 +0800 Subject: [PATCH 1/2] feat: admin's answer list filter by question id --- internal/controller/question_controller.go | 1 + internal/entity/answer_entity.go | 11 ++++++----- internal/repo/answer/answer_repo.go | 7 +++++++ 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/internal/controller/question_controller.go b/internal/controller/question_controller.go index ae40d01e..281a7e1b 100644 --- a/internal/controller/question_controller.go +++ b/internal/controller/question_controller.go @@ -391,6 +391,7 @@ func (qc *QuestionController) CmsSearchList(ctx *gin.Context) { // @Param page_size query int false "page size" // @Param status query string false "user status" Enums(available,deleted) // @Param query query string false "answer id or question title" +// @Param question_id query string false "question id" // @Success 200 {object} handler.RespBody // @Router /answer/admin/api/answer/page [get] func (qc *QuestionController) CmsSearchAnswerList(ctx *gin.Context) { diff --git a/internal/entity/answer_entity.go b/internal/entity/answer_entity.go index 0cc9b31e..c51ae157 100644 --- a/internal/entity/answer_entity.go +++ b/internal/entity/answer_entity.go @@ -40,11 +40,12 @@ type AnswerSearch struct { } type CmsAnswerSearch struct { - Page int `json:"page" form:"page"` // Query number of pages - PageSize int `json:"page_size" form:"page_size"` // Search page size - Status int `json:"-" form:"-"` - StatusStr string `json:"status" form:"status"` // Status 1 Available 2 closed 10 Deleted - Query string `validate:"omitempty,gt=0,lte=100" json:"query" form:"query" ` //Query string + Page int `json:"page" form:"page"` // Query number of pages + PageSize int `json:"page_size" form:"page_size"` // Search page size + Status int `json:"-" form:"-"` + StatusStr string `json:"status" form:"status"` // Status 1 Available 2 closed 10 Deleted + Query string `validate:"omitempty,gt=0,lte=100" json:"query" form:"query" ` //Query string + QuestionID string `validate:"omitempty,gt=0,lte=24" json:"question_id" form:"question_id" ` //Query string } type AdminSetAnswerStatusRequest struct { diff --git a/internal/repo/answer/answer_repo.go b/internal/repo/answer/answer_repo.go index a16c695b..4897f05f 100644 --- a/internal/repo/answer/answer_repo.go +++ b/internal/repo/answer/answer_repo.go @@ -257,6 +257,13 @@ func (ar *answerRepo) CmsSearchList(ctx context.Context, search *entity.CmsAnswe } } + // check search by question id + if len(search.QuestionID) > 0 { + session.And(builder.Eq{ + "question_id": search.QuestionID, + }) + } + offset := search.Page * search.PageSize session. OrderBy("a.updated_at desc"). From 1711ab5753396ef4ac49ff9b8cffc2393c9ef1b7 Mon Sep 17 00:00:00 2001 From: kumfo Date: Tue, 1 Nov 2022 18:18:29 +0800 Subject: [PATCH 2/2] feat: admin's answer list filter by question id --- docs/docs.go | 6 ++++++ docs/swagger.json | 6 ++++++ docs/swagger.yaml | 4 ++++ 3 files changed, 16 insertions(+) diff --git a/docs/docs.go b/docs/docs.go index 4162d8a0..f21f508c 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -62,6 +62,12 @@ const docTemplate = `{ "description": "answer id or question title", "name": "query", "in": "query" + }, + { + "type": "string", + "description": "question id", + "name": "question_id", + "in": "query" } ], "responses": { diff --git a/docs/swagger.json b/docs/swagger.json index e60de534..039f67f5 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -50,6 +50,12 @@ "description": "answer id or question title", "name": "query", "in": "query" + }, + { + "type": "string", + "description": "question id", + "name": "question_id", + "in": "query" } ], "responses": { diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 810cfef8..c419b60e 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -1394,6 +1394,10 @@ paths: in: query name: query type: string + - description: question id + in: query + name: question_id + type: string produces: - application/json responses: