Skip to content

Commit

Permalink
fix(template): incorrectly parsing the question title to the answer i…
Browse files Browse the repository at this point in the history
…d, resulting in the infinite redirect #885
  • Loading branch information
LinkinStars committed Apr 7, 2024
1 parent 3bec091 commit 58dd97a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions internal/controller/template_controller.go
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions internal/controller/template_render/answer.go
Expand Up @@ -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)
}
12 changes: 12 additions & 0 deletions internal/service/content/answer_service.go
Expand Up @@ -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)
}
Expand Down

0 comments on commit 58dd97a

Please sign in to comment.