diff --git a/internal/controller/template_controller.go b/internal/controller/template_controller.go index 894b4930..5922bff4 100644 --- a/internal/controller/template_controller.go +++ b/internal/controller/template_controller.go @@ -404,22 +404,17 @@ func (tc *TemplateController) UserInfo(ctx *gin.Context) { req := &schema.GetOtherUserInfoByUsernameReq{} req.Username = username userinfo, err := tc.templateRenderController.UserInfo(ctx, req) - if err != nil { tc.Page404(ctx) return } - if !userinfo.Has { - 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.Info.BioHTML), + "bio": template.HTML(userinfo.BioHTML), }) } diff --git a/internal/controller/template_render/userinfo.go b/internal/controller/template_render/userinfo.go index e10e2dfa..2186fac5 100644 --- a/internal/controller/template_render/userinfo.go +++ b/internal/controller/template_render/userinfo.go @@ -5,6 +5,6 @@ import ( "golang.org/x/net/context" ) -func (q *TemplateRenderController) UserInfo(ctx context.Context, req *schema.GetOtherUserInfoByUsernameReq) (resp *schema.GetOtherUserInfoResp, err error) { +func (q *TemplateRenderController) UserInfo(ctx context.Context, req *schema.GetOtherUserInfoByUsernameReq) (resp *schema.GetOtherUserInfoByUsernameResp, err error) { return q.userService.GetOtherUserInfoByUsername(ctx, req.Username) } diff --git a/internal/schema/user_schema.go b/internal/schema/user_schema.go index 308568c8..40b160d1 100644 --- a/internal/schema/user_schema.go +++ b/internal/schema/user_schema.go @@ -386,7 +386,6 @@ type GetOtherUserInfoByUsernameReq struct { type GetOtherUserInfoResp struct { Info *GetOtherUserInfoByUsernameResp `json:"info"` - Has bool `json:"has"` } type UserChangeEmailSendCodeReq struct { diff --git a/internal/service/question_common/question.go b/internal/service/question_common/question.go index 23424d2c..b37e9099 100644 --- a/internal/service/question_common/question.go +++ b/internal/service/question_common/question.go @@ -148,7 +148,7 @@ func (qs *QuestionCommon) Info(ctx context.Context, questionID string, loginUser return showinfo, err } if !has { - return showinfo, errors.BadRequest(reason.QuestionNotFound) + return showinfo, errors.NotFound(reason.QuestionNotFound) } showinfo = qs.ShowFormat(ctx, dbinfo) diff --git a/internal/service/tag/tag_service.go b/internal/service/tag/tag_service.go index 1fb118ec..db28ef09 100644 --- a/internal/service/tag/tag_service.go +++ b/internal/service/tag/tag_service.go @@ -102,7 +102,7 @@ func (ts *TagService) GetTagInfo(ctx context.Context, req *schema.GetTagInfoReq) return nil, err } if !exist { - return nil, errors.BadRequest(reason.TagNotFound) + return nil, errors.NotFound(reason.TagNotFound) } resp = &schema.GetTagResp{} @@ -113,7 +113,7 @@ func (ts *TagService) GetTagInfo(ctx context.Context, req *schema.GetTagInfoReq) return nil, err } if !exist { - return nil, errors.BadRequest(reason.TagNotFound) + return nil, errors.NotFound(reason.TagNotFound) } resp.MainTagSlugName = tagInfo.SlugName } diff --git a/internal/service/user_service.go b/internal/service/user_service.go index e7bd4374..6ca26620 100644 --- a/internal/service/user_service.go +++ b/internal/service/user_service.go @@ -86,19 +86,17 @@ func (us *UserService) GetUserInfoByUserID(ctx context.Context, token, userID st } func (us *UserService) GetOtherUserInfoByUsername(ctx context.Context, username string) ( - resp *schema.GetOtherUserInfoResp, err error, + resp *schema.GetOtherUserInfoByUsernameResp, err error, ) { userInfo, exist, err := us.userRepo.GetByUsername(ctx, username) if err != nil { return nil, err } - resp = &schema.GetOtherUserInfoResp{} if !exist { - return resp, nil + return nil, errors.NotFound(reason.UserNotFound) } - resp.Has = true - resp.Info = &schema.GetOtherUserInfoByUsernameResp{} - resp.Info.GetFromUserEntity(userInfo) + resp = &schema.GetOtherUserInfoByUsernameResp{} + resp.GetFromUserEntity(userInfo) return resp, nil } diff --git a/ui/template/homepage.html b/ui/template/homepage.html index 2c82f20b..0f9c2a92 100644 --- a/ui/template/homepage.html +++ b/ui/template/homepage.html @@ -3,28 +3,28 @@
-
-
@{{.userinfo.Info.Username}}
+
@{{.userinfo.Username}}
- {{.userinfo.Info.Rank}} {{translator $.language "ui.personal.x_reputation"}} + {{.userinfo.Rank}} {{translator $.language "ui.personal.x_reputation"}}
- {{.userinfo.Info.AnswerCount}} {{translator $.language "ui.personal.x_answers"}} + {{.userinfo.AnswerCount}} {{translator $.language "ui.personal.x_answers"}}
- {{.userinfo.Info.QuestionCount}} {{translator $.language "ui.personal.x_questions"}} + {{.userinfo.QuestionCount}} {{translator $.language "ui.personal.x_questions"}}
- {{if .userinfo.Info.Website }} - + {{if .userinfo.Website }} + {{else}} {{end}}