FreeDrinkList für Bardienste und AG
Es wurde die komplette backendverwaltung für Freigetränke Band und AG hinzugefügt. Es gibt auch schon ansätze für das Interface um Freigetränke zu bearbeiten.
This commit is contained in:
parent
fac8afab03
commit
c1c3437682
|
@ -1,6 +1,6 @@
|
|||
from ..mainController import Singleton
|
||||
from geruecht import db
|
||||
from ..databaseController import dbUserController, dbCreditListController, dbJobKindController, dbPricelistController, dbWorkerController, dbWorkgroupController, dbJobInviteController, dbJobRequesController, dbAccessTokenController, dbRegistrationController
|
||||
from ..databaseController import dbUserController, dbCreditListController, dbJobKindController, dbPricelistController, dbWorkerController, dbWorkgroupController, dbJobInviteController, dbJobRequesController, dbAccessTokenController, dbRegistrationController, dbFreeDrinkListConfigController
|
||||
from geruecht.exceptions import DatabaseExecption
|
||||
import traceback
|
||||
from MySQLdb._exceptions import IntegrityError
|
||||
|
@ -15,6 +15,7 @@ class DatabaseController(dbUserController.Base,
|
|||
dbJobRequesController.Base,
|
||||
dbAccessTokenController.Base,
|
||||
dbRegistrationController.Base,
|
||||
dbFreeDrinkListConfigController.Base,
|
||||
metaclass=Singleton):
|
||||
'''
|
||||
DatabaesController
|
||||
|
|
|
@ -0,0 +1,136 @@
|
|||
import traceback
|
||||
from datetime import datetime
|
||||
from datetime import timedelta
|
||||
from geruecht.exceptions import DatabaseExecption
|
||||
|
||||
class Base:
|
||||
def get_free_drink_list_config(self, id):
|
||||
try:
|
||||
cursor = self.db.connection.cursor()
|
||||
cursor.execute(f'select * from free_drink_list_config where id={id}')
|
||||
data = cursor.fetchone()
|
||||
if data['drink_id'] != None:
|
||||
data['drink'] = self.getDrinkPrice(data['drink_id'])
|
||||
data['free_drink_types'] = self.get_free_drink_list_types_for_drink(data['id'])
|
||||
return data
|
||||
except Exception as err:
|
||||
traceback.print_exc()
|
||||
self.db.connection.rollback()
|
||||
raise DatabaseExecption("Something went wrong with Database: {}".format(err))
|
||||
|
||||
def get_free_drink_list_configs(self):
|
||||
try:
|
||||
cursor = self.db.connection.cursor()
|
||||
cursor.execute("select * from free_drink_list_config")
|
||||
retVal = cursor.fetchall()
|
||||
for data in retVal:
|
||||
if data['drink_id'] != None:
|
||||
data['drink'] = self.getDrinkPrice(data['drink_id'])
|
||||
data['free_drink_types'] = self.get_free_drink_list_types_for_drink(data['id'])
|
||||
|
||||
return retVal
|
||||
except Exception as err:
|
||||
traceback.print_exc()
|
||||
self.db.connection.rollback()
|
||||
raise DatabaseExecption("Something went wrong with Database: {}".format(err))
|
||||
|
||||
def set_free_drink_list_config(self, free_drink_list_config):
|
||||
try:
|
||||
cursor = self.db.connection.cursor()
|
||||
cursor.execute(f'insert into free_drink_list_config (drink_id, label, price) values ({free_drink_list_config["drink"]["id"]}, "{free_drink_list_config["label"]}", {free_drink_list_config["price"]})')
|
||||
self.db.connection.commit()
|
||||
return self.get_free_drink_list_configs()
|
||||
except Exception as err:
|
||||
traceback.print_exc()
|
||||
self.db.connection.rollback()
|
||||
raise DatabaseExecption("Something went wrong with Database: {}".format(err))
|
||||
|
||||
def get_free_drink_list_types(self):
|
||||
try:
|
||||
cursor = self.db.connection.cursor()
|
||||
cursor.execute('select * from free_drink_list_type')
|
||||
return cursor.fetchall()
|
||||
except Exception as err:
|
||||
traceback.print_exc()
|
||||
self.db.connection.rollback()
|
||||
raise DatabaseExecption("Something went wrong with Database: {}".format(err))
|
||||
|
||||
def get_free_drink_list_types_for_drink(self, id):
|
||||
try:
|
||||
cursor = self.db.connection.cursor()
|
||||
cursor.execute(f'select a.* from free_drink_list_type a, free_drink_list_type_config b where free_drink_list_config_id={id} and b.free_drink_list_type_id=a.id')
|
||||
return cursor.fetchall()
|
||||
except Exception as err:
|
||||
traceback.print_exc()
|
||||
self.db.connection.rollback()
|
||||
raise DatabaseExecption("Something went wrong with Database: {}".format(err))
|
||||
|
||||
def get_free_drink_list_type(self, name):
|
||||
try:
|
||||
cursor = self.db.connection.cursor()
|
||||
if type(name) == str:
|
||||
sql = f'select * from free_drink_list_type where name={name}'
|
||||
elif type(name) == int:
|
||||
sql = f'select * from free_drink_list_type where id={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 set_free_drink_list_history(self, user, free_drink_list_config):
|
||||
try:
|
||||
cursor = self.db.connection.cursor()
|
||||
cursor.execute(f'insert into free_drink_list_history (timestamp, free_drink_config_id, user_id, free_drink_type_id) values ("{datetime.now()}", {free_drink_list_config["id"]}, {user.id}, {free_drink_list_config["free_drink_type_id"]})')
|
||||
self.db.connection.commit()
|
||||
return self.get_free_drink_list_history_by_user(user)
|
||||
except Exception as err:
|
||||
traceback.print_exc()
|
||||
self.db.connection.rollback()
|
||||
raise DatabaseExecption("Something went wrong with Database: {}".format(err))
|
||||
|
||||
def get_free_drink_list_history_by_user(self, user):
|
||||
try:
|
||||
cursor = self.db.connection.cursor()
|
||||
now = datetime.now()
|
||||
worker = self.getWorker(user, now)
|
||||
cursor.execute(f'select * from free_drink_list_history where timestamp>="{worker["startdatetime"]}" and user_id={user.id}')
|
||||
retVal = cursor.fetchall()
|
||||
for data in retVal:
|
||||
data['timestamp'] = {'year': data['timestamp'].year,
|
||||
'month': data['timestamp'].month,
|
||||
'day': data['timestamp'].day,
|
||||
'hour': data['timestamp'].hour,
|
||||
'minute': data['timestamp'].minute,
|
||||
'second': data['timestamp'].second}
|
||||
data['free_drink_config'] = self.get_free_drink_list_config(data['free_drink_config_id'])
|
||||
data['free_drink_type'] = self.get_free_drink_list_type(data['free_drink_type_id'])
|
||||
return retVal
|
||||
except Exception as err:
|
||||
traceback.print_exc()
|
||||
self.db.connection.rollback()
|
||||
raise DatabaseExecption("Something went wrong with Database: {}".format(err))
|
||||
|
||||
def update_free_drink_list_history(self, free_drink_list_history):
|
||||
try:
|
||||
cursor = self.db.connection.cursor()
|
||||
cursor.execute(f'update free_drink_list_history set canceled={free_drink_list_history["canceled"]} where id={free_drink_list_history["id"]}')
|
||||
self.db.connection.commit()
|
||||
return True
|
||||
except Exception as err:
|
||||
traceback.print_exc()
|
||||
self.db.connection.rollback()
|
||||
raise DatabaseExecption("Something went wrong with Database: {}".format(err))
|
||||
def delete_free_drink_list_history(self, free_drink_list_history):
|
||||
try:
|
||||
cursor = self.db.connection.cursor()
|
||||
cursor.execute(f'delete from free_drink_list_history where id={free_drink_list_history["id"]}')
|
||||
self.db.connection.commit()
|
||||
return True
|
||||
except Exception as err:
|
||||
traceback.print_exc()
|
||||
self.db.connection.rollback()
|
||||
raise DatabaseExecption("Something went wrong with Database: {}".format(err))
|
|
@ -8,6 +8,9 @@ class Base:
|
|||
try:
|
||||
cursor = self.db.connection.cursor()
|
||||
cursor.execute("select * from pricelist")
|
||||
retVal = cursor.fetchall()
|
||||
for data in retVal:
|
||||
data['drink_type'] = self.getDrinkType(data['type'])
|
||||
return cursor.fetchall()
|
||||
except Exception as err:
|
||||
traceback.print_exc()
|
||||
|
@ -24,7 +27,10 @@ class Base:
|
|||
else:
|
||||
raise DatabaseExecption("name as no type int or str. name={}, type={}".format(name, type(name)))
|
||||
cursor.execute(sql)
|
||||
return cursor.fetchone()
|
||||
retVal = cursor.fetchone()
|
||||
if retVal:
|
||||
retVal['drink_type'] = self.getDrinkType(retVal['type'])
|
||||
return retVal
|
||||
except Exception as err:
|
||||
traceback.print_exc()
|
||||
self.db.connection.rollback()
|
||||
|
|
|
@ -8,7 +8,7 @@ class Base:
|
|||
def getWorker(self, user, date):
|
||||
try:
|
||||
cursor = self.db.connection.cursor()
|
||||
cursor.execute("select * from bardienste where user_id={} and startdatetime='{}'".format(user.id, date))
|
||||
cursor.execute("select * from bardienste where user_id={} and startdatetime<='{}' and enddatetime>='{}'".format(user.id, date, date))
|
||||
data = cursor.fetchone()
|
||||
return {"user": user.toJSON(), "startdatetime": data['startdatetime'], "enddatetime": data['enddatetime'], "start": { "year": data['startdatetime'].year, "month": data['startdatetime'].month, "day": data['startdatetime'].day}, "job_kind": self.getJobKind(data['job_kind']) if data['job_kind'] != None else None} if data else None
|
||||
except Exception as err:
|
||||
|
|
|
@ -5,7 +5,7 @@ import geruecht.controller.emailController as ec
|
|||
from geruecht.model.user import User
|
||||
from datetime import datetime, timedelta
|
||||
from geruecht.logger import getDebugLogger
|
||||
from ..mainController import mainJobKindController, mainCreditListController, mainPricelistController, mainUserController, mainWorkerController, mainWorkgroupController, mainJobInviteController, mainJobRequestController, mainRegistrationController, mainPasswordReset
|
||||
from ..mainController import mainJobKindController, mainCreditListController, mainPricelistController, mainUserController, mainWorkerController, mainWorkgroupController, mainJobInviteController, mainJobRequestController, mainRegistrationController, mainPasswordReset, mainFreeDrinkListConfigController
|
||||
|
||||
db = dc.DatabaseController()
|
||||
ldap = lc.LDAPController()
|
||||
|
@ -24,6 +24,7 @@ class MainController(mainJobKindController.Base,
|
|||
mainJobRequestController.Base,
|
||||
mainRegistrationController.Base,
|
||||
mainPasswordReset.Base,
|
||||
mainFreeDrinkListConfigController.Base,
|
||||
metaclass=Singleton):
|
||||
|
||||
def __init__(self):
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
import geruecht.controller.databaseController as dc
|
||||
from geruecht.logger import getDebugLogger
|
||||
|
||||
db = dc.DatabaseController()
|
||||
debug = getDebugLogger()
|
||||
|
||||
class Base:
|
||||
def get_free_drink_list_configs(self):
|
||||
return db.get_free_drink_list_configs()
|
||||
|
||||
def set_free_drink_list_config(self, data):
|
||||
return db.set_free_drink_list_config(data)
|
||||
|
||||
def set_free_drink_list_history(self, user, data):
|
||||
return db.set_free_drink_list_history(user, data)
|
||||
|
||||
def get_free_drink_list_history(self, user):
|
||||
return db.get_free_drink_list_history_by_user(user)
|
||||
|
||||
def delete_free_drink_list_history(self, data):
|
||||
return db.delete_free_drink_list_history(data)
|
||||
|
||||
def update_free_drink_list_history(self, user, data):
|
||||
db.update_free_drink_list_history(data)
|
||||
return db.get_free_drink_list_history_by_user(user)
|
|
@ -26,6 +26,49 @@ def _valid(**kwargs):
|
|||
debug.warning("exception in valide.", exc_info=True)
|
||||
return jsonify({"error": str(err)}), 500
|
||||
|
||||
@app.route("/freeDrinkListConfig", methods=['GET'])
|
||||
@login_required()
|
||||
def _free_drink_list_config(**kwargs):
|
||||
try:
|
||||
debug.info("get free_drink_list_config")
|
||||
retVal = mainController.get_free_drink_list_configs()
|
||||
debug.info("return free_drink_list_config {{ {} }}".format(retVal))
|
||||
return jsonify(retVal)
|
||||
except Exception as err:
|
||||
debug.warning("exception in get free_dirnk_list_config.", exc_info=True)
|
||||
return jsonify({"error": str(err)}), 500
|
||||
|
||||
@app.route("/freeDrinkListHistory", methods=['GET', 'POST', 'PUT'])
|
||||
@login_required()
|
||||
def _free_drink_list_history(**kwargs):
|
||||
try:
|
||||
debug.info("set free_drink_list_history")
|
||||
user = kwargs['accToken'].user
|
||||
if request.method == 'GET':
|
||||
retVal = mainController.get_free_drink_list_history(user)
|
||||
if request.method == 'POST' or request.method == 'PUT':
|
||||
data = request.get_json()
|
||||
if request.method == 'POST':
|
||||
retVal = mainController.set_free_drink_list_history(user, data)
|
||||
else:
|
||||
retVal = mainController.update_free_drink_list_history(user, data)
|
||||
debug.debug(f'return free_drink_list_history {{{retVal}}}')
|
||||
return jsonify(retVal)
|
||||
except Exception as err:
|
||||
debug.warning("exception in get free_dirnk_list_config.", exc_info=True)
|
||||
return jsonify({"error": str(err)}), 500
|
||||
|
||||
@app.route("/deleteDrinkListHistory", methods=['POST'])
|
||||
@login_required()
|
||||
def _delete_free_drink_list_history(**kwargs):
|
||||
try:
|
||||
debug.info("delete free_drink_list_history")
|
||||
data = request.get_json()
|
||||
retVal = mainController.delete_free_drink_list_history(data)
|
||||
return jsonify({"ok": retVal})
|
||||
except Exception as err:
|
||||
debug.warning("exception in delete free_dirnk_list_config.", exc_info=True)
|
||||
return jsonify({"error": str(err)}), 500
|
||||
@app.route("/pricelist", methods=['GET'])
|
||||
def _getPricelist():
|
||||
try:
|
||||
|
|
Loading…
Reference in New Issue