fix(template): incorrectly parsing the question title to the answer id, resulting in the infinite redirect #885
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user