diff --git a/geruecht/controller/databaseController/dbFreeDrinkListConfigController.py b/geruecht/controller/databaseController/dbFreeDrinkListConfigController.py index 1481260..5844e54 100644 --- a/geruecht/controller/databaseController/dbFreeDrinkListConfigController.py +++ b/geruecht/controller/databaseController/dbFreeDrinkListConfigController.py @@ -216,6 +216,40 @@ class Base: cursor = self.db.connection.cursor() cursor.execute(f'select * from free_drink_list_reason') return cursor.fetchall() + 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_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() diff --git a/geruecht/controller/mainController/mainFreeDrinkListConfigController.py b/geruecht/controller/mainController/mainFreeDrinkListConfigController.py index b75af0a..1e8fe9e 100644 --- a/geruecht/controller/mainController/mainFreeDrinkListConfigController.py +++ b/geruecht/controller/mainController/mainFreeDrinkListConfigController.py @@ -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() \ No newline at end of file diff --git a/geruecht/routes.py b/geruecht/routes.py index 625cebd..810b141 100644 --- a/geruecht/routes.py +++ b/geruecht/routes.py @@ -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)