Gründe für Freigetränke können erstell und gelöscht werden.

Auch modifizieren ist möglich
This commit is contained in:
Tim Gröger 2020-08-24 15:19:12 +02:00
parent fe7b81a534
commit 6249b143f1
3 changed files with 64 additions and 2 deletions

View File

@ -220,3 +220,37 @@ class Base:
traceback.print_exc()
self.db.connection.rollback()
raise DatabaseExecption("Something went wrong with Database: {}".format(err))
def set_free_drink_list_reason(self, free_drink_list_reason):
try:
cursor = self.db.connection.cursor()
cursor.execute(f'insert into free_drink_list_reason (name) values ("{free_drink_list_reason["name"]}")')
self.db.connection.commit()
return self.get_free_drink_list_reasons()
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_reason(self, free_drink_list_reason):
try:
cursor = self.db.connection.cursor()
cursor.execute(f'update free_drink_list_reason set name="{free_drink_list_reason["name"]}" where id={free_drink_list_reason["id"]}')
self.db.connection.commit()
return self.get_free_drink_list_reasons()
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_reason(self, free_drink_list_reason):
try:
cursor = self.db.connection.cursor()
cursor.execute(f'update free_drink_list_history set free_drink_list_reason_id=NULL where free_drink_list_reason_id={free_drink_list_reason["id"]}')
cursor.execute(f'delete from free_drink_list_reason where id={free_drink_list_reason["id"]}')
self.db.connection.commit()
return self.get_free_drink_list_reasons()
except Exception as err:
traceback.print_exc()
self.db.connection.rollback()
raise DatabaseExecption("Something went wrong with Database: {}".format(err))

View File

@ -39,5 +39,14 @@ class Base:
def get_free_drink_list_reasons(self):
return db.get_free_drink_list_reasons()
def set_free_drink_list_reason(self, data):
return db.set_free_drink_list_reason(data)
def update_free_drink_list_reason(self, data):
return db.update_free_drink_list_reason(data)
def delete_free_drink_list_reason(self, data):
return db.delete_free_drink_list_reason(data)
def get_free_drink_types(self):
return db.get_free_drink_list_types()

View File

@ -103,12 +103,31 @@ def _delete_free_drink_list_history(**kwargs):
debug.warning("exception in delete free_dirnk_list_config.", exc_info=True)
return jsonify({"error": str(err)}), 500
@app.route("/freeDrinkListReasons", methods=['GET'])
@app.route("/freeDrinkListReasons", methods=['GET', 'POST', 'PUT'])
@login_required()
def _free_drink_list_reasons(**kwargs):
try:
debug.info("get free_drink_list_reasons")
retVal = mainController.get_free_drink_list_reasons()
if request.method == 'GET':
retVal = mainController.get_free_drink_list_reasons()
elif request.method == 'POST' or request.method == 'PUT':
data = request.get_json()
if request.method == 'POST':
retVal = mainController.set_free_drink_list_reason(data)
else:
retVal = mainController.update_free_drink_list_reason(data)
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("/deleteFreeDrinkListReason", methods=['POST'])
@login_required(groups=[VORSTAND])
def __delete_free_drink_list_reason(**kwargs):
try:
debug.info("delete free_drink_list_reason")
data = request.get_json()
retVal = mainController.delete_free_drink_list_reason(data)
return jsonify(retVal)
except Exception as err:
debug.warning("exception in delete free_dirnk_list_reasons.", exc_info=True)