Löschen und modifizieren von Freigetränken

Der Vorstand hat nun die Möglichkeit Freigetränke zu löschen oder zu ändern. Beim Löschen wird auch der gesamte Verlauf dieses Freigetränks gelöscht.
This commit is contained in:
Tim Gröger 2020-08-23 21:14:43 +02:00
parent 2f2fdacca2
commit fa5097da10
3 changed files with 61 additions and 2 deletions

View File

@ -39,6 +39,39 @@ class Base:
cursor = self.db.connection.cursor() 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"]})') 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() self.db.connection.commit()
cursor.execute(f'select id from free_drink_list_config where drink_id={free_drink_list_config["drink"]["id"]} and label="{free_drink_list_config["label"]}" and price={free_drink_list_config["price"]}')
data = cursor.fetchone()
for free_drink_type in free_drink_list_config["free_drink_types"]:
cursor.execute(
f'insert into free_drink_list_type_config (free_drink_list_config_id, free_drink_list_type_id) values ({data["id"]},{free_drink_type["id"]})')
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 update_free_drink_list_config(self, free_drink_list_config):
try:
cursor = self.db.connection.cursor()
cursor.execute(f'update free_drink_list_config set drink_id={free_drink_list_config["drink"]["id"]}, label="{free_drink_list_config["label"]}", price={free_drink_list_config["price"]} where id={free_drink_list_config["id"]}')
cursor.execute(f'delete from free_drink_list_type_config where free_drink_list_config_id={free_drink_list_config["id"]}')
for free_drink_type in free_drink_list_config["free_drink_types"]:
cursor.execute(f'insert into free_drink_list_type_config (free_drink_list_config_id, free_drink_list_type_id) values ({free_drink_list_config["id"]},{free_drink_type["id"]})')
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 delete_free_drink_list_config(self, free_drink_list_config):
try:
cursor = self.db.connection.cursor()
cursor.execute(f'delete from free_drink_list_type_config where free_drink_list_config_id={free_drink_list_config["id"]}')
cursor.execute(f'delete from free_drink_list_history where free_drink_config_id={free_drink_list_config["id"]}')
cursor.execute(f'delete from free_drink_list_config where id={free_drink_list_config["id"]}')
self.db.connection.commit()
return self.get_free_drink_list_configs() return self.get_free_drink_list_configs()
except Exception as err: except Exception as err:
traceback.print_exc() traceback.print_exc()

View File

@ -11,6 +11,12 @@ class Base:
def set_free_drink_list_config(self, data): def set_free_drink_list_config(self, data):
return db.set_free_drink_list_config(data) return db.set_free_drink_list_config(data)
def update_free_drink_list_config(self, data):
return db.update_free_drink_list_config(data)
def delete_free_drink_list_config(self, data):
return db.delete_free_drink_list_config(data)
def set_free_drink_list_history(self, user, data): def set_free_drink_list_history(self, user, data):
return db.set_free_drink_list_history(user, data) return db.set_free_drink_list_history(user, data)

View File

@ -26,18 +26,38 @@ def _valid(**kwargs):
debug.warning("exception in valide.", exc_info=True) debug.warning("exception in valide.", exc_info=True)
return jsonify({"error": str(err)}), 500 return jsonify({"error": str(err)}), 500
@app.route("/freeDrinkListConfig", methods=['GET']) @app.route("/freeDrinkListConfig", methods=['GET', 'POST', 'PUT'])
@login_required() @login_required()
def _free_drink_list_config(**kwargs): def _free_drink_list_config(**kwargs):
try: try:
debug.info("get free_drink_list_config") debug.info("get free_drink_list_config")
if request.method == 'GET':
retVal = mainController.get_free_drink_list_configs() retVal = mainController.get_free_drink_list_configs()
if request.method == 'POST':
data = request.get_json()
retVal = mainController.set_free_drink_list_config(data)
if request.method == 'PUT':
data = request.get_json()
retVal = mainController.update_free_drink_list_config(data)
debug.info("return free_drink_list_config {{ {} }}".format(retVal)) debug.info("return free_drink_list_config {{ {} }}".format(retVal))
return jsonify(retVal) return jsonify(retVal)
except Exception as err: except Exception as err:
debug.warning("exception in get free_dirnk_list_config.", exc_info=True) debug.warning("exception in get free_dirnk_list_config.", exc_info=True)
return jsonify({"error": str(err)}), 500 return jsonify({"error": str(err)}), 500
@app.route("/deleteFreeDrinkListConfig", methods=['POST'])
@login_required()
def _delete_free_drink_list_config(**kwargs):
try:
debug.info("delete free_drink_list_config")
data = request.get_json()
retVal = mainController.delete_free_drink_list_config(data)
debug.info("return delete_free_drink_list_config {{ {} }}".format(retVal))
return jsonify(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("/freeDrinkListHistory", methods=['GET', 'POST', 'PUT']) @app.route("/freeDrinkListHistory", methods=['GET', 'POST', 'PUT'])
@login_required() @login_required()
def _free_drink_list_history(**kwargs): def _free_drink_list_history(**kwargs):