You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@answer.apache.org by li...@apache.org on 2025/06/24 03:06:26 UTC
(answer) 02/03: refactor(api): update API documentation and method names for clarity
This is an automated email from the ASF dual-hosted git repository.
linkinstar pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/answer.git
commit dc98f61d69e28023d1113fee276227f3f2390896
Author: LinkinStars <li...@foxmail.com>
AuthorDate: Tue Jun 24 11:05:11 2025 +0800
refactor(api): update API documentation and method names for clarity
---
internal/controller/answer_controller.go | 70 ++++++++++++++++----------------
internal/router/answer_api_router.go | 4 +-
internal/schema/answer_schema.go | 5 +++
3 files changed, 42 insertions(+), 37 deletions(-)
diff --git a/internal/controller/answer_controller.go b/internal/controller/answer_controller.go
index 157e1b25..a22c597f 100644
--- a/internal/controller/answer_controller.go
+++ b/internal/controller/answer_controller.go
@@ -69,7 +69,7 @@ func NewAnswerController(
// RemoveAnswer delete answer
// @Summary delete answer
// @Description delete answer
-// @Tags api-answer
+// @Tags Answer
// @Accept json
// @Produce json
// @Security ApiKeyAuth
@@ -119,7 +119,7 @@ func (ac *AnswerController) RemoveAnswer(ctx *gin.Context) {
// RecoverAnswer recover answer
// @Summary recover answer
-// @Description recover deleted answer
+// @Description recover the deleted answer
// @Tags Answer
// @Accept json
// @Produce json
@@ -151,16 +151,16 @@ func (ac *AnswerController) RecoverAnswer(ctx *gin.Context) {
handler.HandleResponse(ctx, err, nil)
}
-// Get godoc
-// @Summary Get Answer
-// @Description Get Answer
-// @Tags api-answer
-// @Accept json
-// @Produce json
-// @Param id query string true "Answer TagID" default(1)
-// @Router /answer/api/v1/answer/info [get]
-// @Success 200 {string} string ""
-func (ac *AnswerController) Get(ctx *gin.Context) {
+// GetAnswerInfo get answer info
+// @Summary Get Answer Detail
+// @Description Get Answer Detail
+// @Tags Answer
+// @Accept json
+// @Produce json
+// @Param id query string true "id"
+// @Success 200 {object} handler.RespBody{data=schema.GetAnswerInfoResp}
+// @Router /answer/api/v1/answer/info [get]
+func (ac *AnswerController) GetAnswerInfo(ctx *gin.Context) {
id := ctx.Query("id")
id = uid.DeShortID(id)
userID := middleware.GetLoginUserIDFromContext(ctx)
@@ -174,23 +174,23 @@ func (ac *AnswerController) Get(ctx *gin.Context) {
handler.HandleResponse(ctx, fmt.Errorf(""), gin.H{})
return
}
- handler.HandleResponse(ctx, err, gin.H{
- "info": info,
- "question": questionInfo,
+ handler.HandleResponse(ctx, err, &schema.GetAnswerInfoResp{
+ Info: info,
+ Question: questionInfo,
})
}
-// Add godoc
-// @Summary Insert Answer
-// @Description Insert Answer
-// @Tags api-answer
-// @Accept json
-// @Produce json
+// AddAnswer add answer
+// @Summary Add Answer
+// @Description add answer
+// @Tags Answer
+// @Accept json
+// @Produce json
// @Security ApiKeyAuth
-// @Param data body schema.AnswerAddReq true "AnswerAddReq"
-// @Success 200 {string} string ""
+// @Param data body schema.AnswerAddReq true "add answer request"
+// @Success 200 {object} handler.RespBody{}
// @Router /answer/api/v1/answer [post]
-func (ac *AnswerController) Add(ctx *gin.Context) {
+func (ac *AnswerController) AddAnswer(ctx *gin.Context) {
req := &schema.AnswerAddReq{}
if handler.BindAndCheck(ctx, req) {
return
@@ -295,11 +295,11 @@ func (ac *AnswerController) Add(ctx *gin.Context) {
// Update godoc
// @Summary Update Answer
// @Description Update Answer
-// @Tags api-answer
-// @Accept json
-// @Produce json
+// @Tags Answer
+// @Accept json
+// @Produce json
// @Security ApiKeyAuth
-// @Param data body schema.AnswerUpdateReq true "AnswerUpdateReq"
+// @Param data body schema.AnswerUpdateReq true "AnswerUpdateReq"
// @Success 200 {string} string ""
// @Router /answer/api/v1/answer [put]
func (ac *AnswerController) Update(ctx *gin.Context) {
@@ -360,9 +360,9 @@ func (ac *AnswerController) Update(ctx *gin.Context) {
// AnswerList godoc
// @Summary AnswerList
// @Description AnswerList <br> <b>order</b> (default or updated)
-// @Tags api-answer
-// @Accept json
-// @Produce json
+// @Tags Answer
+// @Accept json
+// @Produce json
// @Param question_id query string true "question_id"
// @Param order query string true "order"
// @Param page query string true "page"
@@ -405,11 +405,11 @@ func (ac *AnswerController) AnswerList(ctx *gin.Context) {
// Accepted godoc
// @Summary Accepted
// @Description Accepted
-// @Tags api-answer
-// @Accept json
-// @Produce json
+// @Tags Answer
+// @Accept json
+// @Produce json
// @Security ApiKeyAuth
-// @Param data body schema.AcceptAnswerReq true "AcceptAnswerReq"
+// @Param data body schema.AcceptAnswerReq true "AcceptAnswerReq"
// @Success 200 {string} string ""
// @Router /answer/api/v1/answer/acceptance [post]
func (ac *AnswerController) Accepted(ctx *gin.Context) {
diff --git a/internal/router/answer_api_router.go b/internal/router/answer_api_router.go
index e01bd9a9..cba23707 100644
--- a/internal/router/answer_api_router.go
+++ b/internal/router/answer_api_router.go
@@ -157,7 +157,7 @@ func (a *AnswerAPIRouter) RegisterUnAuthAnswerAPIRouter(r *gin.RouterGroup) {
r.GET("/user/staff", a.userController.UserStaff)
// answer
- r.GET("/answer/info", a.answerController.Get)
+ r.GET("/answer/info", a.answerController.GetAnswerInfo)
r.GET("/answer/page", a.answerController.AnswerList)
r.GET("/personal/answer/page", a.questionController.PersonalAnswerPage)
@@ -265,7 +265,7 @@ func (a *AnswerAPIRouter) RegisterAnswerAPIRouter(r *gin.RouterGroup) {
r.POST("/question/recover", a.questionController.QuestionRecover)
// answer
- r.POST("/answer", a.answerController.Add)
+ r.POST("/answer", a.answerController.AddAnswer)
r.PUT("/answer", a.answerController.Update)
r.POST("/answer/acceptance", a.answerController.Accepted)
r.DELETE("/answer", a.answerController.RemoveAnswer)
diff --git a/internal/schema/answer_schema.go b/internal/schema/answer_schema.go
index 3a404ed1..015e26ac 100644
--- a/internal/schema/answer_schema.go
+++ b/internal/schema/answer_schema.go
@@ -71,6 +71,11 @@ func (req *AnswerAddReq) Check() (errFields []*validator.FormErrorField, err err
return nil, nil
}
+type GetAnswerInfoResp struct {
+ Info *AnswerInfo `json:"info"`
+ Question *QuestionInfoResp `json:"question"`
+}
+
type AnswerUpdateReq struct {
ID string `json:"id"`
QuestionID string `json:"question_id"`