@@ -22,6 +22,36 @@ import ( | |||
"time" | |||
) | |||
// PersonalSendingList | |||
// @Summary 朋友圈-个人发送朋友圈列表 | |||
// @Tags 朋友圈 | |||
// @Description 个人发送朋友圈列表 | |||
// @Accept json | |||
// @Produce json | |||
// @param Authorization header string true "验证参数Bearer和token空格拼接" | |||
// @Param req body friend_circles.PersonalSendingListReq true "签名上传url" | |||
// @Success 200 {object} friend_circles.PersonalSendingListResp "返回数据" | |||
// @Failure 400 {object} md.Response "具体错误" | |||
// @Router /api/v1/circleFriends/personalSending [POST] | |||
func PersonalSendingList(c *gin.Context) { | |||
var req friend_circles.PersonalSendingListReq | |||
err := c.ShouldBindJSON(&req) | |||
if err != nil { | |||
err = svc.HandleValidateErr(err) | |||
err1 := err.(e.E) | |||
e.OutErr(c, err1.Code, err1.Error()) | |||
return | |||
} | |||
resp, err := svc2.GetPersonalSendingList(c, req) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
} | |||
resp.Page = req.Page | |||
resp.PageSize = req.PageSize | |||
e.OutSuc(c, resp, nil) | |||
} | |||
// MySelfList | |||
// @Summary 朋友圈-我的朋友圈列表 | |||
// @Tags 朋友圈 | |||
@@ -27,6 +27,19 @@ type PublishReq struct { | |||
ImageList []string `json:"image_list"` // 图片 | |||
Video string `json:"video"` // 视屏 | |||
} | |||
type PersonalSendingListReq struct { | |||
Page int `json:"page"` // 页码 | |||
PageSize int `json:"page_size"` // 每页数量 | |||
} | |||
type PersonalSendingListResp struct { | |||
Page int `json:"page"` // 页码 | |||
PageSize int `json:"page_size"` // 每页数量 | |||
Total int64 `json:"total"` // 总量 | |||
List []*EggFriendCircleEsStruct `json:"list"` | |||
} | |||
type MySelfListReq struct { | |||
Page int `json:"page"` // 页码 | |||
PageSize int `json:"page_size"` // 每页数量 | |||
@@ -210,12 +210,13 @@ func route(r *gin.RouterGroup) { | |||
} | |||
func rCircleFriends(r *gin.RouterGroup) { | |||
r.POST("/mySelfList", friend_circle.MySelfList) // 我的朋友圈列表 | |||
r.POST("/recommendList", friend_circle.RecommendList) // 推荐列表 | |||
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.POST("/personalSending", friend_circle.PersonalSendingList) // 个人发送的朋友圈列表 | |||
r.POST("/mySelfList", friend_circle.MySelfList) // 我的朋友圈列表 | |||
r.POST("/recommendList", friend_circle.RecommendList) // 推荐列表 | |||
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) // 点赞 | |||
@@ -70,26 +70,73 @@ func IsCanPublish(c *gin.Context) (isCan bool, err error) { | |||
return | |||
} | |||
func MySelfList(c *gin.Context, req friend_circles.MySelfListReq) (resp friend_circles.MySelfListResp, err error) { | |||
func GetPersonalSendingList(c *gin.Context, req friend_circles.PersonalSendingListReq) (resp friend_circles.PersonalSendingListResp, err error) { | |||
user := svc.GetUser(c) | |||
// 分页参数 | |||
from := (req.Page - 1) * req.PageSize | |||
//获取当前用户在im中的user_id | |||
var friends []*model.Friend | |||
err = db.DbIm.Where("`user_id`=?", user.Id).Limit(5000).Find(&friends) | |||
// 构建查询 | |||
query := elastic.NewBoolQuery() | |||
query.Must(elastic.NewTermQuery("uid", user.Id)) | |||
searchResult, err := es.EsClient.Search(). | |||
Index(md.EggFriendCircleEsIndex). // 替换为你的索引名称 | |||
Query(query). | |||
Sort("created_at", false). // 按时间倒排 | |||
From(from). | |||
Size(req.PageSize). | |||
Pretty(true). | |||
Do(context.Background()) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
var friendIDs []interface{} | |||
for _, v := range friends { | |||
friendIDs = append(friendIDs, v.FriendId) | |||
// 检查是否有结果 | |||
if searchResult.Hits.TotalHits.Value == 0 { | |||
return | |||
} | |||
// 解析结果 | |||
for _, hit := range searchResult.Hits.Hits { | |||
var doc friend_circles.EggFriendCircleEsStruct | |||
err = json.Unmarshal(hit.Source, &doc) | |||
if err != nil { | |||
return | |||
} | |||
doc.CircleIndexId = hit.Id | |||
likeEsIndex := svc3.GetEggFriendCircleLikeEsIndex(user.Id) | |||
likeId := svc3.GetEggFriendCircleLikeEsIndexId(user.Id, hit.Id) | |||
likeDoc, _ := es.FirstDoc(likeEsIndex, likeId) | |||
if likeDoc != nil && likeDoc.Found { // 表示已点赞 | |||
doc.IsLike = true | |||
} | |||
resp.List = append(resp.List, &doc) | |||
} | |||
resp.Total = searchResult.TotalHits() | |||
return | |||
} | |||
func MySelfList(c *gin.Context, req friend_circles.MySelfListReq) (resp friend_circles.MySelfListResp, err error) { | |||
user := svc.GetUser(c) | |||
var imUser model.User | |||
_, err = db.DbIm.Where("phone_number = ?", user.Phone).Get(&imUser) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
//获取当前用户在im中的user_id | |||
var friends []*model.Friend | |||
err = db.DbIm.Where("`user_id`=?", imUser.Id).Limit(5000).Find(&friends) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
var friendIDs []interface{} | |||
for _, v := range friends { | |||
friendIDs = append(friendIDs, v.FriendId) | |||
} | |||
// 加入用户自身 | |||
friendIDs = append(friendIDs, imUser.Id) | |||
// 分页参数 | |||
from := (req.Page - 1) * req.PageSize | |||
@@ -1030,6 +1030,53 @@ const docTemplate = `{ | |||
} | |||
} | |||
}, | |||
"/api/v1/circleFriends/personalSending": { | |||
"post": { | |||
"description": "个人发送朋友圈列表", | |||
"consumes": [ | |||
"application/json" | |||
], | |||
"produces": [ | |||
"application/json" | |||
], | |||
"tags": [ | |||
"朋友圈" | |||
], | |||
"summary": "朋友圈-个人发送朋友圈列表", | |||
"parameters": [ | |||
{ | |||
"type": "string", | |||
"description": "验证参数Bearer和token空格拼接", | |||
"name": "Authorization", | |||
"in": "header", | |||
"required": true | |||
}, | |||
{ | |||
"description": "签名上传url", | |||
"name": "req", | |||
"in": "body", | |||
"required": true, | |||
"schema": { | |||
"$ref": "#/definitions/friend_circles.PersonalSendingListReq" | |||
} | |||
} | |||
], | |||
"responses": { | |||
"200": { | |||
"description": "返回数据", | |||
"schema": { | |||
"$ref": "#/definitions/friend_circles.PersonalSendingListResp" | |||
} | |||
}, | |||
"400": { | |||
"description": "具体错误", | |||
"schema": { | |||
"$ref": "#/definitions/md.Response" | |||
} | |||
} | |||
} | |||
} | |||
}, | |||
"/api/v1/circleFriends/publish": { | |||
"post": { | |||
"description": "发布朋友圈", | |||
@@ -4418,6 +4465,42 @@ const docTemplate = `{ | |||
} | |||
} | |||
}, | |||
"friend_circles.PersonalSendingListReq": { | |||
"type": "object", | |||
"properties": { | |||
"page": { | |||
"description": "页码", | |||
"type": "integer" | |||
}, | |||
"page_size": { | |||
"description": "每页数量", | |||
"type": "integer" | |||
} | |||
} | |||
}, | |||
"friend_circles.PersonalSendingListResp": { | |||
"type": "object", | |||
"properties": { | |||
"list": { | |||
"type": "array", | |||
"items": { | |||
"$ref": "#/definitions/friend_circles.EggFriendCircleEsStruct" | |||
} | |||
}, | |||
"page": { | |||
"description": "页码", | |||
"type": "integer" | |||
}, | |||
"page_size": { | |||
"description": "每页数量", | |||
"type": "integer" | |||
}, | |||
"total": { | |||
"description": "总量", | |||
"type": "integer" | |||
} | |||
} | |||
}, | |||
"friend_circles.PublishReq": { | |||
"type": "object", | |||
"properties": { | |||
@@ -1024,6 +1024,53 @@ | |||
} | |||
} | |||
}, | |||
"/api/v1/circleFriends/personalSending": { | |||
"post": { | |||
"description": "个人发送朋友圈列表", | |||
"consumes": [ | |||
"application/json" | |||
], | |||
"produces": [ | |||
"application/json" | |||
], | |||
"tags": [ | |||
"朋友圈" | |||
], | |||
"summary": "朋友圈-个人发送朋友圈列表", | |||
"parameters": [ | |||
{ | |||
"type": "string", | |||
"description": "验证参数Bearer和token空格拼接", | |||
"name": "Authorization", | |||
"in": "header", | |||
"required": true | |||
}, | |||
{ | |||
"description": "签名上传url", | |||
"name": "req", | |||
"in": "body", | |||
"required": true, | |||
"schema": { | |||
"$ref": "#/definitions/friend_circles.PersonalSendingListReq" | |||
} | |||
} | |||
], | |||
"responses": { | |||
"200": { | |||
"description": "返回数据", | |||
"schema": { | |||
"$ref": "#/definitions/friend_circles.PersonalSendingListResp" | |||
} | |||
}, | |||
"400": { | |||
"description": "具体错误", | |||
"schema": { | |||
"$ref": "#/definitions/md.Response" | |||
} | |||
} | |||
} | |||
} | |||
}, | |||
"/api/v1/circleFriends/publish": { | |||
"post": { | |||
"description": "发布朋友圈", | |||
@@ -4412,6 +4459,42 @@ | |||
} | |||
} | |||
}, | |||
"friend_circles.PersonalSendingListReq": { | |||
"type": "object", | |||
"properties": { | |||
"page": { | |||
"description": "页码", | |||
"type": "integer" | |||
}, | |||
"page_size": { | |||
"description": "每页数量", | |||
"type": "integer" | |||
} | |||
} | |||
}, | |||
"friend_circles.PersonalSendingListResp": { | |||
"type": "object", | |||
"properties": { | |||
"list": { | |||
"type": "array", | |||
"items": { | |||
"$ref": "#/definitions/friend_circles.EggFriendCircleEsStruct" | |||
} | |||
}, | |||
"page": { | |||
"description": "页码", | |||
"type": "integer" | |||
}, | |||
"page_size": { | |||
"description": "每页数量", | |||
"type": "integer" | |||
}, | |||
"total": { | |||
"description": "总量", | |||
"type": "integer" | |||
} | |||
} | |||
}, | |||
"friend_circles.PublishReq": { | |||
"type": "object", | |||
"properties": { | |||
@@ -137,6 +137,31 @@ definitions: | |||
description: 总量 | |||
type: integer | |||
type: object | |||
friend_circles.PersonalSendingListReq: | |||
properties: | |||
page: | |||
description: 页码 | |||
type: integer | |||
page_size: | |||
description: 每页数量 | |||
type: integer | |||
type: object | |||
friend_circles.PersonalSendingListResp: | |||
properties: | |||
list: | |||
items: | |||
$ref: '#/definitions/friend_circles.EggFriendCircleEsStruct' | |||
type: array | |||
page: | |||
description: 页码 | |||
type: integer | |||
page_size: | |||
description: 每页数量 | |||
type: integer | |||
total: | |||
description: 总量 | |||
type: integer | |||
type: object | |||
friend_circles.PublishReq: | |||
properties: | |||
content: | |||
@@ -2430,6 +2455,37 @@ paths: | |||
summary: 朋友圈-我的朋友圈列表 | |||
tags: | |||
- 朋友圈 | |||
/api/v1/circleFriends/personalSending: | |||
post: | |||
consumes: | |||
- application/json | |||
description: 个人发送朋友圈列表 | |||
parameters: | |||
- description: 验证参数Bearer和token空格拼接 | |||
in: header | |||
name: Authorization | |||
required: true | |||
type: string | |||
- description: 签名上传url | |||
in: body | |||
name: req | |||
required: true | |||
schema: | |||
$ref: '#/definitions/friend_circles.PersonalSendingListReq' | |||
produces: | |||
- application/json | |||
responses: | |||
"200": | |||
description: 返回数据 | |||
schema: | |||
$ref: '#/definitions/friend_circles.PersonalSendingListResp' | |||
"400": | |||
description: 具体错误 | |||
schema: | |||
$ref: '#/definitions/md.Response' | |||
summary: 朋友圈-个人发送朋友圈列表 | |||
tags: | |||
- 朋友圈 | |||
/api/v1/circleFriends/publish: | |||
post: | |||
consumes: | |||