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 AvatarInfo to show img

aichy1260ec198bad016
diff --git a/internal/schema/user_schema.go b/internal/schema/user_schema.go
index ea37582f..2362cf03 100644
--- a/internal/schema/user_schema.go
+++ b/internal/schema/user_schema.go
@@ -73,7 +73,7 @@ type GetUserResp struct {
func (r *GetUserResp) GetFromUserEntity(userInfo *entity.User) {
_ = copier.Copy(r, userInfo)
- r.Avatar = r.AvatarInfo(userInfo.Avatar)
+ r.Avatar = FormatAvatarInfo(userInfo.Avatar)
r.CreatedAt = userInfo.CreatedAt.Unix()
r.LastLoginDate = userInfo.LastLoginDate.Unix()
statusShow, ok := UserStatusShow[userInfo.Status]
@@ -103,7 +103,7 @@ func (r *GetUserToSetShowResp) GetFromUserEntity(userInfo *entity.User) {
r.Avatar = avatarInfo
}
-func (us *GetUserResp) AvatarInfo(avatarJson string) string {
+func FormatAvatarInfo(avatarJson string) string {
if avatarJson == "" {
return ""
}
@@ -172,6 +172,9 @@ type GetOtherUserInfoByUsernameResp struct {
func (r *GetOtherUserInfoByUsernameResp) GetFromUserEntity(userInfo *entity.User) {
_ = copier.Copy(r, userInfo)
+ Avatar := FormatAvatarInfo(userInfo.Avatar)
+ r.Avatar = Avatar
+
r.CreatedAt = userInfo.CreatedAt.Unix()
r.LastLoginDate = userInfo.LastLoginDate.Unix()
statusShow, ok := UserStatusShow[userInfo.Status]
diff --git a/internal/service/user_common/user.go b/internal/service/user_common/user.go
index adb87317..37363166 100644
--- a/internal/service/user_common/user.go
+++ b/internal/service/user_common/user.go
@@ -76,13 +76,12 @@ func (us *UserCommon) BatchUserBasicInfoByID(ctx context.Context, IDs []string)
// UserBasicInfoFormat
func (us *UserCommon) UserBasicInfoFormat(ctx context.Context, userInfo *entity.User) *schema.UserBasicInfo {
userBasicInfo := &schema.UserBasicInfo{}
- uinfo := &schema.GetUserResp{}
- uinfo.AvatarInfo(userInfo.Avatar)
+ Avatar := schema.FormatAvatarInfo(userInfo.Avatar)
userBasicInfo.ID = userInfo.ID
userBasicInfo.Username = userInfo.Username
userBasicInfo.Rank = userInfo.Rank
userBasicInfo.DisplayName = userInfo.DisplayName
- userBasicInfo.Avatar = uinfo.Avatar
+ userBasicInfo.Avatar = Avatar
userBasicInfo.Website = userInfo.Website
userBasicInfo.Location = userInfo.Location
userBasicInfo.IpInfo = userInfo.IPInfo