flaschengeist/geruecht/finanzer/routes.py

48 lines
1.3 KiB
Python

from flask import Blueprint, request, jsonify
from geruecht import MONEY
from geruecht.routes import verifyAccessToken
from geruecht.model.user import User
finanzer = Blueprint("finanzer", __name__)
@finanzer.route("/getFinanzerMain")
def _getFinanzer():
""" Function for /getFinanzerMain
Retrieves all User for the groupe 'moneymaster'
Returns:
A JSON-File with Users or an Error.
example:
"""
token = request.headers.get("Token")
accToken = verifyAccessToken(token, MONEY)
if accToken is not None:
users = User.query.all()
dic = {}
for user in users:
dic[user.userID] = user.toJSON()
return jsonify(dic)
return jsonify({"error": "permission denied"}), 401
@finanzer.route("/getFinanzerYears", methods=['POST'])
def _getFinanzerYear():
print(request.headers)
token = request.headers.get("Token")
print(token)
accToken = verifyAccessToken(token, MONEY)
dic = {}
if accToken is not None:
data = request.get_json()
userID = data['userId']
user = User.query.filter_by(userID=userID).first()
dic[user.userID] = {}
for geruecht in user.geruechte:
dic[user.userID][geruecht.year] = geruecht.toJSON()
return jsonify(dic)
return jsonify({"error": "permission denied"}), 401