2020-01-17 00:05:58 +00:00
|
|
|
from flask import Blueprint, request, jsonify
|
2020-01-19 08:07:45 +00:00
|
|
|
from geruecht.decorator import login_required
|
2020-01-18 23:37:40 +00:00
|
|
|
import geruecht.controller.userController as uc
|
2020-01-17 00:05:58 +00:00
|
|
|
from geruecht.model import USER
|
|
|
|
from datetime import datetime
|
2020-01-26 22:54:18 +00:00
|
|
|
import time
|
2020-01-27 19:16:04 +00:00
|
|
|
import traceback
|
2020-01-17 00:05:58 +00:00
|
|
|
|
|
|
|
user = Blueprint("user", __name__)
|
|
|
|
|
2020-01-18 23:37:40 +00:00
|
|
|
userController = uc.UserController()
|
|
|
|
|
2020-01-17 00:05:58 +00:00
|
|
|
|
2020-01-19 08:07:45 +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)
|
2020-01-19 08:07:45 +00:00
|
|
|
return jsonify("error", "something went wrong"), 500
|
2020-01-17 00:05:58 +00:00
|
|
|
|
|
|
|
@user.route("/user/addAmount", methods=['POST'])
|
2020-01-19 08:07:45 +00:00
|
|
|
@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)
|
2020-01-26 22:31:22 +00:00
|
|
|
return jsonify({"error": "something went wrong"}), 500
|
|
|
|
|
|
|
|
@user.route("/user/saveConfig", methods=['POST'])
|
|
|
|
@login_required(groups=[USER])
|
|
|
|
def _saveConfig(**kwargs):
|
|
|
|
try:
|
|
|
|
if 'accToken' in kwargs:
|
|
|
|
accToken = kwargs['accToken']
|
|
|
|
data = request.get_json()
|
|
|
|
accToken.user = userController.modifyUser(accToken.user, accToken.ldap_conn, data)
|
2020-01-26 22:54:18 +00:00
|
|
|
retVal = accToken.user.toJSON()
|
|
|
|
retVal['creditList'] = {credit.year: credit.toJSON() for credit in accToken.user.geruechte}
|
|
|
|
return jsonify(retVal)
|
2020-01-26 22:31:22 +00:00
|
|
|
except Exception as err:
|
2020-01-27 19:16:04 +00:00
|
|
|
return jsonify({"error": err}), 409
|
|
|
|
|
|
|
|
@user.route("/user/job", methods=['POST'])
|
|
|
|
@login_required(groups=[USER])
|
2020-02-22 10:15:20 +00:00
|
|
|
def _getUser(**kwargs):
|
|
|
|
data = request.get_json()
|
|
|
|
date = datetime.utcfromtimestamp(int(data['date']))
|
|
|
|
retVal = userController.getWorker(date)
|
|
|
|
print(retVal)
|
|
|
|
return jsonify(retVal)
|