Adicionar limit e offset na query (GET /trainer)

This commit is contained in:
Augusto Gunsch 2021-10-18 09:51:50 -03:00
parent 9b63327c0f
commit b905a812b9
No known key found for this signature in database
GPG Key ID: F7EEFE29825C72DC
1 changed files with 2 additions and 2 deletions

View File

@ -34,12 +34,12 @@ def get_trainers():
if nickname_contains: if nickname_contains:
return ConflictingParameters("nickname and nickname_contains are mutually exclusive") return ConflictingParameters("nickname and nickname_contains are mutually exclusive")
query = Trainer.query.filter_by(nickname=nickname) query = Trainer.query.filter_by(nickname=nickname).limit(limit).offset(offset)
return trainer_schemas.dumps(query.all()) return trainer_schemas.dumps(query.all())
else: # se nickname_contains também está vazio, retornará todos trainers else: # se nickname_contains também está vazio, retornará todos trainers
pattern = '%'+nickname_contains+'%' pattern = '%'+nickname_contains+'%'
query = Trainer.query.filter(Trainer.nickname.like(pattern)) query = Trainer.query.filter(Trainer.nickname.like(pattern)).limit(limit).offset(offset)
return trainer_schemas.dumps(query.all()) return trainer_schemas.dumps(query.all())
except NoResultFound: except NoResultFound: