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.

fix: answer wrong route

LinkinStar0616351f7e9b
diff --git a/internal/controller/answer_controller.go b/internal/controller/answer_controller.go
index 1389b402..1b9204d6 100644
--- a/internal/controller/answer_controller.go
+++ b/internal/controller/answer_controller.go
@@ -1,7 +1,6 @@
package controller
import (
- "context"
"fmt"
"github.com/gin-gonic/gin"
@@ -176,23 +175,19 @@ func (ac *AnswerController) Update(ctx *gin.Context) {
// @Produce json
// @Param data body schema.AnswerList true "AnswerList"
// @Success 200 {string} string ""
-// @Router /answer/api/v1/answer/list [post]
-func (ac *AnswerController) AnswerList(c *gin.Context) {
- input := new(schema.AnswerList)
- err := c.BindJSON(input)
- if err != nil {
- handler.HandleResponse(c, err, nil)
+// @Router /answer/api/v1/answer/list [get]
+func (ac *AnswerController) AnswerList(ctx *gin.Context) {
+ req := &schema.AnswerList{}
+ if handler.BindAndCheck(ctx, req) {
return
}
- ctx := context.Background()
- userId := middleware.GetLoginUserIDFromContext(c)
- input.LoginUserID = userId
- list, count, err := ac.answerService.SearchList(ctx, input)
+ req.LoginUserID = middleware.GetLoginUserIDFromContext(ctx)
+ list, count, err := ac.answerService.SearchList(ctx, req)
if err != nil {
- handler.HandleResponse(c, err, nil)
+ handler.HandleResponse(ctx, err, nil)
return
}
- handler.HandleResponse(c, nil, gin.H{
+ handler.HandleResponse(ctx, nil, gin.H{
"list": list,
"count": count,
})
diff --git a/internal/router/answer_api_router.go b/internal/router/answer_api_router.go
index fb171877..fc706223 100644
--- a/internal/router/answer_api_router.go
+++ b/internal/router/answer_api_router.go
@@ -100,7 +100,7 @@ func (a *AnswerAPIRouter) RegisterUnAuthAnswerAPIRouter(r *gin.RouterGroup) {
//answer
r.GET("/answer/info", a.answerController.Get)
- r.POST("/answer/list", a.answerController.AnswerList)
+ r.GET("/answer/page", a.answerController.AnswerList)
r.GET("/personal/answer/page", a.questionController.UserAnswerList)
//question
diff --git a/internal/schema/answer_schema.go b/internal/schema/answer_schema.go
index f34391ac..49968e7b 100644
--- a/internal/schema/answer_schema.go
+++ b/internal/schema/answer_schema.go
@@ -113,10 +113,10 @@ type AnswerUpdateReq struct {
}
type AnswerList struct {
- QuestionId string `json:"question_id" ` // question_id
- Order string `json:"order" ` // 1 Default 2 time
- Page int `json:"page" form:"page"` //Query number of pages
- PageSize int `json:"page_size" form:"page_size"` //Search page size
+ QuestionId string `json:"question_id" form:"question_id"` // question_id
+ Order string `json:"order" form:"order"` // 1 Default 2 time
+ Page int `json:"page" form:"page"` //Query number of pages
+ PageSize int `json:"page_size" form:"page_size"` //Search page size
LoginUserID string `json:"-" `
}