fix: 统一分页请求的 offset 语义

This commit is contained in:
zetaloop
2026-04-07 17:56:38 +08:00
parent 424b2b1cca
commit d153b5cf51
46 changed files with 334 additions and 346 deletions
@@ -43,7 +43,7 @@ func (l *CreateCommentLogic) CreateComment(req *types.CreateCommentReq) (resp *t
return nil, err
}
comments, err := l.svcCtx.CommunityRpc.SearchComments(l.ctx, &communitypb.SearchCommentsReq{
Page: 0,
Offset: 0,
Limit: 1,
PostId: req.PostId,
AuthorId: uid,
@@ -52,7 +52,7 @@ func (l *CreatePostLogic) CreatePost(req *types.CreatePostReq) (resp *types.Post
return nil, err
}
posts, err := l.svcCtx.CommunityRpc.SearchPosts(l.ctx, &communitypb.SearchPostsReq{
Page: 0,
Offset: 0,
Limit: 1,
AuthorId: &uid,
})
@@ -36,7 +36,7 @@ func (l *GetPostLogic) GetPost(req *types.PathId) (resp *types.Post, err error)
uid := currentUserIDOrZero(l.ctx)
liked := false
if uid > 0 {
likes, e := l.svcCtx.CommunityRpc.SearchPostLikes(l.ctx, &communitypb.SearchPostLikesReq{Page: 0, Limit: 1, PostId: &req.Id, UserId: &uid})
likes, e := l.svcCtx.CommunityRpc.SearchPostLikes(l.ctx, &communitypb.SearchPostLikesReq{Offset: 0, Limit: 1, PostId: &req.Id, UserId: &uid})
liked = e == nil && len(likes.GetPostLikes()) > 0
}
post := mapPost(l.ctx, l.svcCtx, out.GetPosts(), liked)
@@ -33,7 +33,7 @@ func (l *ListCommentsLogic) ListComments(req *types.ListCommentsReq) (resp *type
req.Limit = 20
}
out, err := l.svcCtx.CommunityRpc.SearchComments(l.ctx, &communitypb.SearchCommentsReq{
Page: req.Offset,
Offset: req.Offset,
Limit: req.Limit,
PostId: req.Id,
})
@@ -45,7 +45,7 @@ func (l *ListCommentsLogic) ListComments(req *types.ListCommentsReq) (resp *type
for _, c := range out.GetComments() {
liked := false
if uid > 0 {
likes, e := l.svcCtx.CommunityRpc.SearchCommentLikes(l.ctx, &communitypb.SearchCommentLikesReq{Page: 0, Limit: 1, CommentId: c.Id, UserId: uid})
likes, e := l.svcCtx.CommunityRpc.SearchCommentLikes(l.ctx, &communitypb.SearchCommentLikesReq{Offset: 0, Limit: 1, CommentId: c.Id, UserId: uid})
liked = e == nil && len(likes.GetCommentLikes()) > 0
}
items = append(items, mapComment(l.ctx, l.svcCtx, c, liked))
@@ -33,7 +33,7 @@ func (l *ListPostsLogic) ListPosts(req *types.PostListReq) (resp *types.PostList
if req.Limit <= 0 {
req.Limit = 20
}
in := &communitypb.SearchPostsReq{Page: req.Offset, Limit: req.Limit}
in := &communitypb.SearchPostsReq{Offset: req.Offset, Limit: req.Limit}
if req.Tags != "" {
in.Tags = strings.Split(req.Tags, ",")
}
@@ -46,7 +46,7 @@ func (l *ListPostsLogic) ListPosts(req *types.PostListReq) (resp *types.PostList
for _, p := range posts.GetPosts() {
liked := false
if uid > 0 {
likes, e := l.svcCtx.CommunityRpc.SearchPostLikes(l.ctx, &communitypb.SearchPostLikesReq{Page: 0, Limit: 1, PostId: &p.Id, UserId: &uid})
likes, e := l.svcCtx.CommunityRpc.SearchPostLikes(l.ctx, &communitypb.SearchPostLikesReq{Offset: 0, Limit: 1, PostId: &p.Id, UserId: &uid})
liked = e == nil && len(likes.GetPostLikes()) > 0
}
items = append(items, mapPost(l.ctx, l.svcCtx, p, liked))
@@ -33,7 +33,7 @@ func (l *ListUserPostsLogic) ListUserPosts(req *types.ListCommentsReq) (resp *ty
req.Limit = 20
}
authorID := req.Id
out, err := l.svcCtx.CommunityRpc.SearchPosts(l.ctx, &communitypb.SearchPostsReq{Page: req.Offset, Limit: req.Limit, AuthorId: &authorID})
out, err := l.svcCtx.CommunityRpc.SearchPosts(l.ctx, &communitypb.SearchPostsReq{Offset: req.Offset, Limit: req.Limit, AuthorId: &authorID})
if err != nil {
return nil, err
}
@@ -42,7 +42,7 @@ func (l *ListUserPostsLogic) ListUserPosts(req *types.ListCommentsReq) (resp *ty
for _, p := range out.GetPosts() {
liked := false
if uid > 0 {
likes, e := l.svcCtx.CommunityRpc.SearchPostLikes(l.ctx, &communitypb.SearchPostLikesReq{Page: 0, Limit: 1, PostId: &p.Id, UserId: &uid})
likes, e := l.svcCtx.CommunityRpc.SearchPostLikes(l.ctx, &communitypb.SearchPostLikesReq{Offset: 0, Limit: 1, PostId: &p.Id, UserId: &uid})
liked = e == nil && len(likes.GetPostLikes()) > 0
}
items = append(items, mapPost(l.ctx, l.svcCtx, p, liked))