Skip to content

A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.

feat: admin's answer list filter by question id

kumfoc6d703321fc3
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").