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(template): incorrectly parsing the question title to the answer id, resulting in the infinite redirect #885
LinkinStars58dd97ac2a6f
diff --git a/internal/controller/template_controller.go b/internal/controller/template_controller.goindex b128b91a..fa95e460 100644--- a/internal/controller/template_controller.go+++ b/internal/controller/template_controller.go@@ -218,6 +218,11 @@ func (tc *TemplateController) QuestionInfoeRdirect(ctx *gin.Context, siteInfo *s}}+ if _, err := tc.templateRenderController.AnswerDetail(ctx, answerID); err != nil {+ answerID = ""+ titleIsAnswerID = false+ }+url = fmt.Sprintf("%s/questions/%s", siteInfo.General.SiteUrl, questionID)if siteInfo.SiteSeo.Permalink == constant.PermalinkQuestionID || siteInfo.SiteSeo.Permalink == constant.PermalinkQuestionIDByShortID {if len(ctx.Request.URL.Query()) > 0 {diff --git a/internal/controller/template_render/answer.go b/internal/controller/template_render/answer.goindex cc94f0dd..72a0925a 100644--- a/internal/controller/template_render/answer.go+++ b/internal/controller/template_render/answer.go@@ -28,3 +28,7 @@ import (func (t *TemplateRenderController) AnswerList(ctx context.Context, req *schema.AnswerListReq) ([]*schema.AnswerInfo, int64, error) {return t.answerService.SearchList(ctx, req)}++func (t *TemplateRenderController) AnswerDetail(ctx context.Context, id string) (*schema.AnswerInfo, error) {+ return t.answerService.GetDetail(ctx, id)+}diff --git a/internal/service/content/answer_service.go b/internal/service/content/answer_service.goindex d96d75c5..09ec50c8 100644--- a/internal/service/content/answer_service.go+++ b/internal/service/content/answer_service.go@@ -510,6 +510,18 @@ func (as *AnswerService) Get(ctx context.Context, answerID, loginUserID string)return info, questionInfo, has, nil}+func (as *AnswerService) GetDetail(ctx context.Context, answerID string) (*schema.AnswerInfo, error) {+ answerInfo, has, err := as.answerRepo.GetByID(ctx, answerID)+ if err != nil {+ return nil, err+ }+ if !has {+ return nil, errors.BadRequest(reason.AnswerNotFound)+ }+ info := as.ShowFormat(ctx, answerInfo)+ return info, nil+}+func (as *AnswerService) GetCountByUserIDQuestionID(ctx context.Context, userId string, questionId string) (ids []string, err error) {return as.answerRepo.GetIDsByUserIDAndQuestionID(ctx, userId, questionId)}