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))
@@ -28,7 +28,7 @@ func (l *SearchCommentLikesLogic) SearchCommentLikes(in *pb.SearchCommentLikesRe
if limit <= 0 {
limit = 20
}
offset := in.GetPage()
offset := in.GetOffset()
if offset < 0 {
offset = 0
}
@@ -29,7 +29,7 @@ func (l *SearchCommentsLogic) SearchComments(in *pb.SearchCommentsReq) (*pb.Sear
if limit <= 0 {
limit = 20
}
offset := in.GetPage()
offset := in.GetOffset()
if offset < 0 {
offset = 0
}
@@ -28,7 +28,7 @@ func (l *SearchPostLikesLogic) SearchPostLikes(in *pb.SearchPostLikesReq) (*pb.S
if limit <= 0 {
limit = 20
}
offset := in.GetPage()
offset := in.GetOffset()
if offset < 0 {
offset = 0
}
@@ -29,7 +29,7 @@ func (l *SearchPostsLogic) SearchPosts(in *pb.SearchPostsReq) (*pb.SearchPostsRe
if limit <= 0 {
limit = 20
}
offset := in.GetPage()
offset := in.GetOffset()
if offset < 0 {
offset = 0
}
+25 -25
View File
@@ -1,7 +1,7 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.36.11
// protoc v5.29.6
// protoc v7.34.1
// source: community.proto
package pb
@@ -452,7 +452,7 @@ func (x *GetCommentLikesByIdResp) GetCommentLikes() *CommentLikes {
type SearchCommentLikesReq struct {
state protoimpl.MessageState `protogen:"open.v1"`
Page int64 `protobuf:"varint,1,opt,name=page,proto3" json:"page,omitempty"` //page
Offset int64 `protobuf:"varint,1,opt,name=offset,proto3" json:"offset,omitempty"` //offset
Limit int64 `protobuf:"varint,2,opt,name=limit,proto3" json:"limit,omitempty"` //limit
CommentId int64 `protobuf:"varint,3,opt,name=commentId,proto3" json:"commentId,omitempty"` //commentId
UserId int64 `protobuf:"varint,4,opt,name=userId,proto3" json:"userId,omitempty"` //userId
@@ -491,9 +491,9 @@ func (*SearchCommentLikesReq) Descriptor() ([]byte, []int) {
return file_community_proto_rawDescGZIP(), []int{9}
}
func (x *SearchCommentLikesReq) GetPage() int64 {
func (x *SearchCommentLikesReq) GetOffset() int64 {
if x != nil {
return x.Page
return x.Offset
}
return 0
}
@@ -1081,7 +1081,7 @@ func (x *GetCommentsByIdResp) GetComments() *Comments {
type SearchCommentsReq struct {
state protoimpl.MessageState `protogen:"open.v1"`
Page int64 `protobuf:"varint,1,opt,name=page,proto3" json:"page,omitempty"` //page
Offset int64 `protobuf:"varint,1,opt,name=offset,proto3" json:"offset,omitempty"` //offset
Limit int64 `protobuf:"varint,2,opt,name=limit,proto3" json:"limit,omitempty"` //limit
Id int64 `protobuf:"varint,3,opt,name=id,proto3" json:"id,omitempty"` //id
PostId int64 `protobuf:"varint,4,opt,name=postId,proto3" json:"postId,omitempty"` //postId
@@ -1124,9 +1124,9 @@ func (*SearchCommentsReq) Descriptor() ([]byte, []int) {
return file_community_proto_rawDescGZIP(), []int{20}
}
func (x *SearchCommentsReq) GetPage() int64 {
func (x *SearchCommentsReq) GetOffset() int64 {
if x != nil {
return x.Page
return x.Offset
}
return 0
}
@@ -1662,7 +1662,7 @@ func (x *GetPostLikesByIdResp) GetPostLikes() *PostLikes {
type SearchPostLikesReq struct {
state protoimpl.MessageState `protogen:"open.v1"`
Page int64 `protobuf:"varint,1,opt,name=page,proto3" json:"page,omitempty"` //page
Offset int64 `protobuf:"varint,1,opt,name=offset,proto3" json:"offset,omitempty"` //offset
Limit int64 `protobuf:"varint,2,opt,name=limit,proto3" json:"limit,omitempty"` //limit
PostId *int64 `protobuf:"varint,3,opt,name=postId,proto3,oneof" json:"postId,omitempty"` //postId
UserId *int64 `protobuf:"varint,4,opt,name=userId,proto3,oneof" json:"userId,omitempty"` //userId
@@ -1701,9 +1701,9 @@ func (*SearchPostLikesReq) Descriptor() ([]byte, []int) {
return file_community_proto_rawDescGZIP(), []int{31}
}
func (x *SearchPostLikesReq) GetPage() int64 {
func (x *SearchPostLikesReq) GetOffset() int64 {
if x != nil {
return x.Page
return x.Offset
}
return 0
}
@@ -2507,7 +2507,7 @@ func (x *GetPostsByIdResp) GetPosts() *Posts {
type SearchPostsReq struct {
state protoimpl.MessageState `protogen:"open.v1"`
Page int64 `protobuf:"varint,1,opt,name=page,proto3" json:"page,omitempty"` //page
Offset int64 `protobuf:"varint,1,opt,name=offset,proto3" json:"offset,omitempty"` //offset
Limit int64 `protobuf:"varint,2,opt,name=limit,proto3" json:"limit,omitempty"` //limit
Id int64 `protobuf:"varint,3,opt,name=id,proto3" json:"id,omitempty"` //id
AuthorId *int64 `protobuf:"varint,4,opt,name=authorId,proto3,oneof" json:"authorId,omitempty"` //authorId
@@ -2559,9 +2559,9 @@ func (*SearchPostsReq) Descriptor() ([]byte, []int) {
return file_community_proto_rawDescGZIP(), []int{42}
}
func (x *SearchPostsReq) GetPage() int64 {
func (x *SearchPostsReq) GetOffset() int64 {
if x != nil {
return x.Page
return x.Offset
}
return 0
}
@@ -2756,9 +2756,9 @@ const file_community_proto_rawDesc = "" +
"\x16GetCommentLikesByIdReq\x12\x0e\n" +
"\x02id\x18\x01 \x01(\x03R\x02id\"O\n" +
"\x17GetCommentLikesByIdResp\x124\n" +
"\fcommentLikes\x18\x01 \x01(\v2\x10.pb.CommentLikesR\fcommentLikes\"\x95\x01\n" +
"\x15SearchCommentLikesReq\x12\x12\n" +
"\x04page\x18\x01 \x01(\x03R\x04page\x12\x14\n" +
"\fcommentLikes\x18\x01 \x01(\v2\x10.pb.CommentLikesR\fcommentLikes\"\x99\x01\n" +
"\x15SearchCommentLikesReq\x12\x16\n" +
"\x06offset\x18\x01 \x01(\x03R\x06offset\x12\x14\n" +
"\x05limit\x18\x02 \x01(\x03R\x05limit\x12\x1c\n" +
"\tcommentId\x18\x03 \x01(\x03R\tcommentId\x12\x16\n" +
"\x06userId\x18\x04 \x01(\x03R\x06userId\x12\x1c\n" +
@@ -2796,9 +2796,9 @@ const file_community_proto_rawDesc = "" +
"\x12GetCommentsByIdReq\x12\x0e\n" +
"\x02id\x18\x01 \x01(\x03R\x02id\"?\n" +
"\x13GetCommentsByIdResp\x12(\n" +
"\bcomments\x18\x01 \x01(\v2\f.pb.CommentsR\bcomments\"\x99\x02\n" +
"\x11SearchCommentsReq\x12\x12\n" +
"\x04page\x18\x01 \x01(\x03R\x04page\x12\x14\n" +
"\bcomments\x18\x01 \x01(\v2\f.pb.CommentsR\bcomments\"\x9d\x02\n" +
"\x11SearchCommentsReq\x12\x16\n" +
"\x06offset\x18\x01 \x01(\x03R\x06offset\x12\x14\n" +
"\x05limit\x18\x02 \x01(\x03R\x05limit\x12\x0e\n" +
"\x02id\x18\x03 \x01(\x03R\x02id\x12\x16\n" +
"\x06postId\x18\x04 \x01(\x03R\x06postId\x12\x1a\n" +
@@ -2837,9 +2837,9 @@ const file_community_proto_rawDesc = "" +
"\x13GetPostLikesByIdReq\x12\x0e\n" +
"\x02id\x18\x01 \x01(\x03R\x02id\"C\n" +
"\x14GetPostLikesByIdResp\x12+\n" +
"\tpostLikes\x18\x01 \x01(\v2\r.pb.PostLikesR\tpostLikes\"\xac\x01\n" +
"\x12SearchPostLikesReq\x12\x12\n" +
"\x04page\x18\x01 \x01(\x03R\x04page\x12\x14\n" +
"\tpostLikes\x18\x01 \x01(\v2\r.pb.PostLikesR\tpostLikes\"\xb0\x01\n" +
"\x12SearchPostLikesReq\x12\x16\n" +
"\x06offset\x18\x01 \x01(\x03R\x06offset\x12\x14\n" +
"\x05limit\x18\x02 \x01(\x03R\x05limit\x12\x1b\n" +
"\x06postId\x18\x03 \x01(\x03H\x00R\x06postId\x88\x01\x01\x12\x1b\n" +
"\x06userId\x18\x04 \x01(\x03H\x01R\x06userId\x88\x01\x01\x12\x1c\n" +
@@ -2940,9 +2940,9 @@ const file_community_proto_rawDesc = "" +
"\x0fGetPostsByIdReq\x12\x0e\n" +
"\x02id\x18\x01 \x01(\x03R\x02id\"3\n" +
"\x10GetPostsByIdResp\x12\x1f\n" +
"\x05posts\x18\x01 \x01(\v2\t.pb.PostsR\x05posts\"\xf9\x05\n" +
"\x0eSearchPostsReq\x12\x12\n" +
"\x04page\x18\x01 \x01(\x03R\x04page\x12\x14\n" +
"\x05posts\x18\x01 \x01(\v2\t.pb.PostsR\x05posts\"\xfd\x05\n" +
"\x0eSearchPostsReq\x12\x16\n" +
"\x06offset\x18\x01 \x01(\x03R\x06offset\x12\x14\n" +
"\x05limit\x18\x02 \x01(\x03R\x05limit\x12\x0e\n" +
"\x02id\x18\x03 \x01(\x03R\x02id\x12\x1f\n" +
"\bauthorId\x18\x04 \x01(\x03H\x00R\bauthorId\x88\x01\x01\x12#\n" +