Logik für FreeDrinkListHistoryWorkgroup

Es können nun auch Freigetränke mit Grund und Beschreibung des Grundes erstellt werden. Count wird erstmal vernachlässigt.
This commit is contained in:
Tim Gröger 2020-08-20 22:03:43 +02:00
parent 7ac3813782
commit 4a69d54660
3 changed files with 42 additions and 3 deletions

View File

@ -84,7 +84,11 @@ class Base:
def set_free_drink_list_history(self, user, free_drink_list_config): def set_free_drink_list_history(self, user, free_drink_list_config):
try: try:
cursor = self.db.connection.cursor() 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"]})') if 'free_drink_list_reason_id' in free_drink_list_config and 'description' in free_drink_list_config:
sql = f'insert into free_drink_list_history (timestamp, free_drink_config_id, user_id, free_drink_type_id, free_drink_list_reason_id, description) values ("{datetime.now()}", {free_drink_list_config["id"]}, {user.id}, {free_drink_list_config["free_drink_type_id"]}, {free_drink_list_config["free_drink_list_reason_id"]}, "{free_drink_list_config["description"]}")'
else:
sql = 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"]})'
cursor.execute(sql)
self.db.connection.commit() self.db.connection.commit()
return self.get_free_drink_list_history_by_user(user) return self.get_free_drink_list_history_by_user(user)
except Exception as err: except Exception as err:
@ -112,6 +116,7 @@ class Base:
'second': data['timestamp'].second} 'second': data['timestamp'].second}
data['free_drink_config'] = self.get_free_drink_list_config(data['free_drink_config_id']) 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']) data['free_drink_type'] = self.get_free_drink_list_type(data['free_drink_type_id'])
data['free_drink_list_reason'] = self.get_free_drink_list_reason(data['free_drink_list_reason_id']) if data['free_drink_list_reason_id'] else None
return retVal return retVal
except Exception as err: except Exception as err:
traceback.print_exc() traceback.print_exc()
@ -134,6 +139,26 @@ class Base:
cursor.execute(f'delete from free_drink_list_history where id={free_drink_list_history["id"]}') cursor.execute(f'delete from free_drink_list_history where id={free_drink_list_history["id"]}')
self.db.connection.commit() self.db.connection.commit()
return True return True
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_reason(self, id):
try:
cursor = self.db.connection.cursor()
cursor.execute(f'select * from free_drink_list_reason where id={id}')
return cursor.fetchone()
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_reasons(self):
try:
cursor = self.db.connection.cursor()
cursor.execute(f'select * from free_drink_list_reason')
return cursor.fetchall()
except Exception as err: except Exception as err:
traceback.print_exc() traceback.print_exc()
self.db.connection.rollback() self.db.connection.rollback()

View File

@ -22,4 +22,7 @@ class Base:
def update_free_drink_list_history(self, user, data): def update_free_drink_list_history(self, user, data):
db.update_free_drink_list_history(data) db.update_free_drink_list_history(data)
return db.get_free_drink_list_history_by_user(user) return db.get_free_drink_list_history_by_user(user)
def get_free_drink_list_reasons(self):
return db.get_free_drink_list_reasons()

View File

@ -69,6 +69,18 @@ def _delete_free_drink_list_history(**kwargs):
except Exception as err: except Exception as err:
debug.warning("exception in delete free_dirnk_list_config.", exc_info=True) debug.warning("exception in delete free_dirnk_list_config.", exc_info=True)
return jsonify({"error": str(err)}), 500 return jsonify({"error": str(err)}), 500
@app.route("/freeDrinkListReasons", methods=['GET'])
@login_required()
def _free_drink_list_reasons(**kwargs):
try:
debug.info("get free_drink_list_reasons")
retVal = mainController.get_free_drink_list_reasons()
return jsonify(retVal)
except Exception as err:
debug.warning("exception in delete free_dirnk_list_reasons.", exc_info=True)
return jsonify({"error": str(err)}), 500
@app.route("/pricelist", methods=['GET']) @app.route("/pricelist", methods=['GET'])
def _getPricelist(): def _getPricelist():
try: try:
@ -80,7 +92,6 @@ def _getPricelist():
debug.warning("exception in get pricelist.", exc_info=True) debug.warning("exception in get pricelist.", exc_info=True)
return jsonify({"error": str(err)}), 500 return jsonify({"error": str(err)}), 500
@app.route('/drinkTypes', methods=['GET']) @app.route('/drinkTypes', methods=['GET'])
def getTypes(): def getTypes():
try: try: