From 6249b143f1515cc042a7dfd0301bfe39c2fde08a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Mon, 24 Aug 2020 15:19:12 +0200 Subject: [PATCH] =?UTF-8?q?Gr=C3=BCnde=20f=C3=BCr=20Freigetr=C3=A4nke=20k?= =?UTF-8?q?=C3=B6nnen=20erstell=20und=20gel=C3=B6scht=20werden.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Auch modifizieren ist möglich --- .../dbFreeDrinkListConfigController.py | 34 +++++++++++++++++++ .../mainFreeDrinkListConfigController.py | 9 +++++ geruecht/routes.py | 23 +++++++++++-- 3 files changed, 64 insertions(+), 2 deletions(-) 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)