mirror of https://gitee.com/answerdev/answer.git
Merge branch 'feat/user-info' into 'main'
feat: user info api allow no login user use and return empty data See merge request opensource/answer!128
This commit is contained in:
commit
bd78e8e828
10
docs/docs.go
10
docs/docs.go
|
@ -3303,7 +3303,7 @@ const docTemplate = `{
|
|||
"ApiKeyAuth": []
|
||||
}
|
||||
],
|
||||
"description": "GetUserInfoByUserID",
|
||||
"description": "get user info, if user no login response http code is 200, but user info is null",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
|
@ -5628,6 +5628,14 @@ const docTemplate = `{
|
|||
"e_mail"
|
||||
],
|
||||
"properties": {
|
||||
"captcha_code": {
|
||||
"type": "string",
|
||||
"maxLength": 500
|
||||
},
|
||||
"captcha_id": {
|
||||
"type": "string",
|
||||
"maxLength": 500
|
||||
},
|
||||
"e_mail": {
|
||||
"type": "string",
|
||||
"maxLength": 500
|
||||
|
|
|
@ -3291,7 +3291,7 @@
|
|||
"ApiKeyAuth": []
|
||||
}
|
||||
],
|
||||
"description": "GetUserInfoByUserID",
|
||||
"description": "get user info, if user no login response http code is 200, but user info is null",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
|
@ -5616,6 +5616,14 @@
|
|||
"e_mail"
|
||||
],
|
||||
"properties": {
|
||||
"captcha_code": {
|
||||
"type": "string",
|
||||
"maxLength": 500
|
||||
},
|
||||
"captcha_id": {
|
||||
"type": "string",
|
||||
"maxLength": 500
|
||||
},
|
||||
"e_mail": {
|
||||
"type": "string",
|
||||
"maxLength": 500
|
||||
|
|
|
@ -1241,6 +1241,12 @@ definitions:
|
|||
type: object
|
||||
schema.UserChangeEmailSendCodeReq:
|
||||
properties:
|
||||
captcha_code:
|
||||
maxLength: 500
|
||||
type: string
|
||||
captcha_id:
|
||||
maxLength: 500
|
||||
type: string
|
||||
e_mail:
|
||||
maxLength: 500
|
||||
type: string
|
||||
|
@ -3365,7 +3371,8 @@ paths:
|
|||
get:
|
||||
consumes:
|
||||
- application/json
|
||||
description: GetUserInfoByUserID
|
||||
description: get user info, if user no login response http code is 200, but
|
||||
user info is null
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
|
|
|
@ -45,9 +45,9 @@ func NewUserController(
|
|||
}
|
||||
}
|
||||
|
||||
// GetUserInfoByUserID godoc
|
||||
// GetUserInfoByUserID get user info, if user no login response http code is 200, but user info is null
|
||||
// @Summary GetUserInfoByUserID
|
||||
// @Description GetUserInfoByUserID
|
||||
// @Description get user info, if user no login response http code is 200, but user info is null
|
||||
// @Tags User
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
|
@ -57,6 +57,13 @@ func NewUserController(
|
|||
func (uc *UserController) GetUserInfoByUserID(ctx *gin.Context) {
|
||||
userID := middleware.GetLoginUserIDFromContext(ctx)
|
||||
token := middleware.ExtractToken(ctx)
|
||||
|
||||
// if user is no login return null in data
|
||||
if len(token) == 0 || len(userID) == 0 {
|
||||
handler.HandleResponse(ctx, nil, nil)
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := uc.userService.GetUserInfoByUserID(ctx, token, userID)
|
||||
handler.HandleResponse(ctx, err, resp)
|
||||
}
|
||||
|
|
|
@ -87,6 +87,7 @@ func (a *AnswerAPIRouter) RegisterUnAuthAnswerAPIRouter(r *gin.RouterGroup) {
|
|||
r.GET("/comment", a.commentController.GetComment)
|
||||
|
||||
// user
|
||||
r.GET("/user/info", a.userController.GetUserInfoByUserID)
|
||||
r.GET("/user/status", a.userController.GetUserStatus)
|
||||
r.GET("/user/action/record", a.userController.ActionRecord)
|
||||
r.POST("/user/login/email", a.userController.UserEmailLogin)
|
||||
|
@ -174,7 +175,6 @@ func (a *AnswerAPIRouter) RegisterAnswerAPIRouter(r *gin.RouterGroup) {
|
|||
r.DELETE("/answer", a.answerController.RemoveAnswer)
|
||||
|
||||
// user
|
||||
r.GET("/user/info", a.userController.GetUserInfoByUserID)
|
||||
r.PUT("/user/password", a.userController.UserModifyPassWord)
|
||||
r.PUT("/user/info", a.userController.UserUpdateInfo)
|
||||
r.POST("/user/avatar/upload", a.userController.UploadUserAvatar)
|
||||
|
|
|
@ -95,12 +95,12 @@ func (r *GetUserToSetShowResp) GetFromUserEntity(userInfo *entity.User) {
|
|||
if ok {
|
||||
r.Status = statusShow
|
||||
}
|
||||
AvatarInfo := &AvatarInfo{}
|
||||
err := json.Unmarshal([]byte(userInfo.Avatar), AvatarInfo)
|
||||
avatarInfo := &AvatarInfo{}
|
||||
err := json.Unmarshal([]byte(userInfo.Avatar), avatarInfo)
|
||||
if err != nil {
|
||||
log.Error("AvatarInfo json.Unmarshal Error", err)
|
||||
}
|
||||
r.Avatar = AvatarInfo
|
||||
r.Avatar = avatarInfo
|
||||
}
|
||||
|
||||
func (us *GetUserResp) AvatarInfo(avatarJson string) string {
|
||||
|
|
Loading…
Reference in New Issue