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:
aichy 2022-10-28 09:58:19 +00:00
commit bd78e8e828
6 changed files with 39 additions and 9 deletions

View File

@ -3303,7 +3303,7 @@ const docTemplate = `{
"ApiKeyAuth": [] "ApiKeyAuth": []
} }
], ],
"description": "GetUserInfoByUserID", "description": "get user info, if user no login response http code is 200, but user info is null",
"consumes": [ "consumes": [
"application/json" "application/json"
], ],
@ -5628,6 +5628,14 @@ const docTemplate = `{
"e_mail" "e_mail"
], ],
"properties": { "properties": {
"captcha_code": {
"type": "string",
"maxLength": 500
},
"captcha_id": {
"type": "string",
"maxLength": 500
},
"e_mail": { "e_mail": {
"type": "string", "type": "string",
"maxLength": 500 "maxLength": 500

View File

@ -3291,7 +3291,7 @@
"ApiKeyAuth": [] "ApiKeyAuth": []
} }
], ],
"description": "GetUserInfoByUserID", "description": "get user info, if user no login response http code is 200, but user info is null",
"consumes": [ "consumes": [
"application/json" "application/json"
], ],
@ -5616,6 +5616,14 @@
"e_mail" "e_mail"
], ],
"properties": { "properties": {
"captcha_code": {
"type": "string",
"maxLength": 500
},
"captcha_id": {
"type": "string",
"maxLength": 500
},
"e_mail": { "e_mail": {
"type": "string", "type": "string",
"maxLength": 500 "maxLength": 500

View File

@ -1241,6 +1241,12 @@ definitions:
type: object type: object
schema.UserChangeEmailSendCodeReq: schema.UserChangeEmailSendCodeReq:
properties: properties:
captcha_code:
maxLength: 500
type: string
captcha_id:
maxLength: 500
type: string
e_mail: e_mail:
maxLength: 500 maxLength: 500
type: string type: string
@ -3365,7 +3371,8 @@ paths:
get: get:
consumes: consumes:
- application/json - application/json
description: GetUserInfoByUserID description: get user info, if user no login response http code is 200, but
user info is null
produces: produces:
- application/json - application/json
responses: responses:

View File

@ -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 // @Summary GetUserInfoByUserID
// @Description GetUserInfoByUserID // @Description get user info, if user no login response http code is 200, but user info is null
// @Tags User // @Tags User
// @Accept json // @Accept json
// @Produce json // @Produce json
@ -57,6 +57,13 @@ func NewUserController(
func (uc *UserController) GetUserInfoByUserID(ctx *gin.Context) { func (uc *UserController) GetUserInfoByUserID(ctx *gin.Context) {
userID := middleware.GetLoginUserIDFromContext(ctx) userID := middleware.GetLoginUserIDFromContext(ctx)
token := middleware.ExtractToken(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) resp, err := uc.userService.GetUserInfoByUserID(ctx, token, userID)
handler.HandleResponse(ctx, err, resp) handler.HandleResponse(ctx, err, resp)
} }

View File

@ -87,6 +87,7 @@ func (a *AnswerAPIRouter) RegisterUnAuthAnswerAPIRouter(r *gin.RouterGroup) {
r.GET("/comment", a.commentController.GetComment) r.GET("/comment", a.commentController.GetComment)
// user // user
r.GET("/user/info", a.userController.GetUserInfoByUserID)
r.GET("/user/status", a.userController.GetUserStatus) r.GET("/user/status", a.userController.GetUserStatus)
r.GET("/user/action/record", a.userController.ActionRecord) r.GET("/user/action/record", a.userController.ActionRecord)
r.POST("/user/login/email", a.userController.UserEmailLogin) 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) r.DELETE("/answer", a.answerController.RemoveAnswer)
// user // user
r.GET("/user/info", a.userController.GetUserInfoByUserID)
r.PUT("/user/password", a.userController.UserModifyPassWord) r.PUT("/user/password", a.userController.UserModifyPassWord)
r.PUT("/user/info", a.userController.UserUpdateInfo) r.PUT("/user/info", a.userController.UserUpdateInfo)
r.POST("/user/avatar/upload", a.userController.UploadUserAvatar) r.POST("/user/avatar/upload", a.userController.UploadUserAvatar)

View File

@ -95,12 +95,12 @@ func (r *GetUserToSetShowResp) GetFromUserEntity(userInfo *entity.User) {
if ok { if ok {
r.Status = statusShow r.Status = statusShow
} }
AvatarInfo := &AvatarInfo{} avatarInfo := &AvatarInfo{}
err := json.Unmarshal([]byte(userInfo.Avatar), AvatarInfo) err := json.Unmarshal([]byte(userInfo.Avatar), avatarInfo)
if err != nil { if err != nil {
log.Error("AvatarInfo json.Unmarshal Error", err) log.Error("AvatarInfo json.Unmarshal Error", err)
} }
r.Avatar = AvatarInfo r.Avatar = avatarInfo
} }
func (us *GetUserResp) AvatarInfo(avatarJson string) string { func (us *GetUserResp) AvatarInfo(avatarJson string) string {