UserInfo user info
(ctx *gin.Context)
| 511 | |
| 512 | // UserInfo user info |
| 513 | func (tc *TemplateController) UserInfo(ctx *gin.Context) { |
| 514 | username := ctx.Param("username") |
| 515 | if username == "" { |
| 516 | tc.Page404(ctx) |
| 517 | return |
| 518 | } |
| 519 | |
| 520 | exist := checker.IsUsersIgnorePath(username) |
| 521 | if exist { |
| 522 | file, err := ui.Build.ReadFile("build/index.html") |
| 523 | if err != nil { |
| 524 | log.Error(err) |
| 525 | tc.Page404(ctx) |
| 526 | return |
| 527 | } |
| 528 | ctx.Header("content-type", "text/html;charset=utf-8") |
| 529 | ctx.String(http.StatusOK, string(file)) |
| 530 | return |
| 531 | } |
| 532 | req := &schema.GetOtherUserInfoByUsernameReq{} |
| 533 | req.Username = username |
| 534 | userinfo, err := tc.templateRenderController.UserInfo(ctx, req) |
| 535 | if err != nil { |
| 536 | tc.Page404(ctx) |
| 537 | return |
| 538 | } |
| 539 | |
| 540 | questionList, answerList, err := tc.questionService.SearchUserTopList(ctx, req.Username, "") |
| 541 | if err != nil { |
| 542 | tc.Page404(ctx) |
| 543 | return |
| 544 | } |
| 545 | |
| 546 | siteInfo := tc.SiteInfo(ctx) |
| 547 | siteInfo.Canonical = fmt.Sprintf("%s/users/%s", siteInfo.General.SiteUrl, username) |
| 548 | siteInfo.Title = fmt.Sprintf("%s - %s", username, siteInfo.General.Name) |
| 549 | tc.html(ctx, http.StatusOK, "homepage.html", siteInfo, gin.H{ |
| 550 | "userinfo": userinfo, |
| 551 | "bio": template.HTML(userinfo.BioHTML), |
| 552 | "topQuestions": questionList, |
| 553 | "topAnswers": answerList, |
| 554 | }) |
| 555 | } |
| 556 | |
| 557 | func (tc *TemplateController) Page404(ctx *gin.Context) { |
| 558 | tc.html(ctx, http.StatusNotFound, "404.html", tc.SiteInfo(ctx), gin.H{}) |
nothing calls this directly
no test coverage detected