finished ##172

add, edit, delete drinks in pricelist

add, edit, delete drinkTypes
This commit is contained in:
Tim Gröger 2020-03-01 19:20:47 +01:00
parent 3e61893baf
commit 71c850c8c6
8 changed files with 208 additions and 10 deletions

View File

@ -38,9 +38,11 @@ from geruecht.baruser.routes import baruser
from geruecht.finanzer.routes import finanzer
from geruecht.user.routes import user
from geruecht.vorstand.routes import vorstand
from geruecht.gastro.routes import gastrouser
LOGGER.info("Registrate bluebrints")
app.register_blueprint(baruser)
app.register_blueprint(finanzer)
app.register_blueprint(user)
app.register_blueprint(vorstand)
app.register_blueprint(gastrouser)

View File

@ -1,5 +1,4 @@
from flask import Blueprint, request, jsonify
import geruecht.controller as gc
import geruecht.controller.ldapController as lc
import geruecht.controller.userController as uc
from datetime import datetime
@ -8,7 +7,7 @@ from geruecht.decorator import login_required
baruser = Blueprint("baruser", __name__)
ldap= lc.LDAPController(gc.ldapConfig['URL'], gc.ldapConfig['dn'])
ldap= lc.LDAPController()
userController = uc.UserController()

View File

@ -378,12 +378,67 @@ class DatabaseController(metaclass=Singleton):
self.db.connection.rollback()
raise DatabaseExecption("Something went wrong with Database: {}".format(err))
def getDrinkPrice(self, name):
try:
cursor = self.db.connection.cursor()
if type(name) == str:
sql = "select * from pricelist where name='{}'".format(name)
elif type(name) == int:
sql = 'select * from pricelist where id={}'.format(name)
else:
raise DatabaseExecption("name as no type int or str. name={}, type={}".format(name, type(name)))
cursor.execute(sql)
return cursor.fetchone()
except Exception as err:
traceback.print_exc()
self.db.connection.rollback()
raise DatabaseExecption("Something went wrong with Database: {}".format(err))
def setDrinkPrice(self, drink):
try:
cursor = self.db.connection.cursor()
cursor.execute(
"insert into pricelist (name, price, price_big, price_club, price_club_big, premium, premium_club, price_extern_club, type) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)",
(
drink['name'], drink['price'], drink['price_big'], drink['price_club'], drink['price_club_big'],
drink['premium'], drink['premium_club'], drink['price_extern_club'], drink['type']))
self.db.connection.commit()
return self.getDrinkPrice(str(drink['name']))
except Exception as err:
traceback.print_exc()
self.db.connection.rollback()
raise DatabaseExecption("Something went wrong with Database: {}".format(err))
def updateDrinkPrice(self, drink):
try:
cursor = self.db.connection.cursor()
cursor.execute("update pricelist set name=%s, price=%s, price_big=%s, price_club=%s, price_club_big=%s, premium=%s, premium_club=%s, price_extern_club=%s, type=%s where id=%s",
(
drink['name'], drink['price'], drink['price_big'], drink['price_club'], drink['price_club_big'], drink['premium'], drink['premium_club'], drink['price_extern_club'], drink['type'], drink['id']
))
self.db.connection.commit()
return self.getDrinkPrice(drink['id'])
except Exception as err:
traceback.print_exc()
self.db.connection.rollback()
raise DatabaseExecption("Something went wrong with Database: {}".format(err))
def deleteDrink(self, drink):
try:
cursor = self.db.connection.cursor()
cursor.execute("delete from pricelist where id={}".format(drink['id']))
self.db.connection.commit()
except Exception as err:
traceback.print_exc()
self.db.connection.rollback()
raise DatabaseExecption("Something went worng with Database: {}".format(err))
def getDrinkType(self, name):
try:
cursor = self.db.connection.cursor()
if type(name) == str:
sql = 'select * from drink_type where name={}'.format(name)
if type(name) == int:
sql = "select * from drink_type where name='{}'".format(name)
elif type(name) == int:
sql = 'select * from drink_type where id={}'.format(name)
else:
raise DatabaseExecption("name as no type int or str. name={}, type={}".format(name, type(name)))
@ -394,6 +449,48 @@ class DatabaseController(metaclass=Singleton):
self.db.connection.rollback()
raise DatabaseExecption("Something went wrong with Database: {}".format(err))
def setDrinkType(self, name):
try:
cursor = self.db.connection.cursor()
cursor.execute("insert into drink_type (name) values ('{}')".format(name))
self.db.connection.commit()
return self.getDrinkType(name)
except Exception as err:
traceback.print_exc()
self.db.connection.rollback()
raise DatabaseExecption("Something went worng with Database: {}".format(err))
def updateDrinkType(self, type):
try:
cursor = self.db.connection.cursor()
cursor.execute("update drink_type set name='{}' where id={}".format(type['name'], type['id']))
self.db.connection.commit()
return self.getDrinkType(type['id'])
except Exception as err:
traceback.print_exc()
self.db.connection.rollback()
raise DatabaseExecption("Something went worng with Database: {}".format(err))
def deleteDrinkType(self, type):
try:
cursor = self.db.connection.cursor()
cursor.execute("delete from drink_type where id={}".format(type['id']))
self.db.connection.commit()
except Exception as err:
traceback.print_exc()
self.db.connection.rollback()
raise DatabaseExecption("Something went wrong with Database: {}".format(err))
def getAllDrinkTypes(self):
try:
cursor = self.db.connection.cursor()
cursor.execute('select * from drink_type')
return cursor.fetchall()
except Exception as err:
traceback.print_exc()
self.db.connection.rollback()
raise DatabaseExecption("Something went worng with Database: {}".format(err))
if __name__ == '__main__':
db = DatabaseController()
user = db.getUser('jhille')

