瀏覽代碼

add friend circle like list

master
shenjiachi 2 天之前
父節點
當前提交
1eb2df0646
共有 3 個文件被更改,包括 110 次插入3 次删除
  1. +86
    -1
      app/hdl/friend_circle/hdl_friend_circle.go
  2. +23
    -2
      app/md/friend_circles/md_friend_circle.go
  3. +1
    -0
      app/router/router.go

+ 86
- 1
app/hdl/friend_circle/hdl_friend_circle.go 查看文件

@@ -119,6 +119,87 @@ func IsCanPublish(c *gin.Context) {
e.OutSuc(c, resp, nil)
}

func FriendCircleLikeList(c *gin.Context) {
var req friend_circles.FriendCircleLikeListReq
if err1 := c.ShouldBindJSON(&req); err1 != nil {
e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
return
}
//查找朋友圈记录
//doc, err := es.FirstDoc(md.EggFriendCircleEsIndex, req.CircleIndexId)
//if err != nil {
// e.OutErr(c, e.ERR_DB_ORM, err.Error())
// return
//}
//if !doc.Found { // 表示没找到数据
// e.OutErr(c, e.ERR_NOT_FAN, "朋友圈文档记录不存在")
// return
//}

from := (req.Page - 1) * req.PageSize

// 查找点赞列表
query := elastic.NewBoolQuery()
query.Must(elastic.NewTermQuery("circle_id", req.CircleIndexId))

searchResult, err := es.EsClient.Search().
Index(md.EggFriendCircleLikeEsAlias). // 替换为你的索引名称
Query(query).
From(from).
Size(req.PageSize).
Sort("created_at", false). // 按时间倒排
Pretty(true).
Do(context.Background())
if err != nil {
return
}

var docs []*md.EggFriendCircleLikeEs
var docUserIds []int64
var total int64
// 检查是否有结果
if searchResult.Hits.TotalHits.Value != 0 {
// 解析结果
total = searchResult.Hits.TotalHits.Value
for _, hit := range searchResult.Hits.Hits {
var like md.EggFriendCircleLikeEs
err = json.Unmarshal(hit.Source, &like)
if err != nil {
return
}
docUserIds = append(docUserIds, like.ImUid)
docs = append(docs, &like)
}
}

nicknameAndAvatarMap, err := svc2.GetImUserNicknameAndAvatar(docUserIds)
if err != nil {
e.OutErr(c, e.ERR_DB_ORM, err.Error())
return
}
var list []*friend_circles.FriendCircleLikeEsStruct
for _, like := range docs {
temp := friend_circles.FriendCircleLikeEsStruct{
Uid: like.Uid,
ImUid: like.ImUid,
CircleId: like.CircleId,
}
val, ok := nicknameAndAvatarMap[like.ImUid]
if ok {
temp.ImNickname = val.NickName
temp.ImAvatar = val.Avatar
}
list = append(list, &temp)
}
resp := friend_circles.FriendCircleLikeListResp{
List: list,
Page: req.Page,
PageSize: req.PageSize,
Total: total,
}
e.OutSuc(c, resp, nil)
}

// Publish
// @Summary 朋友圈-发布朋友圈
// @Tags 朋友圈
@@ -153,6 +234,10 @@ func Publish(c *gin.Context) {
e.OutErr(c, e.ERR_DB_ORM, err.Error())
return
}
var imageStr string
if len(req.ImageList) > 0 {
imageStr = utils.SerializeStr(req.ImageList)
}

//插入es记录
now := time.Now()
@@ -161,7 +246,7 @@ func Publish(c *gin.Context) {
ImUid: imUser.Id,
Kind: 1,
Content: req.Content,
Image: utils.SerializeStr(req.ImageList),
Image: imageStr,
Video: req.Video,
LikesNums: 0,
ShareNums: 0,


+ 23
- 2
app/md/friend_circles/md_friend_circle.go 查看文件

@@ -12,6 +12,27 @@ type RecommendListResp struct {
List []*EggFriendCircleEsStruct `json:"list"`
}

type FriendCircleLikeListReq struct {
CircleIndexId string `json:"circle_index_id"` //朋友圈文档记录
Page int `json:"page"` // 页码
PageSize int `json:"page_size"` // 每页数量
}

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

type FriendCircleLikeEsStruct struct {
Uid int64 `json:"uid" label:"uid"`
ImUid int64 `json:"im_uid" label:"im_uid"`
CircleId string `json:"circle_id" label:"朋友圈id"`
ImNickname string `json:"im_nickname" label:"im 昵称"`
ImAvatar string `json:"im_avatar" label:"im 头像"`
}

type CommentListReq struct {
CircleIndexId string `json:"circle_index_id"` //朋友圈文档记录
Page int `json:"page"` // 页码
@@ -55,8 +76,8 @@ 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"`
ImNickname string `json:"im_nickname" label:"im 昵称"`
ImAvatar string `json:"im_avatar" label:"im 头像"`
Kind int32 `json:"kind" label:"类型(1:普通 2:官方)"` //类型(1:普通 2:官方)
Content string `json:"content" label:"文本内容"` //文本内容
Image string `json:"image" label:"图片"` //图片


+ 1
- 0
app/router/router.go 查看文件

@@ -217,6 +217,7 @@ func rCircleFriends(r *gin.RouterGroup) {
r.POST("/commentDetail", friend_circle.CommentDetail) // 评论详情
r.POST("/publish", friend_circle.Publish) // 发送朋友圈
r.GET("/isCanPublish", friend_circle.IsCanPublish) // 是否可以发朋友圈
r.POST("/likeList", friend_circle.FriendCircleLikeList) // 点赞列表

r.DELETE("/delete", friend_circle.Delete) // 删除朋友圈
r.POST("/like", friend_circle.Like) // 点赞


Loading…
取消
儲存