From fdf7acc810566759e19ae441d13f6d5ea5d14f2f Mon Sep 17 00:00:00 2001 From: dengbiao Date: Wed, 4 Dec 2024 11:35:42 +0800 Subject: [PATCH] update --- app/hdl/friend_circle/hdl_comment.go | 2 +- app/hdl/friend_circle/hdl_friend_circle.go | 25 ++++++++---- app/md/friend_circles/md_friend_circle.go | 44 ++++++++++++++-------- app/router/router.go | 12 +++--- app/svc/friend_circle/svc_firend_circle.go | 22 +++++++++-- 5 files changed, 70 insertions(+), 35 deletions(-) diff --git a/app/hdl/friend_circle/hdl_comment.go b/app/hdl/friend_circle/hdl_comment.go index d681bdb..435cc7d 100644 --- a/app/hdl/friend_circle/hdl_comment.go +++ b/app/hdl/friend_circle/hdl_comment.go @@ -44,7 +44,7 @@ func IsCanComment(c *gin.Context) { // @Failure 400 {object} md.Response "具体错误" // @Router /api/v1/circleFriends/comment [Get] func Comment(c *gin.Context) { - var req *friend_circles.CommentReq + var req friend_circles.CommentReq if err1 := c.ShouldBindJSON(&req); err1 != nil { e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error()) return diff --git a/app/hdl/friend_circle/hdl_friend_circle.go b/app/hdl/friend_circle/hdl_friend_circle.go index 083834e..e891b06 100644 --- a/app/hdl/friend_circle/hdl_friend_circle.go +++ b/app/hdl/friend_circle/hdl_friend_circle.go @@ -73,7 +73,7 @@ func IsCanPublish(c *gin.Context) { // @Failure 400 {object} md.Response "具体错误" // @Router /api/v1/circleFriends/public [POST] func Publish(c *gin.Context) { - var req *friend_circles.PublishReq + var req friend_circles.PublishReq if err1 := c.ShouldBindJSON(&req); err1 != nil { e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error()) return @@ -118,13 +118,18 @@ func Publish(c *gin.Context) { // @Produce json // @param Authorization header string true "验证参数Bearer和token空格拼接" // @Param circle_index_id query string true "朋友圈文档记录" +// @Param req body comm.CommentListReq true "请求参数" // @Success 200 {string} "success" // @Failure 400 {object} md.Response "具体错误" -// @Router /api/v1/circleFriends/commentList [GET] +// @Router /api/v1/circleFriends/commentList [POST] func CommentList(c *gin.Context) { - circleIndexId := c.DefaultQuery("circle_index_id", "") + var req friend_circles.CommentListReq + if err1 := c.ShouldBindJSON(&req); err1 != nil { + e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error()) + return + } //查找朋友圈记录 - doc, err := es.FirstDoc(md.EggFriendCircleEsIndex, circleIndexId) + doc, err := es.FirstDoc(md.EggFriendCircleEsIndex, req.CircleIndexId) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return @@ -134,7 +139,7 @@ func CommentList(c *gin.Context) { return } - resp, err := svc2.CommentList(circleIndexId) + resp, err := svc2.CommentList(req) if err != nil { e.OutErr(c, e.ERR, err.Error()) return @@ -154,10 +159,14 @@ func CommentList(c *gin.Context) { // @Failure 400 {object} md.Response "具体错误" // @Router /api/v1/circleFriends/commentDetail [GET] func CommentDetail(c *gin.Context) { - commentIndexId := c.DefaultQuery("comment_index_id", "") + var req friend_circles.CommentDetailReq + if err1 := c.ShouldBindJSON(&req); err1 != nil { + e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error()) + return + } //查找评论记录 - doc1, err1 := es.FirstDoc(md.EggFriendCircleCommentEsAlias, commentIndexId) + doc1, err1 := es.FirstDoc(md.EggFriendCircleCommentEsAlias, req.CommentIndexId) if err1 != nil { e.OutErr(c, e.ERR_DB_ORM, err1.Error()) return @@ -167,7 +176,7 @@ func CommentDetail(c *gin.Context) { return } - resp, err := svc2.CommentDetail(commentIndexId) + resp, err := svc2.CommentDetail(req) if err != nil { e.OutErr(c, e.ERR, err.Error()) return diff --git a/app/md/friend_circles/md_friend_circle.go b/app/md/friend_circles/md_friend_circle.go index ee93d83..e883a97 100644 --- a/app/md/friend_circles/md_friend_circle.go +++ b/app/md/friend_circles/md_friend_circle.go @@ -2,6 +2,16 @@ package friend_circles import "code.fnuoos.com/EggPlanet/egg_system_rules.git/md" +type CommentListReq struct { + CircleIndexId string `json:"circle_index_id"` + Page int `json:"page"` // 页码 + PageSize int `json:"page_size"` // 每页数量 +} +type CommentDetailReq struct { + CommentIndexId string `json:"comment_index_id"` + Page int `json:"page"` // 页码 + PageSize int `json:"page_size"` // 每页数量 +} type PublishReq struct { Content string `json:"content,required"` // 文本内容 ImageList []string `json:"image_list"` // 图片 @@ -30,20 +40,22 @@ type CommentDetailResp struct { } type EggFriendCircleCommentEsStruct struct { - NickName string `json:"nickname"` - AvatarUrl string `json:"avatar_url"` // 用户头像 - Uid int64 `json:"uid" label:"uid"` - ImUid int64 `json:"im_uid" label:"im_uid"` - Kind int32 `json:"kind" label:"类型(1:普通 2:官方)"` - CircleId int64 `json:"circle_id" label:"朋友圈id"` - CommentId int64 `json:"comment_id" label:"评论id"` - ReplyCommentNickname int64 `json:"reply_comment_nickname" label:"回复评论的用户昵称"` - ReplyCommentId int64 `json:"reply_comment_id" label:"回复评论id"` - Content string `json:"content" label:"文本内容"` - LikesNums int `json:"likes_nums" label:"点赞数"` - CommentNums int `json:"comment_nums" label:"评论数"` - State int32 `json:"state" label:"状态(1:正常 2:隐藏)"` - IsPraise int32 `json:"is_praise" label:"是否被表扬(1:是 2:否)"` - CreatedAt string `json:"created_at"` - UpdatedAt string `json:"updated_at"` + NickName string `json:"nickname"` + AvatarUrl string `json:"avatar_url"` // 用户头像 + Uid int64 `json:"uid" label:"uid"` + ImUid int64 `json:"im_uid" label:"im_uid"` + Kind int32 `json:"kind" label:"类型(1:普通 2:官方)"` + CircleId string `json:"circle_id" label:"朋友圈id"` + CommentId string `json:"comment_id" label:"评论id"` + ReplyCommentNickname string `json:"reply_comment_nickname" label:"回复评论的用户昵称"` + ReplyCommentId string `json:"reply_comment_id" label:"回复评论id"` + ReplyCommentUserId int64 `json:"reply_comment_user_id" label:"回复评论用户id"` + ReplyCommentUserNickname string `json:"reply_comment_user_nickname" label:"回复评论用户昵称"` + Content string `json:"content" label:"文本内容"` + LikesNums int `json:"likes_nums" label:"点赞数"` + CommentNums int `json:"comment_nums" label:"评论数"` + State int32 `json:"state" label:"状态(1:正常 2:隐藏)"` + IsPraise int32 `json:"is_praise" label:"是否被表扬(1:是 2:否)"` + CreatedAt string `json:"created_at"` + UpdatedAt string `json:"updated_at"` } diff --git a/app/router/router.go b/app/router/router.go index 347101a..694bfd7 100644 --- a/app/router/router.go +++ b/app/router/router.go @@ -181,12 +181,12 @@ func route(r *gin.RouterGroup) { } func rCircleFriends(r *gin.RouterGroup) { - r.POST("/mySelfList", friend_circle.MySelfList) // 我的朋友圈列表 - r.POST("/recommendList", friend_circle.Publish) // 推荐列表 - r.GET("/commentList", friend_circle.CommentList) // 朋友圈详情列表 - r.GET("/commentDetail", friend_circle.CommentDetail) // 评论详情 - r.POST("/publish", friend_circle.Publish) // 发送朋友圈 - r.GET("/isCanPublish", friend_circle.IsCanPublish) // 是否可以发朋友圈 + r.POST("/mySelfList", friend_circle.MySelfList) // 我的朋友圈列表 + r.POST("/recommendList", friend_circle.Publish) // 推荐列表 + r.POST("/commentList", friend_circle.CommentList) // 评论列表 + r.POST("/commentDetail", friend_circle.CommentDetail) // 评论详情 + r.POST("/publish", friend_circle.Publish) // 发送朋友圈 + r.GET("/isCanPublish", friend_circle.IsCanPublish) // 是否可以发朋友圈 r.DELETE("/delete", friend_circle.Delete) // 删除朋友圈 r.POST("/like", friend_circle.Like) // 点赞 diff --git a/app/svc/friend_circle/svc_firend_circle.go b/app/svc/friend_circle/svc_firend_circle.go index 3d8c4a5..084b11e 100644 --- a/app/svc/friend_circle/svc_firend_circle.go +++ b/app/svc/friend_circle/svc_firend_circle.go @@ -118,16 +118,21 @@ func MySelfList(c *gin.Context, req friend_circles.MySelfListReq) (resp friend_c return } -func CommentList(circleIndexId string) (resp friend_circles.CommentListResp, err error) { +func CommentList(req friend_circles.CommentListReq) (resp friend_circles.CommentListResp, err error) { + // 分页参数 + from := (req.Page - 1) * req.PageSize + // 查询所有评论 query := elastic.NewBoolQuery() - query.Must(elastic.NewTermQuery("circle_id", circleIndexId)) + query.Must(elastic.NewTermQuery("circle_id", req.CircleIndexId)) query.Must(elastic.NewTermQuery("state", "1")) searchResult, err := es.EsClient.Search(). Index(md.EggFriendCircleCommentEsAlias). // 替换为你的索引名称 Query(query). Sort("create_at", false). // 按时间倒排 + From(from). + Size(req.PageSize). Pretty(true). Do(context.Background()) if err != nil { @@ -160,16 +165,21 @@ func CommentList(circleIndexId string) (resp friend_circles.CommentListResp, err return } -func CommentDetail(commentIndexId string) (resp friend_circles.CommentDetailResp, err error) { +func CommentDetail(req friend_circles.CommentDetailReq) (resp friend_circles.CommentDetailResp, err error) { + // 分页参数 + from := (req.Page - 1) * req.PageSize + // 查询所有评论 query := elastic.NewBoolQuery() - query.Must(elastic.NewTermQuery("comment_id", commentIndexId)) + query.Must(elastic.NewTermQuery("comment_id", req.CommentIndexId)) query.Must(elastic.NewTermQuery("state", "1")) searchResult, err := es.EsClient.Search(). Index(md.EggFriendCircleCommentEsAlias). // 替换为你的索引名称 Query(query). Sort("create_at", false). // 按时间倒排 + From(from). + Size(req.PageSize). Pretty(true). Do(context.Background()) if err != nil { @@ -196,6 +206,10 @@ func CommentDetail(commentIndexId string) (resp friend_circles.CommentDetailResp doc.NickName = user.Nickname doc.AvatarUrl = user.AvatarUrl + + if doc.ReplyCommentId != "" { + + } resp.List = append(resp.List, doc) }