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
@@ -45,7 +45,7 @@ func (l *GetVerificationsLogic) GetVerifications(req *types.GetPendingListReq) (
limit = 20
}
verifications, err := l.svcCtx.UserVerificationsRpc.SearchUserVerifications(l.ctx, &pb.SearchUserVerificationsReq{
Page: offset / limit,
Offset: offset,
Limit: limit,
Role: req.Role,
Status: req.Status,
@@ -30,9 +30,9 @@ func NewSearchUsersLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Searc
var SearUsersErr = errors.New("search users failed")
func (l *SearchUsersLogic) SearchUsers(in *pb.SearchUsersReq) (out *pb.SearchUsersResp, err error) {
if in.Page == nil || *in.Page < 0 {
logx.Errorf("Invalid page number: %v", in.Page)
return nil, errors.New("invalid page number")
if in.Offset == nil || *in.Offset < 0 {
logx.Errorf("invalid offset: %v", in.Offset)
return nil, errors.New("invalid offset")
}
if *in.Limit > 1000 {
logx.Errorf("Limit exceeds max limit: %d", in.Limit)
@@ -45,7 +45,7 @@ func (l *SearchUsersLogic) SearchUsers(in *pb.SearchUsersReq) (out *pb.SearchUse
users.EmailContainsFold(*in.Username),
users.CurrentRole(*in.CurrentRole),
)).
Offset(int(*in.Page * *in.Limit)).
Offset(int(*in.Offset)).
Limit(int(*in.Limit)).
All(l.ctx)
if err != nil {
+22 -22
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: users.proto
package pb
@@ -725,7 +725,7 @@ func (x *GetUsersByIdResp) GetUsers() *Users {
type SearchUsersReq struct {
state protoimpl.MessageState `protogen:"open.v1"`
Page *int64 `protobuf:"varint,1,opt,name=page,proto3,oneof" json:"page,omitempty"` //page
Offset *int64 `protobuf:"varint,1,opt,name=offset,proto3,oneof" json:"offset,omitempty"` //offset
Limit *int64 `protobuf:"varint,2,opt,name=limit,proto3,oneof" json:"limit,omitempty"` //limit
Id *int64 `protobuf:"varint,3,opt,name=id,proto3,oneof" json:"id,omitempty"` //id
Username *string `protobuf:"bytes,4,opt,name=username,proto3,oneof" json:"username,omitempty"` //username
@@ -776,9 +776,9 @@ func (*SearchUsersReq) Descriptor() ([]byte, []int) {
return file_users_proto_rawDescGZIP(), []int{9}
}
func (x *SearchUsersReq) GetPage() int64 {
if x != nil && x.Page != nil {
return *x.Page
func (x *SearchUsersReq) GetOffset() int64 {
if x != nil && x.Offset != nil {
return *x.Offset
}
return 0
}
@@ -2234,7 +2234,7 @@ func (x *GetUserFollowsByIdResp) GetUserFollows() *UserFollows {
type SearchUserFollowsReq 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
FollowerId int64 `protobuf:"varint,4,opt,name=followerId,proto3" json:"followerId,omitempty"` //followerId
@@ -2274,9 +2274,9 @@ func (*SearchUserFollowsReq) Descriptor() ([]byte, []int) {
return file_users_proto_rawDescGZIP(), []int{36}
}
func (x *SearchUserFollowsReq) GetPage() int64 {
func (x *SearchUserFollowsReq) GetOffset() int64 {
if x != nil {
return x.Page
return x.Offset
}
return 0
}
@@ -2879,7 +2879,7 @@ func (x *GetUserPreferencesByIdResp) GetUserPreferences() *UserPreferences {
type SearchUserPreferencesReq 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
UserId int64 `protobuf:"varint,3,opt,name=userId,proto3" json:"userId,omitempty"` //userId
NotificationOrder bool `protobuf:"varint,4,opt,name=notificationOrder,proto3" json:"notificationOrder,omitempty"` //notificationOrder
@@ -2922,9 +2922,9 @@ func (*SearchUserPreferencesReq) Descriptor() ([]byte, []int) {
return file_users_proto_rawDescGZIP(), []int{47}
}
func (x *SearchUserPreferencesReq) GetPage() int64 {
func (x *SearchUserPreferencesReq) GetOffset() int64 {
if x != nil {
return x.Page
return x.Offset
}
return 0
}
@@ -3110,9 +3110,9 @@ const file_users_proto_rawDesc = "" +
"\x0fGetUsersByIdReq\x12\x0e\n" +
"\x02id\x18\x01 \x01(\x03R\x02id\"3\n" +
"\x10GetUsersByIdResp\x12\x1f\n" +
"\x05users\x18\x01 \x01(\v2\t.pb.UsersR\x05users\"\x81\x06\n" +
"\x0eSearchUsersReq\x12\x17\n" +
"\x04page\x18\x01 \x01(\x03H\x00R\x04page\x88\x01\x01\x12\x19\n" +
"\x05users\x18\x01 \x01(\v2\t.pb.UsersR\x05users\"\x87\x06\n" +
"\x0eSearchUsersReq\x12\x1b\n" +
"\x06offset\x18\x01 \x01(\x03H\x00R\x06offset\x88\x01\x01\x12\x19\n" +
"\x05limit\x18\x02 \x01(\x03H\x01R\x05limit\x88\x01\x01\x12\x13\n" +
"\x02id\x18\x03 \x01(\x03H\x02R\x02id\x88\x01\x01\x12\x1f\n" +
"\busername\x18\x04 \x01(\tH\x03R\busername\x88\x01\x01\x12'\n" +
@@ -3130,8 +3130,8 @@ const file_users_proto_rawDesc = "" +
"\aisAdmin\x18\x0e \x01(\bH\fR\aisAdmin\x88\x01\x01\x12!\n" +
"\tcreatedAt\x18\x0f \x01(\x03H\rR\tcreatedAt\x88\x01\x01\x12!\n" +
"\tupdatedAt\x18\x10 \x01(\x03H\x0eR\tupdatedAt\x88\x01\x01\x12!\n" +
"\tdeletedAt\x18\x11 \x01(\x03H\x0fR\tdeletedAt\x88\x01\x01B\a\n" +
"\x05_pageB\b\n" +
"\tdeletedAt\x18\x11 \x01(\x03H\x0fR\tdeletedAt\x88\x01\x01B\t\n" +
"\a_offsetB\b\n" +
"\x06_limitB\x05\n" +
"\x03_idB\v\n" +
"\t_usernameB\x0f\n" +
@@ -3239,9 +3239,9 @@ const file_users_proto_rawDesc = "" +
"\x15GetUserFollowsByIdReq\x12\x0e\n" +
"\x02id\x18\x01 \x01(\x03R\x02id\"K\n" +
"\x16GetUserFollowsByIdResp\x121\n" +
"\vuserFollows\x18\x01 \x01(\v2\x0f.pb.UserFollowsR\vuserFollows\"\xae\x01\n" +
"\x14SearchUserFollowsReq\x12\x12\n" +
"\x04page\x18\x01 \x01(\x03R\x04page\x12\x14\n" +
"\vuserFollows\x18\x01 \x01(\v2\x0f.pb.UserFollowsR\vuserFollows\"\xb2\x01\n" +
"\x14SearchUserFollowsReq\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\x1e\n" +
"\n" +
@@ -3285,9 +3285,9 @@ const file_users_proto_rawDesc = "" +
"\x19GetUserPreferencesByIdReq\x12\x0e\n" +
"\x02id\x18\x01 \x01(\x03R\x02id\"[\n" +
"\x1aGetUserPreferencesByIdResp\x12=\n" +
"\x0fuserPreferences\x18\x01 \x01(\v2\x13.pb.UserPreferencesR\x0fuserPreferences\"\xc0\x02\n" +
"\x18SearchUserPreferencesReq\x12\x12\n" +
"\x04page\x18\x01 \x01(\x03R\x04page\x12\x14\n" +
"\x0fuserPreferences\x18\x01 \x01(\v2\x13.pb.UserPreferencesR\x0fuserPreferences\"\xc4\x02\n" +
"\x18SearchUserPreferencesReq\x12\x16\n" +
"\x06offset\x18\x01 \x01(\x03R\x06offset\x12\x14\n" +
"\x05limit\x18\x02 \x01(\x03R\x05limit\x12\x16\n" +
"\x06userId\x18\x03 \x01(\x03R\x06userId\x12,\n" +
"\x11notificationOrder\x18\x04 \x01(\bR\x11notificationOrder\x124\n" +