flaschengeist/geruecht/user/routes.py

36 lines
1.3 KiB
Python
Raw Normal View History

2020-01-17 00:05:58 +00:00
from flask import Blueprint, request, jsonify
from geruecht.decorator import login_required
import geruecht.controller.userController as uc
2020-01-17 00:05:58 +00:00
from geruecht.model import USER
from datetime import datetime
user = Blueprint("user", __name__)
userController = uc.UserController()
2020-01-17 00:05:58 +00:00
@user.route("/user/main")
@login_required(groups=[USER])
def _main(**kwargs):
if 'accToken' in kwargs:
accToken = kwargs['accToken']
2020-01-17 00:05:58 +00:00
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", "something went wrong"), 500
2020-01-17 00:05:58 +00:00
@user.route("/user/addAmount", methods=['POST'])
@login_required(groups=[USER])
def _addAmount(**kwargs):
if 'accToken' in kwargs:
accToken = kwargs['accToken']
2020-01-17 00:05:58 +00:00
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": "something went wrong"}), 500