QuestionInfo question and answers info
(ctx *gin.Context)
| 296 | |
| 297 | // QuestionInfo question and answers info |
| 298 | func (tc *TemplateController) QuestionInfo(ctx *gin.Context) { |
| 299 | id := ctx.Param("id") |
| 300 | title := ctx.Param("title") |
| 301 | answerid := ctx.Param("answerid") |
| 302 | shareUsername := ctx.Query("share") |
| 303 | if checker.IsQuestionsIgnorePath(id) { |
| 304 | // if id == "ask" { |
| 305 | file, err := ui.Build.ReadFile("build/index.html") |
| 306 | if err != nil { |
| 307 | log.Error(err) |
| 308 | tc.Page404(ctx) |
| 309 | return |
| 310 | } |
| 311 | ctx.Header("content-type", "text/html;charset=utf-8") |
| 312 | ctx.String(http.StatusOK, string(file)) |
| 313 | return |
| 314 | } |
| 315 | |
| 316 | correctTitle := false |
| 317 | |
| 318 | detail, err := tc.templateRenderController.QuestionDetail(ctx, id) |
| 319 | if err != nil { |
| 320 | tc.Page404(ctx) |
| 321 | return |
| 322 | } |
| 323 | if len(shareUsername) > 0 { |
| 324 | userInfo, err := tc.userService.GetOtherUserInfoByUsername( |
| 325 | ctx, &schema.GetOtherUserInfoByUsernameReq{Username: shareUsername}) |
| 326 | if err == nil { |
| 327 | tc.eventQueueService.Send(ctx, schema.NewEvent(constant.EventUserShare, userInfo.ID). |
| 328 | QID(id, detail.UserID).AID(answerid, "")) |
| 329 | } |
| 330 | } |
| 331 | encodeTitle := htmltext.UrlTitle(detail.Title) |
| 332 | if encodeTitle == title { |
| 333 | correctTitle = true |
| 334 | } |
| 335 | |
| 336 | siteInfo := tc.SiteInfo(ctx) |
| 337 | jump, jumpurl := tc.QuestionInfoRedirect(ctx, siteInfo, correctTitle) |
| 338 | if jump { |
| 339 | ctx.Redirect(http.StatusFound, jumpurl) |
| 340 | return |
| 341 | } |
| 342 | |
| 343 | // answers |
| 344 | answerReq := &schema.AnswerListReq{ |
| 345 | QuestionID: id, |
| 346 | Order: "", |
| 347 | Page: 1, |
| 348 | PageSize: 999, |
| 349 | UserID: "", |
| 350 | } |
| 351 | answers, answerCount, err := tc.templateRenderController.AnswerList(ctx, answerReq) |
| 352 | if err != nil { |
| 353 | tc.Page404(ctx) |
| 354 | return |
| 355 | } |
nothing calls this directly
no test coverage detected