2019-05-01 20:43:28 +00:00
|
|
|
from flask import Blueprint, request, jsonify
|
|
|
|
from geruecht import BAR, db
|
|
|
|
from geruecht.routes import verifyAccessToken
|
|
|
|
from geruecht.model.user import User
|
|
|
|
from datetime import datetime
|
|
|
|
|
|
|
|
baruser = Blueprint("baruser", __name__)
|
|
|
|
|
|
|
|
@baruser.route("/bar")
|
|
|
|
def _bar():
|
|
|
|
print(request.headers)
|
|
|
|
token = request.headers.get("Token")
|
|
|
|
print(token)
|
|
|
|
accToken = verifyAccessToken(token, BAR)
|
|
|
|
|
|
|
|
dic = {}
|
|
|
|
if accToken is not None:
|
|
|
|
users = User.query.all()
|
|
|
|
for user in users:
|
|
|
|
geruecht = None
|
2019-05-02 00:21:50 +00:00
|
|
|
geruecht = user.getGeruecht()
|
2019-05-01 20:43:28 +00:00
|
|
|
if geruecht is not None:
|
|
|
|
month = geruecht.getMonth(datetime.now().month)
|
|
|
|
amount = abs(month[0] - month[1])
|
|
|
|
if amount != 0:
|
|
|
|
dic[user.userID] = {"username": user.username,
|
|
|
|
"firstname": user.firstname,
|
|
|
|
"lastname": user.lastname,
|
|
|
|
"amount": abs(month[0] - month[1])
|
|
|
|
}
|
|
|
|
return jsonify(dic)
|
|
|
|
return jsonify({"error": "permission denied"}), 401
|
|
|
|
|
|
|
|
@baruser.route("/baradd", methods=['POST'])
|
|
|
|
def _baradd():
|
|
|
|
token = request.headers.get("Token")
|
|
|
|
print(token)
|
|
|
|
accToken = verifyAccessToken(token, BAR)
|
|
|
|
|
|
|
|
if accToken is not None:
|
|
|
|
data = request.get_json()
|
|
|
|
userID = data['userId']
|
|
|
|
amount = int(data['amount'])
|
|
|
|
|
|
|
|
user = User.query.filter_by(userID=userID).first()
|
2019-05-02 00:21:50 +00:00
|
|
|
month = user.addAmount(amount)
|
2019-05-01 20:43:28 +00:00
|
|
|
|
2019-05-02 00:21:50 +00:00
|
|
|
amount = abs(month[0] - month[1])
|
2019-05-01 20:43:28 +00:00
|
|
|
|
|
|
|
return jsonify({"userId": user.userID, "amount": amount})
|
|
|
|
return jsonify({"error", "permission denied"}), 401
|