View File

@ -5,6 +5,7 @@ from geruecht.model import MONEY, USER, GASTRO, BAR
from geruecht.exceptions import PermissionDenied
from . import Singleton
from geruecht.exceptions import UsernameExistLDAP, LDAPExcetpion
from geruecht import ldapConfig
import traceback
class LDAPController(metaclass=Singleton):
@ -12,8 +13,8 @@ class LDAPController(metaclass=Singleton):
Authentification over LDAP. Create Account on-the-fly
'''
def __init__(self, dn='dc=ldap,dc=example,dc=local'):
self.dn = dn
def __init__(self):
self.dn = ldapConfig['dn']
self.ldap = ldap

View File

@ -9,7 +9,7 @@ from datetime import datetime, timedelta
from geruecht.exceptions import UsernameExistLDAP, UsernameExistDB, DatabaseExecption, LDAPExcetpion, DayLocked, TansactJobIsAnswerdException
db = dc.DatabaseController()
ldap = lc.LDAPController(ldapConfig['dn'])
ldap = lc.LDAPController()
emailController = ec.EmailController(mailConfig['URL'], mailConfig['user'], mailConfig['passwd'], mailConfig['crypt'], mailConfig['port'], mailConfig['email'])
class UserController(metaclass=Singleton):
@ -17,11 +17,31 @@ class UserController(metaclass=Singleton):
def __init__(self):
pass
def deleteDrinkType(self, type):
db.deleteDrinkType(type)
def updateDrinkType(self, type):
return db.updateDrinkType(type)
def setDrinkType(self, type):
return db.setDrinkType(type)
def deletDrinkPrice(self, drink):
db.deleteDrink(drink)
def setDrinkPrice(self, drink):
retVal = db.setDrinkPrice(drink)
return retVal
def updateDrinkPrice(self, drink):
retVal = db.updateDrinkPrice(drink)
return retVal
def getAllDrinkTypes(self):
return db.getAllDrinkTypes()
def getPricelist(self):
list = db.getPriceList()
for element in list:
type = db.getDrinkType(element['type'])
element['type'] = type['name']
return list
def setTransactJob(self, from_user, to_user, date):

View File

71
geruecht/gastro/routes.py Normal file
View File

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

View File

@ -38,6 +38,14 @@ def _getPricelist():
except Exception as err:
return jsonify({"error": str(err)})
@app.route('/drinkTypes', methods=['GET'])
def getTypes():
try:
retVal = userController.getAllDrinkTypes()
return jsonify(retVal)
except Exception as err:
return jsonify({"error": str(err)}), 500
@app.route("/login", methods=['POST'])