mirror of https://gitee.com/answerdev/answer.git
feat(object): return 404 page when user, tag and question not found.
This commit is contained in:
parent
66510fcc29
commit
7ec0272a72
|
@ -404,22 +404,17 @@ func (tc *TemplateController) UserInfo(ctx *gin.Context) {
|
||||||
req := &schema.GetOtherUserInfoByUsernameReq{}
|
req := &schema.GetOtherUserInfoByUsernameReq{}
|
||||||
req.Username = username
|
req.Username = username
|
||||||
userinfo, err := tc.templateRenderController.UserInfo(ctx, req)
|
userinfo, err := tc.templateRenderController.UserInfo(ctx, req)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tc.Page404(ctx)
|
tc.Page404(ctx)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !userinfo.Has {
|
|
||||||
tc.Page404(ctx)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
siteInfo := tc.SiteInfo(ctx)
|
siteInfo := tc.SiteInfo(ctx)
|
||||||
siteInfo.Canonical = fmt.Sprintf("%s/users/%s", siteInfo.General.SiteUrl, username)
|
siteInfo.Canonical = fmt.Sprintf("%s/users/%s", siteInfo.General.SiteUrl, username)
|
||||||
siteInfo.Title = fmt.Sprintf("%s - %s", username, siteInfo.General.Name)
|
siteInfo.Title = fmt.Sprintf("%s - %s", username, siteInfo.General.Name)
|
||||||
tc.html(ctx, http.StatusOK, "homepage.html", siteInfo, gin.H{
|
tc.html(ctx, http.StatusOK, "homepage.html", siteInfo, gin.H{
|
||||||
"userinfo": userinfo,
|
"userinfo": userinfo,
|
||||||
"bio": template.HTML(userinfo.Info.BioHTML),
|
"bio": template.HTML(userinfo.BioHTML),
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,6 @@ import (
|
||||||
"golang.org/x/net/context"
|
"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)
|
return q.userService.GetOtherUserInfoByUsername(ctx, req.Username)
|
||||||
}
|
}
|
||||||
|
|
|
@ -386,7 +386,6 @@ type GetOtherUserInfoByUsernameReq struct {
|
||||||
|
|
||||||
type GetOtherUserInfoResp struct {
|
type GetOtherUserInfoResp struct {
|
||||||
Info *GetOtherUserInfoByUsernameResp `json:"info"`
|
Info *GetOtherUserInfoByUsernameResp `json:"info"`
|
||||||
Has bool `json:"has"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type UserChangeEmailSendCodeReq struct {
|
type UserChangeEmailSendCodeReq struct {
|
||||||
|
|
|
@ -148,7 +148,7 @@ func (qs *QuestionCommon) Info(ctx context.Context, questionID string, loginUser
|
||||||
return showinfo, err
|
return showinfo, err
|
||||||
}
|
}
|
||||||
if !has {
|
if !has {
|
||||||
return showinfo, errors.BadRequest(reason.QuestionNotFound)
|
return showinfo, errors.NotFound(reason.QuestionNotFound)
|
||||||
}
|
}
|
||||||
showinfo = qs.ShowFormat(ctx, dbinfo)
|
showinfo = qs.ShowFormat(ctx, dbinfo)
|
||||||
|
|
||||||
|
|
|
@ -102,7 +102,7 @@ func (ts *TagService) GetTagInfo(ctx context.Context, req *schema.GetTagInfoReq)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if !exist {
|
if !exist {
|
||||||
return nil, errors.BadRequest(reason.TagNotFound)
|
return nil, errors.NotFound(reason.TagNotFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
resp = &schema.GetTagResp{}
|
resp = &schema.GetTagResp{}
|
||||||
|
@ -113,7 +113,7 @@ func (ts *TagService) GetTagInfo(ctx context.Context, req *schema.GetTagInfoReq)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if !exist {
|
if !exist {
|
||||||
return nil, errors.BadRequest(reason.TagNotFound)
|
return nil, errors.NotFound(reason.TagNotFound)
|
||||||
}
|
}
|
||||||
resp.MainTagSlugName = tagInfo.SlugName
|
resp.MainTagSlugName = tagInfo.SlugName
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,19 +86,17 @@ func (us *UserService) GetUserInfoByUserID(ctx context.Context, token, userID st
|
||||||
}
|
}
|
||||||
|
|
||||||
func (us *UserService) GetOtherUserInfoByUsername(ctx context.Context, username string) (
|
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)
|
userInfo, exist, err := us.userRepo.GetByUsername(ctx, username)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
resp = &schema.GetOtherUserInfoResp{}
|
|
||||||
if !exist {
|
if !exist {
|
||||||
return resp, nil
|
return nil, errors.NotFound(reason.UserNotFound)
|
||||||
}
|
}
|
||||||
resp.Has = true
|
resp = &schema.GetOtherUserInfoByUsernameResp{}
|
||||||
resp.Info = &schema.GetOtherUserInfoByUsernameResp{}
|
resp.GetFromUserEntity(userInfo)
|
||||||
resp.Info.GetFromUserEntity(userInfo)
|
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,28 +3,28 @@
|
||||||
<div class="justify-content-center row">
|
<div class="justify-content-center row">
|
||||||
<div class="col-xxl-7 col-lg-8 col-sm-12">
|
<div class="col-xxl-7 col-lg-8 col-sm-12">
|
||||||
<div class="d-flex flex-column flex-md-row mb-4">
|
<div class="d-flex flex-column flex-md-row mb-4">
|
||||||
<a href="/users/{{.userinfo.Info.Username}}"><img
|
<a href="/users/{{.userinfo.Username}}"><img
|
||||||
src="{{.userinfo.Info.Avatar}}"
|
src="{{.userinfo.Avatar}}"
|
||||||
width="160px" height="160px" class="rounded" alt="" /></a>
|
width="160px" height="160px" class="rounded" alt="" /></a>
|
||||||
<div class="ms-0 ms-md-4 mt-4 mt-md-0">
|
<div class="ms-0 ms-md-4 mt-4 mt-md-0">
|
||||||
<div class="d-flex align-items-center mb-2">
|
<div class="d-flex align-items-center mb-2">
|
||||||
<a class="link-dark h3 mb-0" href="/users/{{.userinfo.Info.Username}}">{{.userinfo.Info.DisplayName}}</a>
|
<a class="link-dark h3 mb-0" href="/users/{{.userinfo.Username}}">{{.userinfo.DisplayName}}</a>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div class="text-secondary mb-4">@{{.userinfo.Info.Username}}</div>
|
<div class="text-secondary mb-4">@{{.userinfo.Username}}</div>
|
||||||
<div class="d-flex flex-wrap mb-3">
|
<div class="d-flex flex-wrap mb-3">
|
||||||
<div class="me-3">
|
<div class="me-3">
|
||||||
<strong class="fs-5">{{.userinfo.Info.Rank}}</strong><span class="text-secondary"> {{translator $.language "ui.personal.x_reputation"}}</span>
|
<strong class="fs-5">{{.userinfo.Rank}}</strong><span class="text-secondary"> {{translator $.language "ui.personal.x_reputation"}}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="me-3">
|
<div class="me-3">
|
||||||
<strong class="fs-5">{{.userinfo.Info.AnswerCount}}</strong><span class="text-secondary"> {{translator $.language "ui.personal.x_answers"}}</span>
|
<strong class="fs-5">{{.userinfo.AnswerCount}}</strong><span class="text-secondary"> {{translator $.language "ui.personal.x_answers"}}</span>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<strong class="fs-5">{{.userinfo.Info.QuestionCount}}</strong><span class="text-secondary"> {{translator $.language "ui.personal.x_questions"}}</span>
|
<strong class="fs-5">{{.userinfo.QuestionCount}}</strong><span class="text-secondary"> {{translator $.language "ui.personal.x_questions"}}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{if .userinfo.Info.Website }}
|
{{if .userinfo.Website }}
|
||||||
<div class="d-flex align-items-center"><i class="br bi-house-door-fill me-2"></i><a class="link-secondary" href="{{.userinfo.Info.Website}}">{{.userinfo.Info.Website}}</a></div>
|
<div class="d-flex align-items-center"><i class="br bi-house-door-fill me-2"></i><a class="link-secondary" href="{{.userinfo.Website}}">{{.userinfo.Website}}</a></div>
|
||||||
{{else}}
|
{{else}}
|
||||||
{{end}}
|
{{end}}
|
||||||
<div class="d-flex text-secondary"></div>
|
<div class="d-flex text-secondary"></div>
|
||||||
|
|
Loading…
Reference in New Issue