2026-08-09 10:43:45 +08:00
|
|
|
|
package post
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
|
"context"
|
|
|
|
|
|
|
2026-08-10 11:42:45 +08:00
|
|
|
|
"bsm/full/module/social/feed/internal/models"
|
|
|
|
|
|
pb "bsm/full/module/social/feed/pb"
|
2026-08-09 10:43:45 +08:00
|
|
|
|
"git.apinb.com/bsm-sdk/core/errcode"
|
|
|
|
|
|
"git.apinb.com/bsm-sdk/core/printer"
|
|
|
|
|
|
"git.apinb.com/bsm-sdk/core/service"
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2026-09-22 21:15:34 +08:00
|
|
|
|
// maxPageSize 单页最大条数,避免一次请求拉取过多数据
|
|
|
|
|
|
const maxPageSize int64 = 50
|
|
|
|
|
|
|
2026-08-09 10:43:45 +08:00
|
|
|
|
// 推文列表
|
|
|
|
|
|
func Fetch(ctx context.Context, in *pb.FetchRequest) (reply *pb.PostListReply, err error) {
|
2026-09-22 21:15:34 +08:00
|
|
|
|
auth, err := service.ParseMetaCtx(ctx, nil)
|
2026-08-09 10:43:45 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
}
|
2026-09-22 21:15:34 +08:00
|
|
|
|
// 归一化分页参数:页码下限 1,单页条数上限 maxPageSize
|
2026-08-09 10:43:45 +08:00
|
|
|
|
if in.GetPageNo() <= 0 {
|
|
|
|
|
|
in.PageNo = 1
|
|
|
|
|
|
}
|
|
|
|
|
|
if in.GetPageSize() <= 0 {
|
|
|
|
|
|
in.PageSize = 10
|
|
|
|
|
|
}
|
2026-09-22 21:15:34 +08:00
|
|
|
|
if in.GetPageSize() > maxPageSize {
|
|
|
|
|
|
in.PageSize = maxPageSize
|
|
|
|
|
|
}
|
2026-08-09 10:43:45 +08:00
|
|
|
|
|
2026-09-22 21:15:34 +08:00
|
|
|
|
data, cnt, err := models.PostList(in.PageNo, in.PageSize, in.Params["key"], auth.Identity)
|
2026-08-09 10:43:45 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
|
printer.Error(err.Error())
|
|
|
|
|
|
return nil, errcode.ErrDB
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var res = &pb.PostListReply{Cnt: cnt}
|
|
|
|
|
|
if cnt > 0 {
|
|
|
|
|
|
res.List = AssembleList(data)
|
|
|
|
|
|
}
|
|
|
|
|
|
return res, nil
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func AssembleList(data []*models.FeedPost) (res []*pb.PostItem) {
|
|
|
|
|
|
for _, val := range data {
|
|
|
|
|
|
post := &pb.PostItem{
|
|
|
|
|
|
Identity: val.Identity,
|
|
|
|
|
|
Content: val.Content,
|
|
|
|
|
|
FeedIdentity: val.Identity,
|
|
|
|
|
|
FeedId: int64(val.ID),
|
|
|
|
|
|
IsOpen: val.IsOpen,
|
|
|
|
|
|
CntUnlike: val.CntUnlike,
|
|
|
|
|
|
CntLike: val.CntLike,
|
|
|
|
|
|
CntComment: val.CntComment,
|
|
|
|
|
|
}
|
|
|
|
|
|
for _, tag := range val.Tags {
|
|
|
|
|
|
post.Tags = append(post.Tags, &pb.TagItem{
|
|
|
|
|
|
Key: tag.Key,
|
|
|
|
|
|
Content: tag.Content,
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
for _, attachs := range val.Attachs {
|
|
|
|
|
|
post.Attachs = append(post.Attachs, &pb.AttachItem{
|
|
|
|
|
|
Identity: attachs.Identity,
|
|
|
|
|
|
AttachType: attachs.AttachType,
|
|
|
|
|
|
Url: attachs.Url,
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
res = append(res, post)
|
|
|
|
|
|
}
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|