From ce0ec4b806b602518bd8cd2a37ff1aa0834a302c Mon Sep 17 00:00:00 2001 From: LinkinStars Date: Fri, 29 Nov 2024 15:15:23 +0800 Subject: [PATCH] feat(user): add top questions and answers to user homepage --- internal/controller/template_controller.go | 12 ++++++-- ui/template/homepage.html | 33 +++++++++++++++++++++- 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/internal/controller/template_controller.go b/internal/controller/template_controller.go index df10931e..0b22360f 100644 --- a/internal/controller/template_controller.go +++ b/internal/controller/template_controller.go @@ -546,12 +546,20 @@ func (tc *TemplateController) UserInfo(ctx *gin.Context) { return } + questionList, answerList, err := tc.questionService.SearchUserTopList(ctx, req.Username, "") + if err != nil { + tc.Page404(ctx) + return + } + siteInfo := tc.SiteInfo(ctx) siteInfo.Canonical = fmt.Sprintf("%s/users/%s", siteInfo.General.SiteUrl, username) siteInfo.Title = fmt.Sprintf("%s - %s", username, siteInfo.General.Name) tc.html(ctx, http.StatusOK, "homepage.html", siteInfo, gin.H{ - "userinfo": userinfo, - "bio": template.HTML(userinfo.BioHTML), + "userinfo": userinfo, + "bio": template.HTML(userinfo.BioHTML), + "topQuestions": questionList, + "topAnswers": answerList, }) } diff --git a/ui/template/homepage.html b/ui/template/homepage.html index 2f68200d..84887a09 100644 --- a/ui/template/homepage.html +++ b/ui/template/homepage.html @@ -63,10 +63,41 @@
{{translator $.language "ui.personal.about_me"}}
{{if .bio }} -
{{.bio}}
+
{{.bio}}
{{else}}
{{translator $.language "ui.personal.about_me_empty"}}
{{end}} +
+
+
Top Answers
+
    + {{ range .topAnswers }} +
  1. + {{.QuestionInfo.Title}} +
    + {{.VoteCount}} votes +
    +
  2. + {{ end }} +
+
+
+
Top Questions
+
    + {{ range .topQuestions }} +
  1. + {{.Title}} +
    + {{.VoteCount}} votes +
    + {{.AnswerCount}} answers +
    +
    +
  2. + {{ end }} +
+
+