fix: 统一分页请求的 offset 语义
This commit is contained in:
@@ -27,10 +27,10 @@ func NewSearchGamesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Searc
|
||||
|
||||
func (l *SearchGamesLogic) SearchGames(in *pb.SearchGamesReq) (*pb.SearchGamesResp, error) {
|
||||
notFoundErr := entcache.ErrNotFound
|
||||
if in.Page <= 0 || in.Limit <= 0 || in.Page > 1000 || in.Limit > 100 {
|
||||
if in.Offset < 0 || in.Limit <= 0 || in.Limit > 100 {
|
||||
return nil, errors.New("invalid pagination parameters")
|
||||
}
|
||||
all, err := l.svcCtx.GameModelRO.Games.Query().Limit(int(in.Limit)).Offset(int(in.Limit * (in.Page - 1))).All(l.ctx)
|
||||
all, err := l.svcCtx.GameModelRO.Games.Query().Limit(int(in.Limit)).Offset(int(in.Offset)).All(l.ctx)
|
||||
if err != nil && !errors.As(err, ¬FoundErr) {
|
||||
logx.Errorf("failed to query games: %v", err)
|
||||
return nil, errors.New("failed to query games")
|
||||
|
||||
Reference in New Issue
Block a user