Skip to content

A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.

update userinfo show user set avatar

aichy1265ecac4dda3ef
diff --git a/internal/schema/user_schema.go b/internal/schema/user_schema.go
index 951e18b1..db1e42f6 100644
--- a/internal/schema/user_schema.go
+++ b/internal/schema/user_schema.go
@@ -82,6 +82,27 @@ func (r *GetUserResp) GetFromUserEntity(userInfo *entity.User) {
}
}
+type GetUserToSetShowResp struct {
+ *GetUserResp
+ Avatar *AvatarInfo `json:"avatar"`
+}
+
+func (r *GetUserToSetShowResp) GetFromUserEntity(userInfo *entity.User) {
+ _ = copier.Copy(r, userInfo)
+ r.CreatedAt = userInfo.CreatedAt.Unix()
+ r.LastLoginDate = userInfo.LastLoginDate.Unix()
+ statusShow, ok := UserStatusShow[userInfo.Status]
+ if ok {
+ r.Status = statusShow
+ }
+ AvatarInfo := &AvatarInfo{}
+ err := json.Unmarshal([]byte(userInfo.Avatar), AvatarInfo)
+ if err != nil {
+ log.Error("AvatarInfo json.Unmarshal Error", err)
+ }
+ r.Avatar = AvatarInfo
+}
+
func (us *GetUserResp) AvatarInfo(avatarJson string) string {
if avatarJson == "" {
return ""
diff --git a/internal/service/user_service.go b/internal/service/user_service.go
index 7af14d55..bb5f105f 100644
--- a/internal/service/user_service.go
+++ b/internal/service/user_service.go
@@ -51,7 +51,7 @@ func NewUserService(userRepo usercommon.UserRepo,
}
// GetUserInfoByUserID get user info by user id
-func (us *UserService) GetUserInfoByUserID(ctx context.Context, token, userID string) (resp *schema.GetUserResp, err error) {
+func (us *UserService) GetUserInfoByUserID(ctx context.Context, token, userID string) (resp *schema.GetUserToSetShowResp, err error) {
userInfo, exist, err := us.userRepo.GetByUserID(ctx, userID)
if err != nil {
return nil, err
@@ -59,7 +59,7 @@ func (us *UserService) GetUserInfoByUserID(ctx context.Context, token, userID st
if !exist {
return nil, errors.BadRequest(reason.UserNotFound)
}
- resp = &schema.GetUserResp{}
+ resp = &schema.GetUserToSetShowResp{}
resp.GetFromUserEntity(userInfo)
resp.AccessToken = token
return resp, nil