diff --git a/geruecht/controller/databaseController/dbFreeDrinkListConfigController.py b/geruecht/controller/databaseController/dbFreeDrinkListConfigController.py index dbc4738..dabb926 100644 --- a/geruecht/controller/databaseController/dbFreeDrinkListConfigController.py +++ b/geruecht/controller/databaseController/dbFreeDrinkListConfigController.py @@ -156,6 +156,28 @@ class Base: self.db.connection.rollback() raise DatabaseExecption("Something went wrong with Database: {}".format(err)) + def get_free_drink_list_history_from_to(self, from_date, to_date): + try: + cursor = self.db.connection.cursor() + cursor.execute(f'select * from free_drink_list_history where timestamp>="{from_date}" and timestamp<="{to_date}"') + retVal = cursor.fetchall() + for data in retVal: + data['timestamp'] = {'year': data['timestamp'].year, + 'month': data['timestamp'].month, + 'day': data['timestamp'].day, + 'hour': data['timestamp'].hour, + 'minute': data['timestamp'].minute, + '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() + self.db.connection.rollback() + raise DatabaseExecption("Something went wrong with Database: {}".format(err)) + def update_free_drink_list_history(self, free_drink_list_history): try: cursor = self.db.connection.cursor() @@ -166,6 +188,7 @@ class Base: traceback.print_exc() self.db.connection.rollback() raise DatabaseExecption("Something went wrong with Database: {}".format(err)) + def delete_free_drink_list_history(self, free_drink_list_history): try: cursor = self.db.connection.cursor() diff --git a/geruecht/controller/mainController/mainFreeDrinkListConfigController.py b/geruecht/controller/mainController/mainFreeDrinkListConfigController.py index ffcf3e6..b75af0a 100644 --- a/geruecht/controller/mainController/mainFreeDrinkListConfigController.py +++ b/geruecht/controller/mainController/mainFreeDrinkListConfigController.py @@ -1,5 +1,6 @@ import geruecht.controller.databaseController as dc from geruecht.logger import getDebugLogger +from datetime import datetime db = dc.DatabaseController() debug = getDebugLogger() @@ -30,6 +31,11 @@ class Base: db.update_free_drink_list_history(data) return db.get_free_drink_list_history_by_user(user) + def get_free_drink_list_history_from_to(self, data): + from_date = datetime(data["from_date"]["year"], data["from_date"]["month"], data["from_date"]["day"]) + to_date = datetime(data["to_date"]["year"], data["to_date"]["month"], data["to_date"]["day"]) + return db.get_free_drink_list_history_from_to(from_date, to_date) + def get_free_drink_list_reasons(self): return db.get_free_drink_list_reasons() diff --git a/geruecht/routes.py b/geruecht/routes.py index e58a5bf..625cebd 100644 --- a/geruecht/routes.py +++ b/geruecht/routes.py @@ -78,6 +78,19 @@ def _free_drink_list_history(**kwargs): debug.warning("exception in get free_dirnk_list_config.", exc_info=True) return jsonify({"error": str(err)}), 500 +@app.route("/freeDrinkListHistoryFromTo", methods=['POST']) +@login_required(groups=[VORSTAND]) +def _free_drink_list_history_from_to(**kwargs): + try: + debug.info("get free_drink_list_history") + data = request.get_json() + retVal = mainController.get_free_drink_list_history_from_to(data) + debug.debug(f'return free_drink_list_history {{{retVal}}}') + return jsonify(retVal) + except Exception as err: + debug.warning("exception in get free_dirnk_list_history.", exc_info=True) + return jsonify({"error": str(err)}), 500 + @app.route("/deleteDrinkListHistory", methods=['POST']) @login_required() def _delete_free_drink_list_history(**kwargs):