This is an automated email from the ASF dual-hosted git repository. linkinstar pushed a commit to branch feat/1.7.1/answer in repository https://gitbox.apache.org/repos/asf/answer.git
commit da27577d9c7d0c72dd2c565770931fa2150ed0ad Author: LinkinStars <[email protected]> AuthorDate: Fri Nov 28 10:49:10 2025 +0800 fix(answer): update QuestionID handling in answer update process --- internal/controller/answer_controller.go | 1 - internal/schema/answer_schema.go | 1 - internal/service/content/answer_service.go | 19 +++++++++---------- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/internal/controller/answer_controller.go b/internal/controller/answer_controller.go index 7c5aca1d..0e43121c 100644 --- a/internal/controller/answer_controller.go +++ b/internal/controller/answer_controller.go @@ -318,7 +318,6 @@ func (ac *AnswerController) UpdateAnswer(ctx *gin.Context) { handler.HandleResponse(ctx, err, nil) return } - req.QuestionID = uid.DeShortID(req.QuestionID) linkUrlLimitUser := canList[2] isAdmin := middleware.GetUserIsAdminModerator(ctx) if !isAdmin || !linkUrlLimitUser { diff --git a/internal/schema/answer_schema.go b/internal/schema/answer_schema.go index 015e26ac..9ac4bcad 100644 --- a/internal/schema/answer_schema.go +++ b/internal/schema/answer_schema.go @@ -78,7 +78,6 @@ type GetAnswerInfoResp struct { type AnswerUpdateReq struct { ID string `json:"id"` - QuestionID string `json:"question_id"` Title string `json:"title"` Content string `validate:"required,notblank,gte=6,lte=65535" json:"content"` EditSummary string `validate:"omitempty" json:"edit_summary"` diff --git a/internal/service/content/answer_service.go b/internal/service/content/answer_service.go index b9d45b52..982bbf88 100644 --- a/internal/service/content/answer_service.go +++ b/internal/service/content/answer_service.go @@ -346,24 +346,23 @@ func (as *AnswerService) Update(ctx context.Context, req *schema.AnswerUpdateReq return "", errors.BadRequest(reason.AnswerCannotUpdate) } - questionInfo, exist, err := as.questionRepo.GetQuestion(ctx, req.QuestionID) + answerInfo, exist, err := as.answerRepo.GetByID(ctx, req.ID) if err != nil { return "", err } if !exist { - return "", errors.BadRequest(reason.QuestionNotFound) + return "", errors.BadRequest(reason.AnswerNotFound) + } + if answerInfo.Status == entity.AnswerStatusDeleted { + return "", errors.BadRequest(reason.AnswerCannotUpdate) } - answerInfo, exist, err := as.answerRepo.GetByID(ctx, req.ID) + questionInfo, exist, err := as.questionRepo.GetQuestion(ctx, answerInfo.QuestionID) if err != nil { return "", err } if !exist { - return "", errors.BadRequest(reason.AnswerNotFound) - } - - if answerInfo.Status == entity.AnswerStatusDeleted { - return "", errors.BadRequest(reason.AnswerCannotUpdate) + return "", errors.BadRequest(reason.QuestionNotFound) } //If the content is the same, ignore it @@ -374,7 +373,7 @@ func (as *AnswerService) Update(ctx context.Context, req *schema.AnswerUpdateReq insertData := &entity.Answer{} insertData.ID = req.ID insertData.UserID = answerInfo.UserID - insertData.QuestionID = req.QuestionID + insertData.QuestionID = questionInfo.ID insertData.OriginalText = req.Content insertData.ParsedText = req.HTML insertData.UpdatedAt = time.Now() @@ -403,7 +402,7 @@ func (as *AnswerService) Update(ctx context.Context, req *schema.AnswerUpdateReq if err = as.answerRepo.UpdateAnswer(ctx, insertData, []string{"original_text", "parsed_text", "updated_at", "last_edit_user_id"}); err != nil { return "", err } - err = as.questionCommon.UpdatePostTime(ctx, req.QuestionID) + err = as.questionCommon.UpdatePostTime(ctx, questionInfo.ID) if err != nil { return insertData.ID, err }
