From ee3eee6e6451ce455e44f3c20560246cc4409fe4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Thu, 2 May 2019 15:39:53 +0200 Subject: [PATCH] =?UTF-8?q?task=20#23=20erledigt=20es=20k=C3=B6nnen=20die?= =?UTF-8?q?=20User=20abgefragt=20werden,=20die=20diesen=20Monat=20noch=20k?= =?UTF-8?q?eine=20Schulden=20haben.=20es=20kann=20der=20user=20abgefragt?= =?UTF-8?q?=20werden?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- geruecht/baruser/routes.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/geruecht/baruser/routes.py b/geruecht/baruser/routes.py index 352cdba..2321268 100644 --- a/geruecht/baruser/routes.py +++ b/geruecht/baruser/routes.py @@ -49,3 +49,35 @@ def _baradd(): return jsonify({"userId": user.userID, "amount": amount}) return jsonify({"error", "permission denied"}), 401 + +@baruser.route("/barGetUsers") +def _getUsers(): + token = request.headers.get("Token") + print(token) + accToken = verifyAccessToken(token, BAR) + + retVal = {} + if accToken is not None: + users = User.query.all() + for user in users: + month = user.getGeruecht().getMonth() + if month == 0: + retVal[user.userID] = {user.toJSON()} + return jsonify(retVal) + return jsonify({"error": "permission denied"}), 401 + +@baruser.route("/barGetUser", methods=['POST']) +def _getUser(): + token = request.headers.get("Token") + print(token) + accToken = verifyAccessToken(token, BAR) + + if accToken is not None: + data = request.get_json() + userID = data['userId'] + + user = User.query.filter_by(userID=userID) + month = user.getGeruecht().getMonth() + + return jsonify({"userId": user.userID, "amount": month[1], "credit": month[0]}) + return jsonify({"error": "permission denied"}), 401