2020-01-17 00:05:58 +00:00
|
|
|
from flask import Blueprint, request, jsonify
|
|
|
|
from geruecht.controller import userController, accesTokenController
|
|
|
|
from geruecht.model import USER
|
|
|
|
from datetime import datetime
|
|
|
|
|
|
|
|
user = Blueprint("user", __name__)
|
|
|
|
|
|
|
|
@user.route("/user/main")
|
|
|
|
def _main():
|
|
|
|
|
|
|
|
token = request.headers.get("Token")
|
2020-01-18 22:31:49 +00:00
|
|
|
accToken = accesTokenController.validateAccessToken(token, [USER])
|
2020-01-17 00:05:58 +00:00
|
|
|
if accToken:
|
|
|
|
accToken.user = userController.getUser(accToken.user.uid)
|
|
|
|
retVal = accToken.user.toJSON()
|
|
|
|
retVal['creditList'] = {credit.year: credit.toJSON() for credit in accToken.user.geruechte}
|
|
|
|
return jsonify(retVal)
|
|
|
|
return jsonify({"error": "permission denied"}), 401
|
|
|
|
|
|
|
|
@user.route("/user/addAmount", methods=['POST'])
|
|
|
|
def _addAmount():
|
|
|
|
|
|
|
|
token = request.headers.get("Token")
|
2020-01-18 22:31:49 +00:00
|
|
|
accToken = accesTokenController.validateAccessToken(token, [USER])
|
2020-01-17 00:05:58 +00:00
|
|
|
if accToken:
|
|
|
|
data = request.get_json()
|
|
|
|
amount = int(data['amount'])
|
|
|
|
date = datetime.now()
|
|
|
|
userController.addAmount(accToken.user.uid, amount, year=date.year, month=date.month)
|
|
|
|
accToken.user = userController.getUser(accToken.user.uid)
|
|
|
|
retVal = accToken.user.toJSON()
|
|
|
|
retVal['creditList'] = {credit.year: credit.toJSON() for credit in accToken.user.geruechte}
|
|
|
|
return jsonify(retVal)
|
|
|
|
return jsonify({"error": "permission denied"}), 401
|