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
@@ -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, &notFoundErr) {
logx.Errorf("failed to query games: %v", err)
return nil, errors.New("failed to query games")