mirror of https://gitee.com/answerdev/answer.git
user avatar save
This commit is contained in:
parent
f7df1d3dfd
commit
90deaf027b
20
docs/docs.go
20
docs/docs.go
|
@ -4108,6 +4108,23 @@ const docTemplate = `{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"schema.AvatarInfo": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"custom": {
|
||||||
|
"type": "string",
|
||||||
|
"maxLength": 200
|
||||||
|
},
|
||||||
|
"gravatar": {
|
||||||
|
"type": "string",
|
||||||
|
"maxLength": 200
|
||||||
|
},
|
||||||
|
"type": {
|
||||||
|
"type": "string",
|
||||||
|
"maxLength": 100
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"schema.CloseQuestionReq": {
|
"schema.CloseQuestionReq": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"required": [
|
"required": [
|
||||||
|
@ -5318,8 +5335,7 @@ const docTemplate = `{
|
||||||
"properties": {
|
"properties": {
|
||||||
"avatar": {
|
"avatar": {
|
||||||
"description": "avatar",
|
"description": "avatar",
|
||||||
"type": "string",
|
"$ref": "#/definitions/schema.AvatarInfo"
|
||||||
"maxLength": 500
|
|
||||||
},
|
},
|
||||||
"bio": {
|
"bio": {
|
||||||
"description": "bio",
|
"description": "bio",
|
||||||
|
|
|
@ -4096,6 +4096,23 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"schema.AvatarInfo": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"custom": {
|
||||||
|
"type": "string",
|
||||||
|
"maxLength": 200
|
||||||
|
},
|
||||||
|
"gravatar": {
|
||||||
|
"type": "string",
|
||||||
|
"maxLength": 200
|
||||||
|
},
|
||||||
|
"type": {
|
||||||
|
"type": "string",
|
||||||
|
"maxLength": 100
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"schema.CloseQuestionReq": {
|
"schema.CloseQuestionReq": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"required": [
|
"required": [
|
||||||
|
@ -5306,8 +5323,7 @@
|
||||||
"properties": {
|
"properties": {
|
||||||
"avatar": {
|
"avatar": {
|
||||||
"description": "avatar",
|
"description": "avatar",
|
||||||
"type": "string",
|
"$ref": "#/definitions/schema.AvatarInfo"
|
||||||
"maxLength": 500
|
|
||||||
},
|
},
|
||||||
"bio": {
|
"bio": {
|
||||||
"description": "bio",
|
"description": "bio",
|
||||||
|
|
|
@ -139,6 +139,18 @@ definitions:
|
||||||
description: title
|
description: title
|
||||||
type: string
|
type: string
|
||||||
type: object
|
type: object
|
||||||
|
schema.AvatarInfo:
|
||||||
|
properties:
|
||||||
|
custom:
|
||||||
|
maxLength: 200
|
||||||
|
type: string
|
||||||
|
gravatar:
|
||||||
|
maxLength: 200
|
||||||
|
type: string
|
||||||
|
type:
|
||||||
|
maxLength: 100
|
||||||
|
type: string
|
||||||
|
type: object
|
||||||
schema.CloseQuestionReq:
|
schema.CloseQuestionReq:
|
||||||
properties:
|
properties:
|
||||||
close_msg:
|
close_msg:
|
||||||
|
@ -1013,9 +1025,8 @@ definitions:
|
||||||
schema.UpdateInfoRequest:
|
schema.UpdateInfoRequest:
|
||||||
properties:
|
properties:
|
||||||
avatar:
|
avatar:
|
||||||
|
$ref: '#/definitions/schema.AvatarInfo'
|
||||||
description: avatar
|
description: avatar
|
||||||
maxLength: 500
|
|
||||||
type: string
|
|
||||||
bio:
|
bio:
|
||||||
description: bio
|
description: bio
|
||||||
maxLength: 4096
|
maxLength: 4096
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"github.com/answerdev/answer/pkg/checker"
|
"github.com/answerdev/answer/pkg/checker"
|
||||||
"github.com/jinzhu/copier"
|
"github.com/jinzhu/copier"
|
||||||
"github.com/segmentfault/pacman/errors"
|
"github.com/segmentfault/pacman/errors"
|
||||||
|
"github.com/segmentfault/pacman/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
// UserVerifyEmailReq user verify email request
|
// UserVerifyEmailReq user verify email request
|
||||||
|
@ -72,6 +73,7 @@ type GetUserResp struct {
|
||||||
|
|
||||||
func (r *GetUserResp) GetFromUserEntity(userInfo *entity.User) {
|
func (r *GetUserResp) GetFromUserEntity(userInfo *entity.User) {
|
||||||
_ = copier.Copy(r, userInfo)
|
_ = copier.Copy(r, userInfo)
|
||||||
|
r.Avatar = r.AvatarInfo(userInfo.Avatar)
|
||||||
r.CreatedAt = userInfo.CreatedAt.Unix()
|
r.CreatedAt = userInfo.CreatedAt.Unix()
|
||||||
r.LastLoginDate = userInfo.LastLoginDate.Unix()
|
r.LastLoginDate = userInfo.LastLoginDate.Unix()
|
||||||
statusShow, ok := UserStatusShow[userInfo.Status]
|
statusShow, ok := UserStatusShow[userInfo.Status]
|
||||||
|
@ -80,6 +82,26 @@ func (r *GetUserResp) GetFromUserEntity(userInfo *entity.User) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (us *GetUserResp) AvatarInfo(AvatarJson string) string {
|
||||||
|
if AvatarJson == "" {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
AvatarInfo := &AvatarInfo{}
|
||||||
|
err := json.Unmarshal([]byte(AvatarJson), AvatarInfo)
|
||||||
|
if err != nil {
|
||||||
|
log.Error("AvatarInfo json.Unmarshal Error", err)
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
switch AvatarInfo.Type {
|
||||||
|
case "gravatar":
|
||||||
|
return AvatarInfo.Gravatar
|
||||||
|
case "custom":
|
||||||
|
return AvatarInfo.Custom
|
||||||
|
default:
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// GetUserStatusResp get user status info
|
// GetUserStatusResp get user status info
|
||||||
type GetUserStatusResp struct {
|
type GetUserStatusResp struct {
|
||||||
// user status
|
// user status
|
||||||
|
@ -230,7 +252,7 @@ type UpdateInfoRequest struct {
|
||||||
// username
|
// username
|
||||||
Username string `validate:"omitempty,gt=0,lte=30" json:"username"`
|
Username string `validate:"omitempty,gt=0,lte=30" json:"username"`
|
||||||
// avatar
|
// avatar
|
||||||
Avatar string `validate:"omitempty,gt=0,lte=500" json:"avatar"`
|
Avatar AvatarInfo `json:"avatar"`
|
||||||
// bio
|
// bio
|
||||||
Bio string `validate:"omitempty,gt=0,lte=4096" json:"bio"`
|
Bio string `validate:"omitempty,gt=0,lte=4096" json:"bio"`
|
||||||
// bio
|
// bio
|
||||||
|
@ -243,6 +265,12 @@ type UpdateInfoRequest struct {
|
||||||
UserId string `json:"-" `
|
UserId string `json:"-" `
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type AvatarInfo struct {
|
||||||
|
Type string `validate:"omitempty,gt=0,lte=100" json:"type"`
|
||||||
|
Gravatar string `validate:"omitempty,gt=0,lte=200" json:"gravatar"`
|
||||||
|
Custom string `validate:"omitempty,gt=0,lte=200" json:"custom"`
|
||||||
|
}
|
||||||
|
|
||||||
func (u *UpdateInfoRequest) Check() (errField *validator.ErrorField, err error) {
|
func (u *UpdateInfoRequest) Check() (errField *validator.ErrorField, err error) {
|
||||||
if len(u.Username) > 0 {
|
if len(u.Username) > 0 {
|
||||||
re := regexp.MustCompile(`^[a-z0-9._-]{4,30}$`)
|
re := regexp.MustCompile(`^[a-z0-9._-]{4,30}$`)
|
||||||
|
|
|
@ -76,11 +76,13 @@ func (us *UserCommon) BatchUserBasicInfoByID(ctx context.Context, IDs []string)
|
||||||
// UserBasicInfoFormat
|
// UserBasicInfoFormat
|
||||||
func (us *UserCommon) UserBasicInfoFormat(ctx context.Context, userInfo *entity.User) *schema.UserBasicInfo {
|
func (us *UserCommon) UserBasicInfoFormat(ctx context.Context, userInfo *entity.User) *schema.UserBasicInfo {
|
||||||
userBasicInfo := &schema.UserBasicInfo{}
|
userBasicInfo := &schema.UserBasicInfo{}
|
||||||
|
uinfo := &schema.GetUserResp{}
|
||||||
|
uinfo.AvatarInfo(userInfo.Avatar)
|
||||||
userBasicInfo.ID = userInfo.ID
|
userBasicInfo.ID = userInfo.ID
|
||||||
userBasicInfo.Username = userInfo.Username
|
userBasicInfo.Username = userInfo.Username
|
||||||
userBasicInfo.Rank = userInfo.Rank
|
userBasicInfo.Rank = userInfo.Rank
|
||||||
userBasicInfo.DisplayName = userInfo.DisplayName
|
userBasicInfo.DisplayName = userInfo.DisplayName
|
||||||
userBasicInfo.Avatar = userInfo.Avatar
|
userBasicInfo.Avatar = uinfo.Avatar
|
||||||
userBasicInfo.Website = userInfo.Website
|
userBasicInfo.Website = userInfo.Website
|
||||||
userBasicInfo.Location = userInfo.Location
|
userBasicInfo.Location = userInfo.Location
|
||||||
userBasicInfo.IpInfo = userInfo.IPInfo
|
userBasicInfo.IpInfo = userInfo.IPInfo
|
||||||
|
|
|
@ -3,6 +3,7 @@ package service
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
@ -255,10 +256,13 @@ func (us *UserService) UpdateInfo(ctx context.Context, req *schema.UpdateInfoReq
|
||||||
return errors.BadRequest(reason.UsernameDuplicate)
|
return errors.BadRequest(reason.UsernameDuplicate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Avatar, err := json.Marshal(req.Avatar)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
userInfo := entity.User{}
|
userInfo := entity.User{}
|
||||||
userInfo.ID = req.UserId
|
userInfo.ID = req.UserId
|
||||||
userInfo.Avatar = req.Avatar
|
userInfo.Avatar = string(Avatar)
|
||||||
userInfo.DisplayName = req.DisplayName
|
userInfo.DisplayName = req.DisplayName
|
||||||
userInfo.Bio = req.Bio
|
userInfo.Bio = req.Bio
|
||||||
userInfo.BioHtml = req.BioHtml
|
userInfo.BioHtml = req.BioHtml
|
||||||
|
|
Loading…
Reference in New Issue