From c1c34376824500fbfbf42d2bbee6f3b28c3b02cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Thu, 20 Aug 2020 08:37:24 +0200 Subject: [PATCH 1/9] =?UTF-8?q?FreeDrinkList=20f=C3=BCr=20Bardienste=20und?= =?UTF-8?q?=20AG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Es wurde die komplette backendverwaltung für Freigetränke Band und AG hinzugefügt. Es gibt auch schon ansätze für das Interface um Freigetränke zu bearbeiten. --- .../controller/databaseController/__init__.py | 3 +- .../dbFreeDrinkListConfigController.py | 136 ++++++++++++++++++ .../dbPricelistController.py | 8 +- .../databaseController/dbWorkerController.py | 2 +- .../controller/mainController/__init__.py | 3 +- .../mainFreeDrinkListConfigController.py | 25 ++++ geruecht/routes.py | 43 ++++++ 7 files changed, 216 insertions(+), 4 deletions(-) create mode 100644 geruecht/controller/databaseController/dbFreeDrinkListConfigController.py create mode 100644 geruecht/controller/mainController/mainFreeDrinkListConfigController.py diff --git a/geruecht/controller/databaseController/__init__.py b/geruecht/controller/databaseController/__init__.py index 8f783fd..e53e75b 100644 --- a/geruecht/controller/databaseController/__init__.py +++ b/geruecht/controller/databaseController/__init__.py @@ -1,6 +1,6 @@ from ..mainController import Singleton from geruecht import db -from ..databaseController import dbUserController, dbCreditListController, dbJobKindController, dbPricelistController, dbWorkerController, dbWorkgroupController, dbJobInviteController, dbJobRequesController, dbAccessTokenController, dbRegistrationController +from ..databaseController import dbUserController, dbCreditListController, dbJobKindController, dbPricelistController, dbWorkerController, dbWorkgroupController, dbJobInviteController, dbJobRequesController, dbAccessTokenController, dbRegistrationController, dbFreeDrinkListConfigController from geruecht.exceptions import DatabaseExecption import traceback from MySQLdb._exceptions import IntegrityError @@ -15,6 +15,7 @@ class DatabaseController(dbUserController.Base, dbJobRequesController.Base, dbAccessTokenController.Base, dbRegistrationController.Base, + dbFreeDrinkListConfigController.Base, metaclass=Singleton): ''' DatabaesController diff --git a/geruecht/controller/databaseController/dbFreeDrinkListConfigController.py b/geruecht/controller/databaseController/dbFreeDrinkListConfigController.py new file mode 100644 index 0000000..dd7a7ab --- /dev/null +++ b/geruecht/controller/databaseController/dbFreeDrinkListConfigController.py @@ -0,0 +1,136 @@ +import traceback +from datetime import datetime +from datetime import timedelta +from geruecht.exceptions import DatabaseExecption + +class Base: + def get_free_drink_list_config(self, id): + try: + cursor = self.db.connection.cursor() + cursor.execute(f'select * from free_drink_list_config where id={id}') + data = cursor.fetchone() + if data['drink_id'] != None: + data['drink'] = self.getDrinkPrice(data['drink_id']) + data['free_drink_types'] = self.get_free_drink_list_types_for_drink(data['id']) + return data + 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_configs(self): + try: + cursor = self.db.connection.cursor() + cursor.execute("select * from free_drink_list_config") + retVal = cursor.fetchall() + for data in retVal: + if data['drink_id'] != None: + data['drink'] = self.getDrinkPrice(data['drink_id']) + data['free_drink_types'] = self.get_free_drink_list_types_for_drink(data['id']) + + return retVal + 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_config(self, free_drink_list_config): + try: + cursor = self.db.connection.cursor() + cursor.execute(f'insert into free_drink_list_config (drink_id, label, price) values ({free_drink_list_config["drink"]["id"]}, "{free_drink_list_config["label"]}", {free_drink_list_config["price"]})') + self.db.connection.commit() + return self.get_free_drink_list_configs() + 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_types(self): + try: + cursor = self.db.connection.cursor() + cursor.execute('select * from free_drink_list_type') + return cursor.fetchall() + 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_types_for_drink(self, id): + try: + cursor = self.db.connection.cursor() + cursor.execute(f'select a.* from free_drink_list_type a, free_drink_list_type_config b where free_drink_list_config_id={id} and b.free_drink_list_type_id=a.id') + return cursor.fetchall() + 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_type(self, name): + try: + cursor = self.db.connection.cursor() + if type(name) == str: + sql = f'select * from free_drink_list_type where name={name}' + elif type(name) == int: + sql = f'select * from free_drink_list_type where id={name}' + else: + raise DatabaseExecption("name as no type int or str. name={}, type={}".format(name, type(name))) + cursor.execute(sql) + return cursor.fetchone() + 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_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"]})') + self.db.connection.commit() + return self.get_free_drink_list_history_by_user(user) + 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_history_by_user(self, user): + try: + cursor = self.db.connection.cursor() + now = datetime.now() + worker = self.getWorker(user, now) + cursor.execute(f'select * from free_drink_list_history where timestamp>="{worker["startdatetime"]}" and user_id={user.id}') + 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']) + 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() + cursor.execute(f'update free_drink_list_history set canceled={free_drink_list_history["canceled"]} 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 delete_free_drink_list_history(self, free_drink_list_history): + try: + cursor = self.db.connection.cursor() + 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)) \ No newline at end of file diff --git a/geruecht/controller/databaseController/dbPricelistController.py b/geruecht/controller/databaseController/dbPricelistController.py index 2b0c749..7d00117 100644 --- a/geruecht/controller/databaseController/dbPricelistController.py +++ b/geruecht/controller/databaseController/dbPricelistController.py @@ -8,6 +8,9 @@ class Base: try: cursor = self.db.connection.cursor() cursor.execute("select * from pricelist") + retVal = cursor.fetchall() + for data in retVal: + data['drink_type'] = self.getDrinkType(data['type']) return cursor.fetchall() except Exception as err: traceback.print_exc() @@ -24,7 +27,10 @@ class Base: else: raise DatabaseExecption("name as no type int or str. name={}, type={}".format(name, type(name))) cursor.execute(sql) - return cursor.fetchone() + retVal = cursor.fetchone() + if retVal: + retVal['drink_type'] = self.getDrinkType(retVal['type']) + return retVal except Exception as err: traceback.print_exc() self.db.connection.rollback() diff --git a/geruecht/controller/databaseController/dbWorkerController.py b/geruecht/controller/databaseController/dbWorkerController.py index 3d7652d..c54f16d 100644 --- a/geruecht/controller/databaseController/dbWorkerController.py +++ b/geruecht/controller/databaseController/dbWorkerController.py @@ -8,7 +8,7 @@ class Base: def getWorker(self, user, date): try: cursor = self.db.connection.cursor() - cursor.execute("select * from bardienste where user_id={} and startdatetime='{}'".format(user.id, date)) + cursor.execute("select * from bardienste where user_id={} and startdatetime<='{}' and enddatetime>='{}'".format(user.id, date, date)) data = cursor.fetchone() return {"user": user.toJSON(), "startdatetime": data['startdatetime'], "enddatetime": data['enddatetime'], "start": { "year": data['startdatetime'].year, "month": data['startdatetime'].month, "day": data['startdatetime'].day}, "job_kind": self.getJobKind(data['job_kind']) if data['job_kind'] != None else None} if data else None except Exception as err: diff --git a/geruecht/controller/mainController/__init__.py b/geruecht/controller/mainController/__init__.py index ae3f73a..aabd653 100644 --- a/geruecht/controller/mainController/__init__.py +++ b/geruecht/controller/mainController/__init__.py @@ -5,7 +5,7 @@ import geruecht.controller.emailController as ec from geruecht.model.user import User from datetime import datetime, timedelta from geruecht.logger import getDebugLogger -from ..mainController import mainJobKindController, mainCreditListController, mainPricelistController, mainUserController, mainWorkerController, mainWorkgroupController, mainJobInviteController, mainJobRequestController, mainRegistrationController, mainPasswordReset +from ..mainController import mainJobKindController, mainCreditListController, mainPricelistController, mainUserController, mainWorkerController, mainWorkgroupController, mainJobInviteController, mainJobRequestController, mainRegistrationController, mainPasswordReset, mainFreeDrinkListConfigController db = dc.DatabaseController() ldap = lc.LDAPController() @@ -24,6 +24,7 @@ class MainController(mainJobKindController.Base, mainJobRequestController.Base, mainRegistrationController.Base, mainPasswordReset.Base, + mainFreeDrinkListConfigController.Base, metaclass=Singleton): def __init__(self): diff --git a/geruecht/controller/mainController/mainFreeDrinkListConfigController.py b/geruecht/controller/mainController/mainFreeDrinkListConfigController.py new file mode 100644 index 0000000..52d5bac --- /dev/null +++ b/geruecht/controller/mainController/mainFreeDrinkListConfigController.py @@ -0,0 +1,25 @@ +import geruecht.controller.databaseController as dc +from geruecht.logger import getDebugLogger + +db = dc.DatabaseController() +debug = getDebugLogger() + +class Base: + def get_free_drink_list_configs(self): + return db.get_free_drink_list_configs() + + def set_free_drink_list_config(self, data): + return db.set_free_drink_list_config(data) + + def set_free_drink_list_history(self, user, data): + return db.set_free_drink_list_history(user, data) + + def get_free_drink_list_history(self, user): + return db.get_free_drink_list_history_by_user(user) + + def delete_free_drink_list_history(self, data): + return db.delete_free_drink_list_history(data) + + 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 diff --git a/geruecht/routes.py b/geruecht/routes.py index 07b78ce..f6fa5da 100644 --- a/geruecht/routes.py +++ b/geruecht/routes.py @@ -26,6 +26,49 @@ def _valid(**kwargs): debug.warning("exception in valide.", exc_info=True) return jsonify({"error": str(err)}), 500 +@app.route("/freeDrinkListConfig", methods=['GET']) +@login_required() +def _free_drink_list_config(**kwargs): + try: + debug.info("get free_drink_list_config") + retVal = mainController.get_free_drink_list_configs() + debug.info("return free_drink_list_config {{ {} }}".format(retVal)) + return jsonify(retVal) + except Exception as err: + debug.warning("exception in get free_dirnk_list_config.", exc_info=True) + return jsonify({"error": str(err)}), 500 + +@app.route("/freeDrinkListHistory", methods=['GET', 'POST', 'PUT']) +@login_required() +def _free_drink_list_history(**kwargs): + try: + debug.info("set free_drink_list_history") + user = kwargs['accToken'].user + if request.method == 'GET': + retVal = mainController.get_free_drink_list_history(user) + if request.method == 'POST' or request.method == 'PUT': + data = request.get_json() + if request.method == 'POST': + retVal = mainController.set_free_drink_list_history(user, data) + else: + retVal = mainController.update_free_drink_list_history(user, 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_config.", exc_info=True) + return jsonify({"error": str(err)}), 500 + +@app.route("/deleteDrinkListHistory", methods=['POST']) +@login_required() +def _delete_free_drink_list_history(**kwargs): + try: + debug.info("delete free_drink_list_history") + data = request.get_json() + retVal = mainController.delete_free_drink_list_history(data) + return jsonify({"ok": retVal}) + except Exception as err: + debug.warning("exception in delete free_dirnk_list_config.", exc_info=True) + return jsonify({"error": str(err)}), 500 @app.route("/pricelist", methods=['GET']) def _getPricelist(): try: From e5d2de4d35f914ed0bf6bede0e1938f31bb25602 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Thu, 20 Aug 2020 11:35:42 +0200 Subject: [PATCH 2/9] =?UTF-8?q?Canceld=20FreeDrinks=20hinzugef=C3=BCgt=20u?= =?UTF-8?q?nd=20Bugfix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit FreeDrinksListHistory haben jetzt auch canceld in dem steht ob das getränk storniert wurde oder nicht. Außerdem werden die Bandfreigetränke nicht per User sondern für alle Dienste rausgesucht --- .../databaseController/dbFreeDrinkListConfigController.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/geruecht/controller/databaseController/dbFreeDrinkListConfigController.py b/geruecht/controller/databaseController/dbFreeDrinkListConfigController.py index dd7a7ab..269179c 100644 --- a/geruecht/controller/databaseController/dbFreeDrinkListConfigController.py +++ b/geruecht/controller/databaseController/dbFreeDrinkListConfigController.py @@ -97,7 +97,7 @@ class Base: cursor = self.db.connection.cursor() now = datetime.now() worker = self.getWorker(user, now) - cursor.execute(f'select * from free_drink_list_history where timestamp>="{worker["startdatetime"]}" and user_id={user.id}') + cursor.execute(f'select * from free_drink_list_history where timestamp>="{worker["startdatetime"]}" and (user_id={user.id} or free_drink_type_id=3)') retVal = cursor.fetchall() for data in retVal: data['timestamp'] = {'year': data['timestamp'].year, From 7ac3813782cb6a8fb4876d920947866c6097e829 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Thu, 20 Aug 2020 20:17:35 +0200 Subject: [PATCH 3/9] bugfix, free_drink_list_history wenn kein dienst Sollte der user, der diese liste abruft keinen dienst haben, wird nur die history der letzten halben stunde abgerufen --- .../databaseController/dbFreeDrinkListConfigController.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/geruecht/controller/databaseController/dbFreeDrinkListConfigController.py b/geruecht/controller/databaseController/dbFreeDrinkListConfigController.py index 269179c..e17723f 100644 --- a/geruecht/controller/databaseController/dbFreeDrinkListConfigController.py +++ b/geruecht/controller/databaseController/dbFreeDrinkListConfigController.py @@ -97,7 +97,11 @@ class Base: cursor = self.db.connection.cursor() now = datetime.now() worker = self.getWorker(user, now) - cursor.execute(f'select * from free_drink_list_history where timestamp>="{worker["startdatetime"]}" and (user_id={user.id} or free_drink_type_id=3)') + if worker: + timestamp = worker["startdatetime"] + else: + timestamp = datetime.now() - timedelta(minutes=30) + cursor.execute(f'select * from free_drink_list_history where timestamp>="{timestamp}" and (user_id={user.id} or free_drink_type_id=3)') retVal = cursor.fetchall() for data in retVal: data['timestamp'] = {'year': data['timestamp'].year, From 4a69d546605ff823bdf12b684f515a6bc7efc850 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Thu, 20 Aug 2020 22:03:43 +0200 Subject: [PATCH 4/9] =?UTF-8?q?Logik=20f=C3=BCr=20FreeDrinkListHistoryWork?= =?UTF-8?q?group?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Es können nun auch Freigetränke mit Grund und Beschreibung des Grundes erstellt werden. Count wird erstmal vernachlässigt. --- .../dbFreeDrinkListConfigController.py | 27 ++++++++++++++++++- .../mainFreeDrinkListConfigController.py | 5 +++- geruecht/routes.py | 13 ++++++++- 3 files changed, 42 insertions(+), 3 deletions(-) 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: From 2f2fdacca225ce4692dc656aae3c241d65f06633 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Fri, 21 Aug 2020 21:59:39 +0200 Subject: [PATCH 5/9] Get FreeDrinkTypes und Bugfix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Alle Freigetränktypen können nun geladen werden. Es wurde ein Bug gefixed, sodass die Preisliste wieder geladen werden kann. --- .../databaseController/dbPricelistController.py | 2 +- .../mainFreeDrinkListConfigController.py | 5 ++++- geruecht/routes.py | 11 +++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/geruecht/controller/databaseController/dbPricelistController.py b/geruecht/controller/databaseController/dbPricelistController.py index 7d00117..11f23d1 100644 --- a/geruecht/controller/databaseController/dbPricelistController.py +++ b/geruecht/controller/databaseController/dbPricelistController.py @@ -11,7 +11,7 @@ class Base: retVal = cursor.fetchall() for data in retVal: data['drink_type'] = self.getDrinkType(data['type']) - return cursor.fetchall() + return retVal 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 3c999ad..ac271e5 100644 --- a/geruecht/controller/mainController/mainFreeDrinkListConfigController.py +++ b/geruecht/controller/mainController/mainFreeDrinkListConfigController.py @@ -25,4 +25,7 @@ class Base: 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 + return db.get_free_drink_list_reasons() + + 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 3135f70..2208f94 100644 --- a/geruecht/routes.py +++ b/geruecht/routes.py @@ -81,6 +81,17 @@ def _free_drink_list_reasons(**kwargs): debug.warning("exception in delete free_dirnk_list_reasons.", exc_info=True) return jsonify({"error": str(err)}), 500 +@app.route("/freeDrinkTypes", methods=['GET', 'POST']) +@login_required() +def _free_drink_types(**kwargs): + try: + debug.info("get free_drnik_types") + retVal = mainController.get_free_drink_types() + return jsonify(retVal) + except Exception as err: + debug.warning("exception in free_dirnk_types.", exc_info=True) + return jsonify({"error": str(err)}), 500 + @app.route("/pricelist", methods=['GET']) def _getPricelist(): try: From fa5097da108fecb645d7cecaedd8f3c364a59212 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Sun, 23 Aug 2020 21:14:43 +0200 Subject: [PATCH 6/9] =?UTF-8?q?L=C3=B6schen=20und=20modifizieren=20von=20F?= =?UTF-8?q?reigetr=C3=A4nken?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Der Vorstand hat nun die Möglichkeit Freigetränke zu löschen oder zu ändern. Beim Löschen wird auch der gesamte Verlauf dieses Freigetränks gelöscht. --- .../dbFreeDrinkListConfigController.py | 33 +++++++++++++++++++ .../mainFreeDrinkListConfigController.py | 6 ++++ geruecht/routes.py | 24 ++++++++++++-- 3 files changed, 61 insertions(+), 2 deletions(-) diff --git a/geruecht/controller/databaseController/dbFreeDrinkListConfigController.py b/geruecht/controller/databaseController/dbFreeDrinkListConfigController.py index e7a7e3e..dbc4738 100644 --- a/geruecht/controller/databaseController/dbFreeDrinkListConfigController.py +++ b/geruecht/controller/databaseController/dbFreeDrinkListConfigController.py @@ -39,6 +39,39 @@ class Base: cursor = self.db.connection.cursor() cursor.execute(f'insert into free_drink_list_config (drink_id, label, price) values ({free_drink_list_config["drink"]["id"]}, "{free_drink_list_config["label"]}", {free_drink_list_config["price"]})') self.db.connection.commit() + cursor.execute(f'select id from free_drink_list_config where drink_id={free_drink_list_config["drink"]["id"]} and label="{free_drink_list_config["label"]}" and price={free_drink_list_config["price"]}') + data = cursor.fetchone() + for free_drink_type in free_drink_list_config["free_drink_types"]: + cursor.execute( + f'insert into free_drink_list_type_config (free_drink_list_config_id, free_drink_list_type_id) values ({data["id"]},{free_drink_type["id"]})') + self.db.connection.commit() + return self.get_free_drink_list_configs() + 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_config(self, free_drink_list_config): + try: + cursor = self.db.connection.cursor() + cursor.execute(f'update free_drink_list_config set drink_id={free_drink_list_config["drink"]["id"]}, label="{free_drink_list_config["label"]}", price={free_drink_list_config["price"]} where id={free_drink_list_config["id"]}') + cursor.execute(f'delete from free_drink_list_type_config where free_drink_list_config_id={free_drink_list_config["id"]}') + for free_drink_type in free_drink_list_config["free_drink_types"]: + cursor.execute(f'insert into free_drink_list_type_config (free_drink_list_config_id, free_drink_list_type_id) values ({free_drink_list_config["id"]},{free_drink_type["id"]})') + self.db.connection.commit() + return self.get_free_drink_list_configs() + 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_config(self, free_drink_list_config): + try: + cursor = self.db.connection.cursor() + cursor.execute(f'delete from free_drink_list_type_config where free_drink_list_config_id={free_drink_list_config["id"]}') + cursor.execute(f'delete from free_drink_list_history where free_drink_config_id={free_drink_list_config["id"]}') + cursor.execute(f'delete from free_drink_list_config where id={free_drink_list_config["id"]}') + self.db.connection.commit() return self.get_free_drink_list_configs() except Exception as err: traceback.print_exc() diff --git a/geruecht/controller/mainController/mainFreeDrinkListConfigController.py b/geruecht/controller/mainController/mainFreeDrinkListConfigController.py index ac271e5..ffcf3e6 100644 --- a/geruecht/controller/mainController/mainFreeDrinkListConfigController.py +++ b/geruecht/controller/mainController/mainFreeDrinkListConfigController.py @@ -11,6 +11,12 @@ class Base: def set_free_drink_list_config(self, data): return db.set_free_drink_list_config(data) + def update_free_drink_list_config(self, data): + return db.update_free_drink_list_config(data) + + def delete_free_drink_list_config(self, data): + return db.delete_free_drink_list_config(data) + def set_free_drink_list_history(self, user, data): return db.set_free_drink_list_history(user, data) diff --git a/geruecht/routes.py b/geruecht/routes.py index 2208f94..e58a5bf 100644 --- a/geruecht/routes.py +++ b/geruecht/routes.py @@ -26,18 +26,38 @@ def _valid(**kwargs): debug.warning("exception in valide.", exc_info=True) return jsonify({"error": str(err)}), 500 -@app.route("/freeDrinkListConfig", methods=['GET']) +@app.route("/freeDrinkListConfig", methods=['GET', 'POST', 'PUT']) @login_required() def _free_drink_list_config(**kwargs): try: debug.info("get free_drink_list_config") - retVal = mainController.get_free_drink_list_configs() + if request.method == 'GET': + retVal = mainController.get_free_drink_list_configs() + if request.method == 'POST': + data = request.get_json() + retVal = mainController.set_free_drink_list_config(data) + if request.method == 'PUT': + data = request.get_json() + retVal = mainController.update_free_drink_list_config(data) debug.info("return free_drink_list_config {{ {} }}".format(retVal)) return jsonify(retVal) except Exception as err: debug.warning("exception in get free_dirnk_list_config.", exc_info=True) return jsonify({"error": str(err)}), 500 +@app.route("/deleteFreeDrinkListConfig", methods=['POST']) +@login_required() +def _delete_free_drink_list_config(**kwargs): + try: + debug.info("delete free_drink_list_config") + data = request.get_json() + retVal = mainController.delete_free_drink_list_config(data) + debug.info("return delete_free_drink_list_config {{ {} }}".format(retVal)) + return jsonify(retVal) + except Exception as err: + debug.warning("exception in delete_free_dirnk_list_config.", exc_info=True) + return jsonify({"error": str(err)}), 500 + @app.route("/freeDrinkListHistory", methods=['GET', 'POST', 'PUT']) @login_required() def _free_drink_list_history(**kwargs): From 1f5eb0be9d5c5f3805bece508505d8a806f9c1cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Sun, 23 Aug 2020 23:17:12 +0200 Subject: [PATCH 7/9] FreeDrinkHistory in einem Zeitraumen bekommen MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Der Vorstand kann nun in einem bestimmten Zeitraum alle Freigetränke abrufen. --- .../dbFreeDrinkListConfigController.py | 23 +++++++++++++++++++ .../mainFreeDrinkListConfigController.py | 6 +++++ geruecht/routes.py | 13 +++++++++++ 3 files changed, 42 insertions(+) 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): From fe7b81a5349b6f5c311d92d24b56de72dfc84f4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Mon, 24 Aug 2020 14:05:50 +0200 Subject: [PATCH 8/9] =?UTF-8?q?Users=20f=C3=BCr=20FreeDrinkListHistory?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Der User wird mit gesenden, wenn man die FreeDrinkListHistory abruft. Dabei wurde die Funktion des Users angepasst, dass nicht ständig, das komplette Gerücht neu initialisiert wird. --- .../databaseController/dbFreeDrinkListConfigController.py | 1 + geruecht/controller/databaseController/dbUserController.py | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/geruecht/controller/databaseController/dbFreeDrinkListConfigController.py b/geruecht/controller/databaseController/dbFreeDrinkListConfigController.py index dabb926..1481260 100644 --- a/geruecht/controller/databaseController/dbFreeDrinkListConfigController.py +++ b/geruecht/controller/databaseController/dbFreeDrinkListConfigController.py @@ -172,6 +172,7 @@ class Base: 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 + data['user'] = self.getUserById(data['user_id'], workgroups=False, geruecht=False).toJSON() return retVal except Exception as err: traceback.print_exc() diff --git a/geruecht/controller/databaseController/dbUserController.py b/geruecht/controller/databaseController/dbUserController.py index 3e419d4..4c1dd1c 100644 --- a/geruecht/controller/databaseController/dbUserController.py +++ b/geruecht/controller/databaseController/dbUserController.py @@ -48,7 +48,7 @@ class Base: self.db.connection.rollback() raise DatabaseExecption("Something went worng with Datatabase: {}".format(err)) - def getUserById(self, id, workgroups=True): + def getUserById(self, id, workgroups=True, geruecht=True): try: retVal = None cursor = self.db.connection.cursor() @@ -56,8 +56,9 @@ class Base: data = cursor.fetchone() if data: retVal = User(data) - creditLists = self.getCreditListFromUser(retVal) - retVal.initGeruechte(creditLists) + if geruecht: + creditLists = self.getCreditListFromUser(retVal) + retVal.initGeruechte(creditLists) if workgroups: retVal.workgroups = self.getWorkgroupsOfUser(retVal.id) return retVal 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 9/9] =?UTF-8?q?Gr=C3=BCnde=20f=C3=BCr=20Freigetr=C3=A4nke?= =?UTF-8?q?=20k=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)