flaschengeist/geruecht/vorstand/routes.py

73 lines
2.0 KiB
Python

from flask import Blueprint, request, jsonify
from datetime import datetime
import geruecht.controller.userController as uc
from geruecht.decorator import login_required
from geruecht.model import MONEY, GASTRO
import time
vorstand = Blueprint("vorstand", __name__)
userController = uc.UserController()
@vorstand.route("/sm/addUser", methods=['POST', 'GET'])
@login_required(groups=[MONEY, GASTRO])
def _addUser(**kwargs):
if request.method == 'GET':
return "<h1>HEllo World</h1>"
data = request.get_json()
user = data['user']
day = data['day']
month = data['month']
year = data['year']
date = datetime(year,month,day,12)
retVal = userController.addWorker(user['username'], date)
print(retVal)
return jsonify(retVal)
@vorstand.route("/sm/getUser", methods=['POST'])
@login_required(groups=[MONEY, GASTRO])
def _getUser(**kwargs):
data = request.get_json()
day = data['day']
month = data['month']
year = data['year']
date = datetime(year, month, day, 12)
lockedDay = userController.getLockedDay(date)
if not lockedDay:
lockedDay = {
'date': {
'year': year,
'month': month,
'day': day
},
'locked': False
}
else:
lockedDay = {
'date': {
'year': year,
'month': month,
'day': day
},
'locked': lockedDay['locked']
}
retVal = {
'worker': userController.getWorker(date),
'day': lockedDay
}
print(retVal)
return jsonify(retVal)
@vorstand.route("/sm/deleteUser", methods=['POST'])
@login_required(groups=[MONEY, GASTRO])
def _deletUser(**kwargs):
data = request.get_json()
user = data['user']
day = data['day']
month = data['month']
year = data['year']
date = datetime(year, month, day, 12)
userController.deleteWorker(user['username'], date)
return jsonify({"ok": "ok"})