diff --git a/geruecht/controller/databaseController/dbFreeDrinkListConfigController.py b/geruecht/controller/databaseController/dbFreeDrinkListConfigController.py index e17723f..e7a7e3e 100644 --- a/geruecht/controller/databaseController/dbFreeDrinkListConfigController.py +++ b/geruecht/controller/databaseController/dbFreeDrinkListConfigController.py @@ -84,7 +84,11 @@ class Base: def set_free_drink_list_history(self, user, free_drink_list_config): try: 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() return self.get_free_drink_list_history_by_user(user) except Exception as err: @@ -112,6 +116,7 @@ class Base: 'second': data['timestamp'].second} 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_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 except Exception as err: 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"]}') self.db.connection.commit() 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: traceback.print_exc() self.db.connection.rollback() diff --git a/geruecht/controller/mainController/mainFreeDrinkListConfigController.py b/geruecht/controller/mainController/mainFreeDrinkListConfigController.py index 52d5bac..3c999ad 100644 --- a/geruecht/controller/mainController/mainFreeDrinkListConfigController.py +++ b/geruecht/controller/mainController/mainFreeDrinkListConfigController.py @@ -22,4 +22,7 @@ class Base: def update_free_drink_list_history(self, user, data): db.update_free_drink_list_history(data) - return db.get_free_drink_list_history_by_user(user) \ No newline at end of file + return db.get_free_drink_list_history_by_user(user) + + def get_free_drink_list_reasons(self): + return db.get_free_drink_list_reasons() \ No newline at end of file diff --git a/geruecht/routes.py b/geruecht/routes.py index f6fa5da..3135f70 100644 --- a/geruecht/routes.py +++ b/geruecht/routes.py @@ -69,6 +69,18 @@ def _delete_free_drink_list_history(**kwargs): except Exception as err: debug.warning("exception in delete free_dirnk_list_config.", exc_info=True) 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']) def _getPricelist(): try: @@ -80,7 +92,6 @@ def _getPricelist(): debug.warning("exception in get pricelist.", exc_info=True) return jsonify({"error": str(err)}), 500 - @app.route('/drinkTypes', methods=['GET']) def getTypes(): try: