flaschengeist/geruecht/gastro/routes.py

98 lines
3.1 KiB
Python

from flask import request, jsonify, Blueprint
from geruecht.decorator import login_required
import geruecht.controller.userController as uc
from geruecht.model import GASTRO
from geruecht.logger import getCreditLogger, getDebugLogger
debug = getDebugLogger()
gastrouser = Blueprint('gastrouser', __name__)
userController = uc.UserController()
@gastrouser.route('/gastro/setDrink', methods=['POST'])
@login_required(groups=[GASTRO])
def setDrink(**kwargs):
debug.info("/gastro/setDrink")
try:
data = request.get_json()
retVal = userController.setDrinkPrice(data)
debug.debug("return {{ {} }}".format(retVal))
return jsonify(retVal)
except Exception as err:
debug.debug("exception", exc_info=True)
return jsonify({"error": str(err)}), 500
@gastrouser.route('/gastro/updateDrink', methods=['POST'])
@login_required(groups=[GASTRO])
def updateDrink(**kwargs):
debug.info("/gastro/updateDrink")
try:
data = request.get_json()
retVal = userController.updateDrinkPrice(data)
debug.debug("return {{ {} }}".format(retVal))
return jsonify(retVal)
except Exception as err:
debug.debug("exception", exc_info=True)
return jsonify({"error": str(err)}), 500
@gastrouser.route('/gastro/deleteDrink', methods=['POST'])
@login_required(groups=[GASTRO])
def deleteDrink(**kwargs):
debug.info("/gastro/dleteDrink")
try:
data = request.get_json()
id = data['id']
userController.deletDrinkPrice({"id": id})
debug.debug("return ok")
return jsonify({"ok": "ok"})
except Exception as err:
debug.debug("exception", exc_info=True)
return jsonify({"error": str(err)}), 500
@gastrouser.route('/gastro/setDrinkType', methods=['POST'])
@login_required(groups=[GASTRO])
def setType(**kwark):
debug.info("/gastro/setDrinkType")
try:
data = request.get_json()
name = data['name']
retVal = userController.setDrinkType(name)
debug.debug("return {{ {} }}".format(retVal))
return jsonify(retVal)
except Exception as err:
debug.debug("exception", exc_info=True)
return jsonify({"error": str(err)}), 500
@gastrouser.route('/gastro/updateDrinkType', methods=['POST'])
@login_required(groups=[GASTRO])
def updateType(**kwargs):
debug.info("/gastro/updateDrinkType")
try:
data = request.get_json()
retVal = userController.updateDrinkType(data)
debug.debug("return {{ {} }}".format(retVal))
return jsonify(retVal)
except Exception as err:
debug.debug("exception", exc_info=True)
return jsonify({"error": str(err)}), 500
@gastrouser.route('/gastro/deleteDrinkType', methods=['POST'])
@login_required(groups=[GASTRO])
def deleteType(**kwargs):
debug.info("/gastro/deleteDrinkType")
try:
data = request.get_json()
userController.deleteDrinkType(data)
debug.debug("return ok")
return jsonify({"ok": "ok"})
except Exception as err:
debug.debug("exception", exc_info=True)
return jsonify({"error": str(err)}), 500