Explorar el Código

add nickname and avatar when query friend circle

master
shenjiachi hace 3 días
padre
commit
aaf3293147
Se han modificado 3 ficheros con 72 adiciones y 10 borrados
  1. +36
    -0
      app/hdl/friend_circle/hdl_friend_circle.go
  2. +15
    -8
      app/md/friend_circles/md_friend_circle.go
  3. +21
    -2
      app/svc/friend_circle/svc_firend_circle.go

+ 36
- 0
app/hdl/friend_circle/hdl_friend_circle.go Ver fichero

@@ -47,6 +47,24 @@ func MySelfList(c *gin.Context) {
e.OutErr(c, e.ERR, err.Error())
return
}
imUserIds := make([]int64, len(resp.List))
for i, friendCircle := range resp.List {
imUserIds[i] = friendCircle.ImUid
}

nicknameAndAvatarMap, err := svc2.GetImUserNicknameAndAvatar(imUserIds)
if err != nil {
e.OutErr(c, e.ERR, err.Error())
return
}
for _, friendCircle := range resp.List {
val, ok := nicknameAndAvatarMap[friendCircle.ImUid]
if ok {
friendCircle.ImNickname = val.NickName
friendCircle.ImAvatar = val.Avatar
}
}

resp.Page = args.Page
resp.PageSize = args.PageSize
e.OutSuc(c, resp, nil)
@@ -189,6 +207,24 @@ func RecommendList(c *gin.Context) {
e.OutErr(c, e.ERR, err.Error())
return
}

imUserIds := make([]int64, len(resp.List))
for i, friendCircle := range resp.List {
imUserIds[i] = friendCircle.ImUid
}

nicknameAndAvatarMap, err := svc2.GetImUserNicknameAndAvatar(imUserIds)
if err != nil {
e.OutErr(c, e.ERR, err.Error())
return
}
for _, friendCircle := range resp.List {
val, ok := nicknameAndAvatarMap[friendCircle.ImUid]
if ok {
friendCircle.ImNickname = val.NickName
friendCircle.ImAvatar = val.Avatar
}
}
e.OutSuc(c, resp, nil)
}



+ 15
- 8
app/md/friend_circles/md_friend_circle.go Ver fichero

@@ -6,10 +6,10 @@ type RecommendListReq struct {
}

type RecommendListResp struct {
Page int `json:"page"` // 页码
PageSize int `json:"page_size"` // 每页数量
Total int64 `json:"total"` // 总量
List []EggFriendCircleEsStruct `json:"list"`
Page int `json:"page"` // 页码
PageSize int `json:"page_size"` // 每页数量
Total int64 `json:"total"` // 总量
List []*EggFriendCircleEsStruct `json:"list"`
}

type CommentListReq struct {
@@ -32,16 +32,18 @@ type MySelfListReq struct {
PageSize int `json:"page_size"` // 每页数量
}
type MySelfListResp struct {
Page int `json:"page"` // 页码
PageSize int `json:"page_size"` // 每页数量
Total int64 `json:"total"` // 总量
List []EggFriendCircleEsStruct `json:"list"`
Page int `json:"page"` // 页码
PageSize int `json:"page_size"` // 每页数量
Total int64 `json:"total"` // 总量
List []*EggFriendCircleEsStruct `json:"list"`
}

type EggFriendCircleEsStruct struct {
CircleIndexId string `json:"circle_index_id"` //朋友圈文档记录
Uid int64 `json:"uid" label:"uid"`
ImUid int64 `json:"im_uid" label:"im_uid"`
ImNickname string `json:"im_nickname" label:"im_nickname"`
ImAvatar string `json:"im_avatar" label:"im_avatar"`
Kind int32 `json:"kind" label:"类型(1:普通 2:官方)"` //类型(1:普通 2:官方)
Content string `json:"content" label:"文本内容"` //文本内容
Image string `json:"image" label:"图片"` //图片
@@ -107,3 +109,8 @@ type EggFriendCircleLikeReq struct {
type EggFriendCircleCancelLikeReq struct {
CircleIndexId string `json:"circle_index_id"` // 文章索引
}

type ImUserNicknameAndAvatar struct {
NickName string `json:"nickname"`
Avatar string `json:"avatar"`
}

+ 21
- 2
app/svc/friend_circle/svc_firend_circle.go Ver fichero

@@ -130,7 +130,7 @@ func MySelfList(c *gin.Context, req friend_circles.MySelfListReq) (resp friend_c
if likeDoc != nil && likeDoc.Found { // 表示已点赞
doc.IsLike = true
}
resp.List = append(resp.List, doc)
resp.List = append(resp.List, &doc)
}

resp.Total = searchResult.TotalHits()
@@ -170,7 +170,7 @@ func GetRecommendList(req friend_circles.RecommendListReq) (resp friend_circles.
return
}
doc.CircleIndexId = hit.Id
resp.List = append(resp.List, doc)
resp.List = append(resp.List, &doc)
}

resp.Total = searchResult.TotalHits()
@@ -333,3 +333,22 @@ func DelFriendCircleComment(circleId string) (err error) {
}
return
}

func GetImUserNicknameAndAvatar(imUserIds []int64) (map[int64]friend_circles.ImUserNicknameAndAvatar, error) {
var imUsers []model.User
err := db.DbIm.In("id", imUserIds).Find(&imUsers)
if err != nil {
return nil, err
}
scheme, domain := svc.ImageBucket(db.Db)
info := make(map[int64]friend_circles.ImUserNicknameAndAvatar, len(imUsers))
for _, user := range imUsers {
tempUrl := svc.ImageFormatWithBucket(scheme, domain, user.AvatarUrl)
temp := friend_circles.ImUserNicknameAndAvatar{
NickName: user.Nickname,
Avatar: tempUrl,
}
info[user.Id] = temp
}
return info, nil
}

Cargando…
Cancelar
Guardar