MCPcopy Index your code
hub / github.com/apache/answer / UserInfo

Method UserInfo

internal/controller/template_controller.go:513–555  ·  view source on GitHub ↗

UserInfo user info

(ctx *gin.Context)

Source from the content-addressed store, hash-verified

511
512// UserInfo user info
513func (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
557func (tc *TemplateController) Page404(ctx *gin.Context) {
558 tc.html(ctx, http.StatusNotFound, "404.html", tc.SiteInfo(ctx), gin.H{})

Callers

nothing calls this directly

Calls 6

Page404Method · 0.95
SiteInfoMethod · 0.95
htmlMethod · 0.95
IsUsersIgnorePathFunction · 0.92
SearchUserTopListMethod · 0.80
UserInfoMethod · 0.65

Tested by

no test coverage detected