fix: 统一所有 RPC 分页校验为 max=100 并补齐默认值
This commit is contained in:
@@ -27,8 +27,14 @@ func NewSearchGamesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Searc
|
||||
|
||||
func (l *SearchGamesLogic) SearchGames(in *pb.SearchGamesReq) (*pb.SearchGamesResp, error) {
|
||||
notFoundErr := entcache.ErrNotFound
|
||||
if in.Offset < 0 || in.Limit <= 0 || in.Limit > 100 {
|
||||
return nil, errors.New("invalid pagination parameters")
|
||||
if in.Limit <= 0 {
|
||||
in.Limit = 20
|
||||
}
|
||||
if in.Limit > 100 {
|
||||
return nil, errors.New("limit too large")
|
||||
}
|
||||
if in.Offset < 0 {
|
||||
in.Offset = 0
|
||||
}
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user