diff --git a/app/database.py b/app/database.py index f426c8f..34cedc3 100644 --- a/app/database.py +++ b/app/database.py @@ -34,10 +34,10 @@ class Database: return trainers def get_trainer_by_nickname(self, nickname, limit, offset): - return self.__get_trainers(("SELECT * FROM Trainers WHERE nickname = ? ? OFFSET ?", (nickname, limit, offset))) + return self.__get_trainers(("SELECT * FROM Trainers WHERE nickname = ? LIMIT ? OFFSET ?", (nickname, limit, offset))) def get_trainers_by_nickname_contains(self, contains, limit, offset): - return self.__get_trainers(("SELECT * FROM Trainers WHERE nickname LIKE ? ? OFFSET", ("%" + contains + "%", limit, offset))) + return self.__get_trainers(("SELECT * FROM Trainers WHERE nickname LIKE ? LIMIT ? OFFSET ?", ("%" + contains + "%", limit, offset))) def insert_trainer(self, trainer): con = sqlite3.connect(self.db_file) diff --git a/app/routes/routes.py b/app/routes/routes.py index a48c607..b939fcc 100644 --- a/app/routes/routes.py +++ b/app/routes/routes.py @@ -7,7 +7,7 @@ def route_get_trainers(): args = request.args try: - limit = int(args.get("limit", 0)) + limit = int(args.get("limit", -1)) offset = int(args.get("offset", 0)) except ValueError: return { @@ -16,15 +16,13 @@ def route_get_trainers(): "message": "Couldn't parse parameter as integer" }, 500 - if limit < 0 or offset < 0: + if limit < -1 or offset < 0: return { "code": 2, "type": "Integer parsing error", "message": "Expected positive integer as parameter" }, 500 - limit_str = "LIMIT %d" % limit if "limit" in args else "" # gambiarra pra tornar o limite infinito por padrĂ£o - nickname = args.get("nickname", "") nickname_contains = args.get("nickname_contains", "") @@ -36,6 +34,6 @@ def route_get_trainers(): }, 500 if nickname: - return jsonify(db.get_trainer_by_nickname(nickname, limit_str, offset)) + return jsonify(db.get_trainer_by_nickname(nickname, limit, offset)) else: - return jsonify(db.get_trainers_by_nickname_contains(nickname_contains, limit_str, offset)) + return jsonify(db.get_trainers_by_nickname_contains(nickname_contains, limit, offset))