From 77931a48c6fe5683d191c35d5f9035a16fb40794 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Sun, 23 Feb 2020 11:18:54 +0100 Subject: [PATCH 1/8] finished ##188 for sm only send year, month, day. But you have to decrement month to send, because month starts with 0. Also you have to increment month to get. --- geruecht/controller/databaseController.py | 4 ++-- geruecht/user/routes.py | 5 ++++- geruecht/vorstand/routes.py | 15 ++++++++++++--- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/geruecht/controller/databaseController.py b/geruecht/controller/databaseController.py index 3666374..fe84080 100644 --- a/geruecht/controller/databaseController.py +++ b/geruecht/controller/databaseController.py @@ -132,14 +132,14 @@ class DatabaseController(metaclass=Singleton): cursor = self.db.connection.cursor() cursor.execute("select * from bardienste where user_id={} and startdatetime='{}'".format(user.id, date)) data = cursor.fetchone() - return {"user": user.toJSON(), "startdatetime": data['startdatetime'], "enddatetime": data['enddatetime']} if data else None + return {"user": user.toJSON(), "startdatetime": data['startdatetime'], "enddatetime": data['enddatetime'], "start": { "year": data['startdatetime'].year, "month": data['startdatetime'].month, "day": data['startdatetime'].day}} if data else None def getWorkers(self, date): cursor = self.db.connection.cursor() cursor.execute("select * from bardienste where startdatetime='{}'".format(date)) data = cursor.fetchall() - return [{"user": self.getUserById(work['user_id']).toJSON(), "startdatetime": work['startdatetime'], "enddatetime": work['enddatetime']} for work in data] + return [{"user": self.getUserById(work['user_id']).toJSON(), "startdatetime": work['startdatetime'], "enddatetime": work['enddatetime'], "start": { "year": work['startdatetime'].year, "month": work['startdatetime'].month, "day": work['startdatetime'].day}} for work in data] def setWorker(self, user, date): diff --git a/geruecht/user/routes.py b/geruecht/user/routes.py index 11cb669..b1af021 100644 --- a/geruecht/user/routes.py +++ b/geruecht/user/routes.py @@ -55,7 +55,10 @@ def _saveConfig(**kwargs): @login_required(groups=[USER]) def _getUser(**kwargs): data = request.get_json() - date = datetime.utcfromtimestamp(int(data['date'])) + day = data['day'] + month = data['month'] + year = data['year'] + date = datetime(year, month, day, 12) retVal = userController.getWorker(date) print(retVal) return jsonify(retVal) \ No newline at end of file diff --git a/geruecht/vorstand/routes.py b/geruecht/vorstand/routes.py index 35e375b..a420330 100644 --- a/geruecht/vorstand/routes.py +++ b/geruecht/vorstand/routes.py @@ -18,7 +18,10 @@ def _addUser(**kwargs): data = request.get_json() user = data['user'] - date = datetime.utcfromtimestamp(int(data['date'])) + day = data['day'] + month = data['month'] + year = data['year'] + date = datetime(year,month,day,12) retVal = userController.addWorker(user['username'], date) print(retVal) return jsonify(retVal) @@ -27,7 +30,10 @@ def _addUser(**kwargs): @login_required(groups=[MONEY, GASTRO]) def _getUser(**kwargs): data = request.get_json() - date = datetime.utcfromtimestamp(int(data['date'])) + day = data['day'] + month = data['month'] + year = data['year'] + date = datetime(year, month, day, 12) retVal = userController.getWorker(date) print(retVal) return jsonify(retVal) @@ -37,6 +43,9 @@ def _getUser(**kwargs): def _deletUser(**kwargs): data = request.get_json() user = data['user'] - date = datetime.utcfromtimestamp(int(data['date'])) + day = data['day'] + month = data['month'] + year = data['year'] + date = datetime(year, month, day, 12) userController.deleteWorker(user['username'], date) return jsonify({"ok": "ok"}) \ No newline at end of file From 9a5c7e83669a146cdf4112297feb4cb54b925ea4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Sun, 23 Feb 2020 11:18:54 +0100 Subject: [PATCH 2/8] finished ##188 update routes in vorstand and user. You have to Parse day, month, and year. Datetime ist set to 12 o'clock --- geruecht/controller/databaseController.py | 4 ++-- geruecht/user/routes.py | 5 ++++- geruecht/vorstand/routes.py | 15 ++++++++++++--- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/geruecht/controller/databaseController.py b/geruecht/controller/databaseController.py index 3666374..fe84080 100644 --- a/geruecht/controller/databaseController.py +++ b/geruecht/controller/databaseController.py @@ -132,14 +132,14 @@ class DatabaseController(metaclass=Singleton): cursor = self.db.connection.cursor() cursor.execute("select * from bardienste where user_id={} and startdatetime='{}'".format(user.id, date)) data = cursor.fetchone() - return {"user": user.toJSON(), "startdatetime": data['startdatetime'], "enddatetime": data['enddatetime']} if data else None + return {"user": user.toJSON(), "startdatetime": data['startdatetime'], "enddatetime": data['enddatetime'], "start": { "year": data['startdatetime'].year, "month": data['startdatetime'].month, "day": data['startdatetime'].day}} if data else None def getWorkers(self, date): cursor = self.db.connection.cursor() cursor.execute("select * from bardienste where startdatetime='{}'".format(date)) data = cursor.fetchall() - return [{"user": self.getUserById(work['user_id']).toJSON(), "startdatetime": work['startdatetime'], "enddatetime": work['enddatetime']} for work in data] + return [{"user": self.getUserById(work['user_id']).toJSON(), "startdatetime": work['startdatetime'], "enddatetime": work['enddatetime'], "start": { "year": work['startdatetime'].year, "month": work['startdatetime'].month, "day": work['startdatetime'].day}} for work in data] def setWorker(self, user, date): diff --git a/geruecht/user/routes.py b/geruecht/user/routes.py index 11cb669..b1af021 100644 --- a/geruecht/user/routes.py +++ b/geruecht/user/routes.py @@ -55,7 +55,10 @@ def _saveConfig(**kwargs): @login_required(groups=[USER]) def _getUser(**kwargs): data = request.get_json() - date = datetime.utcfromtimestamp(int(data['date'])) + day = data['day'] + month = data['month'] + year = data['year'] + date = datetime(year, month, day, 12) retVal = userController.getWorker(date) print(retVal) return jsonify(retVal) \ No newline at end of file diff --git a/geruecht/vorstand/routes.py b/geruecht/vorstand/routes.py index 35e375b..a420330 100644 --- a/geruecht/vorstand/routes.py +++ b/geruecht/vorstand/routes.py @@ -18,7 +18,10 @@ def _addUser(**kwargs): data = request.get_json() user = data['user'] - date = datetime.utcfromtimestamp(int(data['date'])) + day = data['day'] + month = data['month'] + year = data['year'] + date = datetime(year,month,day,12) retVal = userController.addWorker(user['username'], date) print(retVal) return jsonify(retVal) @@ -27,7 +30,10 @@ def _addUser(**kwargs): @login_required(groups=[MONEY, GASTRO]) def _getUser(**kwargs): data = request.get_json() - date = datetime.utcfromtimestamp(int(data['date'])) + day = data['day'] + month = data['month'] + year = data['year'] + date = datetime(year, month, day, 12) retVal = userController.getWorker(date) print(retVal) return jsonify(retVal) @@ -37,6 +43,9 @@ def _getUser(**kwargs): def _deletUser(**kwargs): data = request.get_json() user = data['user'] - date = datetime.utcfromtimestamp(int(data['date'])) + day = data['day'] + month = data['month'] + year = data['year'] + date = datetime(year, month, day, 12) userController.deleteWorker(user['username'], date) return jsonify({"ok": "ok"}) \ No newline at end of file From 576002a95cf31ebb1adb38e61b5c9dc620843199 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Sun, 23 Feb 2020 11:46:38 +0100 Subject: [PATCH 3/8] fixed ##190 --- geruecht/controller/userController.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/geruecht/controller/userController.py b/geruecht/controller/userController.py index 6d551c8..23ca96d 100644 --- a/geruecht/controller/userController.py +++ b/geruecht/controller/userController.py @@ -81,8 +81,8 @@ class UserController(metaclass=Singleton): def checkBarUser(self, user): date = datetime.now() zero = date.replace(hour=0, minute=0, second=0, microsecond=0) - end = zero + timedelta(hours=11) - startdatetime = date.replace(hour=11, minute=0, second=0, microsecond=0) + end = zero + timedelta(hours=12) + startdatetime = date.replace(hour=12, minute=0, second=0, microsecond=0) if date > zero and end > date: startdatetime = startdatetime - timedelta(days=1) enddatetime = startdatetime + timedelta(days=1) From 65d09225b1b8112bf24a2e0adaca616e5973b0c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Sun, 23 Feb 2020 21:27:03 +0100 Subject: [PATCH 4/8] finished ##189 it test if the date is lower or equal then date now if true the month will be locked in soft mode if one day exists in database the status of locked will not change --- geruecht/controller/databaseController.py | 281 +++++++++++++++------- geruecht/controller/userController.py | 9 + geruecht/user/routes.py | 5 +- geruecht/vorstand/routes.py | 5 +- 4 files changed, 205 insertions(+), 95 deletions(-) diff --git a/geruecht/controller/databaseController.py b/geruecht/controller/databaseController.py index fe84080..c88c977 100644 --- a/geruecht/controller/databaseController.py +++ b/geruecht/controller/databaseController.py @@ -6,6 +6,7 @@ from geruecht.model.creditList import CreditList from datetime import datetime, timedelta from geruecht.exceptions import UsernameExistDB, DatabaseExecption import traceback +from MySQLdb._exceptions import IntegrityError class DatabaseController(metaclass=Singleton): ''' @@ -18,41 +19,55 @@ class DatabaseController(metaclass=Singleton): self.db = db def getAllUser(self): - cursor = self.db.connection.cursor() - cursor.execute("select * from user") - data = cursor.fetchall() + try: + cursor = self.db.connection.cursor() + cursor.execute("select * from user") + data = cursor.fetchall() - if data: - retVal = [] - for value in data: - user = User(value) - creditLists = self.getCreditListFromUser(user) - user.initGeruechte(creditLists) - retVal.append(user) - return retVal + if data: + retVal = [] + for value in data: + user = User(value) + creditLists = self.getCreditListFromUser(user) + user.initGeruechte(creditLists) + retVal.append(user) + return retVal + except Exception as err: + traceback.print_exc() + self.db.connection.rollback() + raise DatabaseExecption("Something went worng with Datatabase: {}".format(err)) def getUser(self, username): - retVal = None - cursor = self.db.connection.cursor() - cursor.execute("select * from user where uid='{}'".format(username)) - data = cursor.fetchone() - if data: - retVal = User(data) - creditLists = self.getCreditListFromUser(retVal) - retVal.initGeruechte(creditLists) - - return retVal + try: + retVal = None + cursor = self.db.connection.cursor() + cursor.execute("select * from user where uid='{}'".format(username)) + data = cursor.fetchone() + if data: + retVal = User(data) + creditLists = self.getCreditListFromUser(retVal) + retVal.initGeruechte(creditLists) + return retVal + except Exception as err: + traceback.print_exc() + self.db.connection.rollback() + raise DatabaseExecption("Something went worng with Datatabase: {}".format(err)) def getUserById(self, id): - retVal = None - cursor = self.db.connection.cursor() - cursor.execute("select * from user where id={}".format(id)) - data = cursor.fetchone() - if data: - retVal = User(data) - creditLists = self.getCreditListFromUser(retVal) - retVal.initGeruechte(creditLists) - return retVal + try: + retVal = None + cursor = self.db.connection.cursor() + cursor.execute("select * from user where id={}".format(id)) + data = cursor.fetchone() + if data: + retVal = User(data) + creditLists = self.getCreditListFromUser(retVal) + retVal.initGeruechte(creditLists) + return retVal + except Exception as err: + traceback.print_exc() + self.db.connection.rollback() + raise DatabaseExecption("Something went worng with Datatabase: {}".format(err)) def _convertGroupToString(self, groups): retVal = '' @@ -66,86 +81,124 @@ class DatabaseController(metaclass=Singleton): def insertUser(self, user): - cursor = self.db.connection.cursor() - groups = self._convertGroupToString(user.group) - cursor.execute("insert into user (uid, dn, firstname, lastname, gruppe, lockLimit, locked, autoLock, mail) VALUES ('{}','{}','{}','{}','{}',{},{},{},'{}')".format( - user.uid, user.dn, user.firstname, user.lastname, groups, user.limit, user.locked, user.autoLock, user.mail)) - self.db.connection.commit() + try: + cursor = self.db.connection.cursor() + groups = self._convertGroupToString(user.group) + cursor.execute("insert into user (uid, dn, firstname, lastname, gruppe, lockLimit, locked, autoLock, mail) VALUES ('{}','{}','{}','{}','{}',{},{},{},'{}')".format( + user.uid, user.dn, user.firstname, user.lastname, groups, user.limit, user.locked, user.autoLock, user.mail)) + self.db.connection.commit() + except Exception as err: + traceback.print_exc() + self.db.connection.rollback() + raise DatabaseExecption("Something went worng with Datatabase: {}".format(err)) def updateUser(self, user): - cursor = self.db.connection.cursor() - print('uid: {}; group: {}'.format(user.uid, user.group)) - groups = self._convertGroupToString(user.group) - sql = "update user set dn='{}', firstname='{}', lastname='{}', gruppe='{}', lockLimit={}, locked={}, autoLock={}, mail='{}' where uid='{}'".format( - user.dn, user.firstname, user.lastname, groups, user.limit, user.locked, user.autoLock, user.mail, user.uid) - print(sql) - cursor.execute(sql) - self.db.connection.commit() + try: + cursor = self.db.connection.cursor() + print('uid: {}; group: {}'.format(user.uid, user.group)) + groups = self._convertGroupToString(user.group) + sql = "update user set dn='{}', firstname='{}', lastname='{}', gruppe='{}', lockLimit={}, locked={}, autoLock={}, mail='{}' where uid='{}'".format( + user.dn, user.firstname, user.lastname, groups, user.limit, user.locked, user.autoLock, user.mail, user.uid) + print(sql) + cursor.execute(sql) + self.db.connection.commit() + except Exception as err: + traceback.print_exc() + self.db.connection.rollback() + raise DatabaseExecption("Something went worng with Datatabase: {}".format(err)) def getCreditListFromUser(self, user, **kwargs): - cursor = self.db.connection.cursor() - if 'year' in kwargs: - sql = "select * from creditList where user_id={} and year_date={}".format(user.id, kwargs['year']) - else: - sql = "select * from creditList where user_id={}".format(user.id) - cursor.execute(sql) - data = cursor.fetchall() - if len(data) == 1: - return [CreditList(data[0])] - else: - return [CreditList(value) for value in data] + try: + cursor = self.db.connection.cursor() + if 'year' in kwargs: + sql = "select * from creditList where user_id={} and year_date={}".format(user.id, kwargs['year']) + else: + sql = "select * from creditList where user_id={}".format(user.id) + cursor.execute(sql) + data = cursor.fetchall() + if len(data) == 1: + return [CreditList(data[0])] + else: + return [CreditList(value) for value in data] + except Exception as err: + traceback.print_exc() + self.db.connection.rollback() + raise DatabaseExecption("Something went worng with Datatabase: {}".format(err)) def createCreditList(self, user_id, year=datetime.now().year): - cursor = self.db.connection.cursor() - cursor.execute("insert into creditList (year_date, user_id) values ({},{})".format(year, user_id)) - self.db.connection.commit() + try: + cursor = self.db.connection.cursor() + cursor.execute("insert into creditList (year_date, user_id) values ({},{})".format(year, user_id)) + self.db.connection.commit() + except Exception as err: + traceback.print_exc() + self.db.connection.rollback() + raise DatabaseExecption("Something went worng with Datatabase: {}".format(err)) def updateCreditList(self, creditlist): - cursor = self.db.connection.cursor() - cursor.execute("select * from creditList where user_id={} and year_date={}".format(creditlist.user_id, creditlist.year)) - data = cursor.fetchall() - if len(data) == 0: - self.createCreditList(creditlist.user_id, creditlist.year) - sql = "update creditList set jan_guthaben={}, jan_schulden={},feb_guthaben={}, feb_schulden={}, maer_guthaben={}, maer_schulden={}, apr_guthaben={}, apr_schulden={}, mai_guthaben={}, mai_schulden={}, jun_guthaben={}, jun_schulden={}, jul_guthaben={}, jul_schulden={}, aug_guthaben={}, aug_schulden={},sep_guthaben={}, sep_schulden={},okt_guthaben={}, okt_schulden={}, nov_guthaben={}, nov_schulden={}, dez_guthaben={}, dez_schulden={}, last_schulden={} where year_date={} and user_id={}".format(creditlist.jan_guthaben, creditlist.jan_schulden, - creditlist.feb_guthaben, creditlist.feb_schulden, - creditlist.maer_guthaben, creditlist.maer_schulden, - creditlist.apr_guthaben, creditlist.apr_schulden, - creditlist.mai_guthaben, creditlist.mai_schulden, - creditlist.jun_guthaben, creditlist.jun_schulden, - creditlist.jul_guthaben, creditlist.jul_schulden, - creditlist.aug_guthaben, creditlist.aug_schulden, - creditlist.sep_guthaben, creditlist.sep_schulden, - creditlist.okt_guthaben, creditlist.okt_schulden, - creditlist.nov_guthaben, creditlist.nov_schulden, - creditlist.dez_guthaben, creditlist.dez_schulden, - creditlist.last_schulden, creditlist.year, creditlist.user_id) - print(sql) - cursor = self.db.connection.cursor() - cursor.execute(sql) - self.db.connection.commit() + try: + cursor = self.db.connection.cursor() + cursor.execute("select * from creditList where user_id={} and year_date={}".format(creditlist.user_id, creditlist.year)) + data = cursor.fetchall() + if len(data) == 0: + self.createCreditList(creditlist.user_id, creditlist.year) + sql = "update creditList set jan_guthaben={}, jan_schulden={},feb_guthaben={}, feb_schulden={}, maer_guthaben={}, maer_schulden={}, apr_guthaben={}, apr_schulden={}, mai_guthaben={}, mai_schulden={}, jun_guthaben={}, jun_schulden={}, jul_guthaben={}, jul_schulden={}, aug_guthaben={}, aug_schulden={},sep_guthaben={}, sep_schulden={},okt_guthaben={}, okt_schulden={}, nov_guthaben={}, nov_schulden={}, dez_guthaben={}, dez_schulden={}, last_schulden={} where year_date={} and user_id={}".format(creditlist.jan_guthaben, creditlist.jan_schulden, + creditlist.feb_guthaben, creditlist.feb_schulden, + creditlist.maer_guthaben, creditlist.maer_schulden, + creditlist.apr_guthaben, creditlist.apr_schulden, + creditlist.mai_guthaben, creditlist.mai_schulden, + creditlist.jun_guthaben, creditlist.jun_schulden, + creditlist.jul_guthaben, creditlist.jul_schulden, + creditlist.aug_guthaben, creditlist.aug_schulden, + creditlist.sep_guthaben, creditlist.sep_schulden, + creditlist.okt_guthaben, creditlist.okt_schulden, + creditlist.nov_guthaben, creditlist.nov_schulden, + creditlist.dez_guthaben, creditlist.dez_schulden, + creditlist.last_schulden, creditlist.year, creditlist.user_id) + print(sql) + cursor = self.db.connection.cursor() + cursor.execute(sql) + self.db.connection.commit() + except Exception as err: + traceback.print_exc() + self.db.connection.rollback() + raise DatabaseExecption("Something went worng with Datatabase: {}".format(err)) def getWorker(self, user, date): - cursor = self.db.connection.cursor() - cursor.execute("select * from bardienste where user_id={} and startdatetime='{}'".format(user.id, 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}} if data else None - + try: + cursor = self.db.connection.cursor() + cursor.execute("select * from bardienste where user_id={} and startdatetime='{}'".format(user.id, 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}} if data else None + except Exception as err: + traceback.print_exc() + self.db.connection.rollback() + raise DatabaseExecption("Something went worng with Datatabase: {}".format(err)) def getWorkers(self, date): - cursor = self.db.connection.cursor() - cursor.execute("select * from bardienste where startdatetime='{}'".format(date)) - data = cursor.fetchall() - return [{"user": self.getUserById(work['user_id']).toJSON(), "startdatetime": work['startdatetime'], "enddatetime": work['enddatetime'], "start": { "year": work['startdatetime'].year, "month": work['startdatetime'].month, "day": work['startdatetime'].day}} for work in data] - + try: + cursor = self.db.connection.cursor() + cursor.execute("select * from bardienste where startdatetime='{}'".format(date)) + data = cursor.fetchall() + return [{"user": self.getUserById(work['user_id']).toJSON(), "startdatetime": work['startdatetime'], "enddatetime": work['enddatetime'], "start": { "year": work['startdatetime'].year, "month": work['startdatetime'].month, "day": work['startdatetime'].day}} for work in data] + except Exception as err: + traceback.print_exc() + self.db.connection.rollback() + raise DatabaseExecption("Something went worng with Datatabase: {}".format(err)) def setWorker(self, user, date): - cursor = self.db.connection.cursor() - cursor.execute("insert into bardienste (user_id, startdatetime, enddatetime) values ({},'{}','{}')".format(user.id, date, date + timedelta(days=1))) - self.db.connection.commit() + try: + cursor = self.db.connection.cursor() + cursor.execute("insert into bardienste (user_id, startdatetime, enddatetime) values ({},'{}','{}')".format(user.id, date, date + timedelta(days=1))) + self.db.connection.commit() + except Exception as err: + traceback.print_exc() + self.db.connection.rollback() + raise DatabaseExecption("Something went worng with Datatabase: {}".format(err)) def deleteWorker(self, user, date): @@ -155,6 +208,8 @@ class DatabaseController(metaclass=Singleton): self.db.connection.commit() except Exception as err: traceback.print_exc() + self.db.connection.rollback() + raise DatabaseExecption("Something went worng with Datatabase: {}".format(err)) def changeUsername(self, user, newUsername): try: @@ -165,9 +220,49 @@ class DatabaseController(metaclass=Singleton): raise UsernameExistDB("Username already exists") else: cursor.execute("update user set uid='{}' where id={}".format(newUsername, user.id)) - self.db.connection() + self.db.connection.commit() except Exception as err: traceback.print_exc() + self.db.connection.rollback() + raise DatabaseExecption("Something went worng with Datatabase: {}".format(err)) + + def getLockedDay(self, date): + try: + cursor = self.db.connection.cursor() + cursor.execute("select * from locked_days where daydate='{}'".format(date)) + data = cursor.fetchone() + return data + except Exception as err: + traceback.print_exc() + self.db.connection.rollback() + raise DatabaseExecption("Something went worng with Datatabase: {}".format(err)) + + def setLockedDay(self, date, locked, hard=False): + try: + cursor = self.db.connection.cursor() + sql = "insert into locked_days (daydate, locked) VALUES ('{}', {})".format(date, locked) + cursor.execute(sql) + self.db.connection.commit() + return self.getLockedDay(date) + except IntegrityError as err: + self.db.connection.rollback() + try: + exists = self.getLockedDay(date) + if hard: + sql = "update locked_days set locked={} where id={}".format(locked, exists['id']) + else: + sql = False + if sql: + cursor.execute(sql) + self.db.connection.commit() + return self.getLockedDay(date) + except Exception as err: + traceback.print_exc() + self.db.connection.rollback() + raise DatabaseController("Something went wrong with Database: {}".format(err)) + except Exception as err: + traceback.print_exc() + self.db.connection.rollback() raise DatabaseExecption("Something went worng with Datatabase: {}".format(err)) if __name__ == '__main__': diff --git a/geruecht/controller/userController.py b/geruecht/controller/userController.py index 23ca96d..8171995 100644 --- a/geruecht/controller/userController.py +++ b/geruecht/controller/userController.py @@ -2,6 +2,7 @@ from . import LOGGER, Singleton, ldapConfig, dbConfig, mailConfig import geruecht.controller.databaseController as dc import geruecht.controller.ldapController as lc import geruecht.controller.emailController as ec +import calendar from geruecht.model.user import User from geruecht.exceptions import PermissionDenied from datetime import datetime, timedelta @@ -16,6 +17,14 @@ class UserController(metaclass=Singleton): def __init__(self): pass + def getLockedDay(self, date): + now = datetime.now() + daysInMonth = calendar.monthrange(date.year, date.month)[1] + if date.year <= now.year and date.month <= now.month: + for i in range(1, daysInMonth + 1): + db.setLockedDay(datetime(date.year, date.month, i).date(), True) + return db.getLockedDay(date.date()) + def getWorker(self, date, username=None): if (username): user = self.getUser(username) diff --git a/geruecht/user/routes.py b/geruecht/user/routes.py index b1af021..469a66e 100644 --- a/geruecht/user/routes.py +++ b/geruecht/user/routes.py @@ -59,6 +59,9 @@ def _getUser(**kwargs): month = data['month'] year = data['year'] date = datetime(year, month, day, 12) - retVal = userController.getWorker(date) + retVal = { + 'worker': userController.getWorker(date), + 'day': userController.getLockedDay(date) + } print(retVal) return jsonify(retVal) \ No newline at end of file diff --git a/geruecht/vorstand/routes.py b/geruecht/vorstand/routes.py index a420330..57680ac 100644 --- a/geruecht/vorstand/routes.py +++ b/geruecht/vorstand/routes.py @@ -34,7 +34,10 @@ def _getUser(**kwargs): month = data['month'] year = data['year'] date = datetime(year, month, day, 12) - retVal = userController.getWorker(date) + retVal = { + 'worker': userController.getWorker(date), + 'day': userController.getLockedDay(date) + } print(retVal) return jsonify(retVal) From 12ca655d027fce235c1563c9b943f7eb359ba805 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Sun, 23 Feb 2020 22:31:22 +0100 Subject: [PATCH 5/8] finished ##185 --- geruecht/controller/userController.py | 9 ++++-- geruecht/exceptions/__init__.py | 2 ++ geruecht/user/routes.py | 46 ++++++++++++++++++++++++--- geruecht/vorstand/routes.py | 21 +++++++++++- 4 files changed, 71 insertions(+), 7 deletions(-) diff --git a/geruecht/controller/userController.py b/geruecht/controller/userController.py index 8171995..cabf70b 100644 --- a/geruecht/controller/userController.py +++ b/geruecht/controller/userController.py @@ -6,7 +6,7 @@ import calendar from geruecht.model.user import User from geruecht.exceptions import PermissionDenied from datetime import datetime, timedelta -from geruecht.exceptions import UsernameExistLDAP, UsernameExistDB, DatabaseExecption, LDAPExcetpion +from geruecht.exceptions import UsernameExistLDAP, UsernameExistDB, DatabaseExecption, LDAPExcetpion, DayLocked db = dc.DatabaseController() ldap = lc.LDAPController(ldapConfig['dn']) @@ -31,7 +31,12 @@ class UserController(metaclass=Singleton): return [db.getWorker(user, date)] return db.getWorkers(date) - def addWorker(self, username, date): + def addWorker(self, username, date, userExc=False): + if (userExc): + lockedDay = self.getLockedDay(date) + if lockedDay: + if lockedDay['locked']: + raise DayLocked("Day is locked. You can't get the Job") user = self.getUser(username) if (not db.getWorker(user, date)): db.setWorker(user, date) diff --git a/geruecht/exceptions/__init__.py b/geruecht/exceptions/__init__.py index 6aeaf8e..4ef2dbf 100644 --- a/geruecht/exceptions/__init__.py +++ b/geruecht/exceptions/__init__.py @@ -7,4 +7,6 @@ class UsernameExistLDAP(Exception): class DatabaseExecption(Exception): pass class LDAPExcetpion(Exception): + pass +class DayLocked(Exception): pass \ No newline at end of file diff --git a/geruecht/user/routes.py b/geruecht/user/routes.py index 469a66e..e98be40 100644 --- a/geruecht/user/routes.py +++ b/geruecht/user/routes.py @@ -3,8 +3,7 @@ from geruecht.decorator import login_required import geruecht.controller.userController as uc from geruecht.model import USER from datetime import datetime -import time -import traceback +from geruecht.exceptions import DayLocked user = Blueprint("user", __name__) @@ -59,9 +58,48 @@ def _getUser(**kwargs): month = data['month'] year = data['year'] date = datetime(year, month, day, 12) + lockedDay = userController.getLockedDay(date) + if not lockedDay: + lockedDay = { + 'date': { + 'year': year, + 'month': month, + 'day': day + }, + 'locked': False + } + else: + lockedDay = { + 'date': { + 'year': year, + 'month': month, + 'day': day + }, + 'locked': lockedDay['locked'] + } retVal = { 'worker': userController.getWorker(date), - 'day': userController.getLockedDay(date) + 'day': lockedDay } print(retVal) - return jsonify(retVal) \ No newline at end of file + return jsonify(retVal) + +@user.route("/user/addJob", methods=['POST']) +@login_required(groups=[USER]) +def _addUser(**kwargs): + try: + if 'accToken' in kwargs: + accToken = kwargs['accToken'] + user = accToken.user + data = request.get_json() + day = data['day'] + month = data['month'] + year = data['year'] + date = datetime(year,month,day,12) + retVal = userController.addWorker(user.uid, date, userExc=True) + print(retVal) + return jsonify(retVal) + except DayLocked as err: + return jsonify({'error': err}), 403 + except Exception as err: + return jsonify({'error': err}), 409 \ No newline at end of file diff --git a/geruecht/vorstand/routes.py b/geruecht/vorstand/routes.py index 57680ac..40c6234 100644 --- a/geruecht/vorstand/routes.py +++ b/geruecht/vorstand/routes.py @@ -34,9 +34,28 @@ def _getUser(**kwargs): month = data['month'] year = data['year'] date = datetime(year, month, day, 12) + lockedDay = userController.getLockedDay(date) + if not lockedDay: + lockedDay = { + 'date': { + 'year': year, + 'month': month, + 'day': day + }, + 'locked': False + } + else: + lockedDay = { + 'date': { + 'year': year, + 'month': month, + 'day': day + }, + 'locked': lockedDay['locked'] + } retVal = { 'worker': userController.getWorker(date), - 'day': userController.getLockedDay(date) + 'day': lockedDay } print(retVal) return jsonify(retVal) From 61b9f7001a7ad608e1abc362f60c334705705cef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Mon, 24 Feb 2020 12:19:52 +0100 Subject: [PATCH 6/8] finished ##187 --- geruecht/controller/userController.py | 10 +++++++- geruecht/vorstand/routes.py | 36 ++++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/geruecht/controller/userController.py b/geruecht/controller/userController.py index cabf70b..0f7c293 100644 --- a/geruecht/controller/userController.py +++ b/geruecht/controller/userController.py @@ -17,12 +17,20 @@ class UserController(metaclass=Singleton): def __init__(self): pass + def setLockedDay(self, date, locked,hard=False): + return db.setLockedDay(date.date(), locked, hard) + def getLockedDay(self, date): now = datetime.now() daysInMonth = calendar.monthrange(date.year, date.month)[1] if date.year <= now.year and date.month <= now.month: for i in range(1, daysInMonth + 1): - db.setLockedDay(datetime(date.year, date.month, i).date(), True) + self.setLockedDay(datetime(date.year, date.month, i), True) + for i in range(1, 8): + nextMonth = datetime(date.year, date.month + 1, i) + if nextMonth.weekday() == 2: + break + self.setLockedDay(nextMonth, True) return db.getLockedDay(date.date()) def getWorker(self, date, username=None): diff --git a/geruecht/vorstand/routes.py b/geruecht/vorstand/routes.py index 40c6234..8e6ff0d 100644 --- a/geruecht/vorstand/routes.py +++ b/geruecht/vorstand/routes.py @@ -70,4 +70,38 @@ def _deletUser(**kwargs): year = data['year'] date = datetime(year, month, day, 12) userController.deleteWorker(user['username'], date) - return jsonify({"ok": "ok"}) \ No newline at end of file + return jsonify({"ok": "ok"}) + +@vorstand.route("/sm/lockDay", methods=['POST']) +@login_required(groups=[MONEY, GASTRO]) +def _lockDay(**kwargs): + try: + data = request.get_json() + year = data['year'] + month = data['month'] + day = data['day'] + locked = data['locked'] + date = datetime(year, month, day, 12) + lockedDay = userController.setLockedDay(date, locked, True) + if not lockedDay: + retVal = { + 'date': { + 'year': year, + 'month': month, + 'day': day + }, + 'locked': False + } + else: + retVal = { + 'date': { + 'year': year, + 'month': month, + 'day': day + }, + 'locked': lockedDay['locked'] + } + print(retVal) + return jsonify(retVal) + except Exception as err: + return jsonify({'error': err}), 409 \ No newline at end of file From 4e91587731dd660045c3c27c307273eaac4cf978 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Mon, 24 Feb 2020 18:55:57 +0100 Subject: [PATCH 7/8] finished ##193 route for user to delete job, but only if day not locked fixed a bug, that the month start on the first wednesday in month and ended in first tuesday in nextmonth --- geruecht/controller/userController.py | 14 ++++++++++++-- geruecht/user/routes.py | 21 ++++++++++++++++++++- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/geruecht/controller/userController.py b/geruecht/controller/userController.py index 0f7c293..293820e 100644 --- a/geruecht/controller/userController.py +++ b/geruecht/controller/userController.py @@ -23,8 +23,13 @@ class UserController(metaclass=Singleton): def getLockedDay(self, date): now = datetime.now() daysInMonth = calendar.monthrange(date.year, date.month)[1] + startMonth = 1 + for i in range(1, 8): + if datetime(date.year, date.month, i).weekday() == 2: + startMonth = i + break if date.year <= now.year and date.month <= now.month: - for i in range(1, daysInMonth + 1): + for i in range(startMonth, daysInMonth + 1): self.setLockedDay(datetime(date.year, date.month, i), True) for i in range(1, 8): nextMonth = datetime(date.year, date.month + 1, i) @@ -50,7 +55,12 @@ class UserController(metaclass=Singleton): db.setWorker(user, date) return self.getWorker(date, username=username) - def deleteWorker(self, username, date): + def deleteWorker(self, username, date, userExc=False): + if userExc: + lockedDay = self.getLockedDay(date) + if lockedDay: + if lockedDay['locked']: + raise DayLocked("Day is locked. You can't delete the Job") user = self.getUser(username) db.deleteWorker(user, date) diff --git a/geruecht/user/routes.py b/geruecht/user/routes.py index e98be40..4f4ed33 100644 --- a/geruecht/user/routes.py +++ b/geruecht/user/routes.py @@ -102,4 +102,23 @@ def _addUser(**kwargs): except DayLocked as err: return jsonify({'error': err}), 403 except Exception as err: - return jsonify({'error': err}), 409 \ No newline at end of file + return jsonify({'error': err}), 409 + +@user.route("/user/deleteJob", methods=['POST']) +@login_required(groups=[USER]) +def _deletJob(**kwargs): + try: + if 'accToken' in kwargs: + accToken = kwargs['accToken'] + user = accToken.user + data = request.get_json() + day = data['day'] + month = data['month'] + year = data['year'] + date = datetime(year,month,day,12) + userController.deleteWorker(user.uid, date, True) + return jsonify({"ok": "ok"}) + except DayLocked as err: + return jsonify({"error": err}), 403 + except Exception as err: + return jsonify({"error": err}), 409 \ No newline at end of file From 90d503f6aa7952a9f4a9ac59e4ec934470a53284 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Tue, 25 Feb 2020 22:50:32 +0100 Subject: [PATCH 8/8] finished ##169 and ##170 (without config.yml) --- geruecht/baruser/routes.py | 4 +- geruecht/controller/databaseController.py | 106 ++++++++++++++++++- geruecht/controller/userController.py | 42 +++++++- geruecht/exceptions/__init__.py | 2 + geruecht/user/routes.py | 122 +++++++++++++++++++++- 5 files changed, 264 insertions(+), 12 deletions(-) diff --git a/geruecht/baruser/routes.py b/geruecht/baruser/routes.py index a8c47a4..58dbc52 100644 --- a/geruecht/baruser/routes.py +++ b/geruecht/baruser/routes.py @@ -3,7 +3,7 @@ import geruecht.controller as gc import geruecht.controller.ldapController as lc import geruecht.controller.userController as uc from datetime import datetime -from geruecht.model import BAR, MONEY +from geruecht.model import BAR, MONEY, USER from geruecht.decorator import login_required baruser = Blueprint("baruser", __name__) @@ -146,7 +146,7 @@ def _getUser(**kwargs): @baruser.route("/search", methods=['POST']) -@login_required(groups=[BAR, MONEY]) +@login_required(groups=[BAR, MONEY, USER]) def _search(**kwargs): data = request.get_json() searchString = data['searchString'] diff --git a/geruecht/controller/databaseController.py b/geruecht/controller/databaseController.py index c88c977..b9c2ba3 100644 --- a/geruecht/controller/databaseController.py +++ b/geruecht/controller/databaseController.py @@ -259,12 +259,116 @@ class DatabaseController(metaclass=Singleton): except Exception as err: traceback.print_exc() self.db.connection.rollback() - raise DatabaseController("Something went wrong with Database: {}".format(err)) + raise DatabaseExecption("Something went wrong with Database: {}".format(err)) except Exception as err: traceback.print_exc() self.db.connection.rollback() raise DatabaseExecption("Something went worng with Datatabase: {}".format(err)) + def setTransactJob(self, from_user, to_user, date): + try: + exists = self.getTransactJob(from_user, to_user, date) + if exists: + raise IntegrityError("job_transact already exists") + cursor = self.db.connection.cursor() + cursor.execute("insert into job_transact (jobdate, from_user_id, to_user_id) VALUES ('{}', {}, {})".format(date, from_user.id, to_user.id)) + self.db.connection.commit() + return self.getTransactJob(from_user, to_user, date) + except Exception as err: + traceback.print_exc() + self.db.connection.rollback() + raise DatabaseExecption("Somethin went wrong with Database: {}".format(err)) + + def getTransactJob(self, from_user, to_user, date): + try: + cursor = self.db.connection.cursor() + cursor.execute("select * from job_transact where from_user_id={} and to_user_id={} and jobdate='{}'".format(from_user.id, to_user.id, date)) + data = cursor.fetchone() + if data: + return {"from_user": from_user, "to_user": to_user, "date": data['jobdate'], "answerd": data['answerd'], "accepted": data['accepted']} + return None + except Exception as err: + traceback.print_exc() + self.db.connection.rollback() + raise DatabaseExecption("Something went worng with Database: {}".format(err)) + + def getAllTransactJobFromUser(self, from_user, date): + try: + cursor = self.db.connection.cursor() + cursor.execute("select * from job_transact where from_user_id={}".format(from_user.id)) + data = cursor.fetchall() + retVal = [] + for transact in data: + if date <= transact['jobdate']: + retVal.append({"from_user": from_user, "to_user": self.getUserById(transact['to_user_id']), "date": transact['jobdate'], "accepted": transact['accepted'], "answerd": transact['answerd']}) + return retVal + except Exception as err: + traceback.print_exc() + self.db.connection.rollback() + raise DatabaseExecption("Somethin went wrong with Database: {}".format(err)) + + def getAllTransactJobToUser(self, to_user, date): + try: + cursor = self.db.connection.cursor() + cursor.execute("select * from job_transact where to_user_id={}".format(to_user.id)) + data = cursor.fetchall() + retVal = [] + for transact in data: + if date <= transact['jobdate']: + retVal.append({"to_user": to_user, "from_user": self.getUserById(transact['from_user_id']), "date": transact['jobdate'], "accepted": transact['accepted'], "answerd": transact['answerd']}) + return retVal + except Exception as err: + traceback.print_exc() + self.db.connection.rollback() + raise DatabaseExecption("Somethin went wrong with Database: {}".format(err)) + + def getTransactJobToUser(self, to_user, date): + try: + cursor = self.db.connection.cursor() + cursor.execute("select * from job_transact where to_user_id={} and jobdate='{}'".format(to_user.id, date)) + data = cursor.fetchone() + if data: + return {"from_user": self.getUserById(data['from_user_id']), "to_user": to_user, "date": data['jobdate'], "accepted": data['accepted'], "answerd": data['answerd']} + else: + return None + except Exception as err: + traceback.print_exc() + self.db.connection.rollback() + raise DatabaseExecption("Somethin went wrong with Database: {}".format(err)) + + def updateTransactJob(self, from_user, to_user, date, accepted): + try: + cursor = self.db.connection.cursor() + cursor.execute("update job_transact set accepted={}, answerd=true where to_user_id={} and jobdate='{}'".format(accepted, to_user.id, date)) + self.db.connection.commit() + return self.getTransactJob(from_user, to_user, date) + except Exception as err: + traceback.print_exc() + self.db.connection.rollback() + raise DatabaseExecption("Somethin went wrong with Database: {}".format(err)) + + def getTransactJobFromUser(self, user, date): + try: + cursor = self.db.connection.cursor() + cursor.execute("select * from job_transact where from_user_id={} and jobdate='{}'".format(user.id, date)) + data = cursor.fetchall() + return [{"from_user": user, "to_user": self.getUserById(transact['to_user_id']), "date": transact['jobdate'], "accepted": transact['accepted'], "answerd": transact['answerd']} for transact in data] + except Exception as err: + traceback.print_exc() + self.db.connection.rollback() + raise DatabaseExecption("Somethin went wrong with Database: {}".format(err)) + + def deleteTransactJob(self, from_user, to_user, date): + try: + cursor = self.db.connection.cursor() + cursor.execute("delete from job_transact where from_user_id={} and to_user_id={} and jobdate='{}'".format(from_user.id, to_user.id, date)) + self.db.connection.commit() + except Exception as err: + traceback.print_exc() + self.db.connection.rollback() + raise DatabaseExecption("Something went wrong with Database: {}".format(err)) + + if __name__ == '__main__': db = DatabaseController() user = db.getUser('jhille') diff --git a/geruecht/controller/userController.py b/geruecht/controller/userController.py index 293820e..b7210ae 100644 --- a/geruecht/controller/userController.py +++ b/geruecht/controller/userController.py @@ -6,7 +6,7 @@ import calendar from geruecht.model.user import User from geruecht.exceptions import PermissionDenied from datetime import datetime, timedelta -from geruecht.exceptions import UsernameExistLDAP, UsernameExistDB, DatabaseExecption, LDAPExcetpion, DayLocked +from geruecht.exceptions import UsernameExistLDAP, UsernameExistDB, DatabaseExecption, LDAPExcetpion, DayLocked, TansactJobIsAnswerdException db = dc.DatabaseController() ldap = lc.LDAPController(ldapConfig['dn']) @@ -17,7 +17,34 @@ class UserController(metaclass=Singleton): def __init__(self): pass - def setLockedDay(self, date, locked,hard=False): + def setTransactJob(self, from_user, to_user, date): + return db.setTransactJob(from_user, to_user, date.date()) + + def getTransactJobFromUser(self, user, date): + return db.getTransactJobFromUser(user, date.date()) + + def getAllTransactJobFromUser(self, user, date): + return db.getAllTransactJobFromUser(user, date.date()) + + def getAllTransactJobToUser(self, user, date): + return db.getAllTransactJobToUser(user, date.date()) + + def getTransactJob(self, from_user, to_user, date): + return db.getTransactJob(from_user, to_user, date.date()) + + def deleteTransactJob(self, from_user, to_user, date): + transactJob = self.getTransactJob(from_user, to_user, date) + if transactJob['answerd']: + raise TansactJobIsAnswerdException("TransactJob is already answerd") + db.deleteTransactJob(from_user, to_user, date.date()) + + def answerdTransactJob(self, from_user, to_user, date, answer): + transactJob = db.updateTransactJob(from_user, to_user, date.date(), answer) + if answer: + self.addWorker(to_user.uid, date) + return transactJob + + def setLockedDay(self, date, locked, hard=False): return db.setLockedDay(date.date(), locked, hard) def getLockedDay(self, date): @@ -56,12 +83,19 @@ class UserController(metaclass=Singleton): return self.getWorker(date, username=username) def deleteWorker(self, username, date, userExc=False): + user = self.getUser(username) if userExc: lockedDay = self.getLockedDay(date) if lockedDay: if lockedDay['locked']: - raise DayLocked("Day is locked. You can't delete the Job") - user = self.getUser(username) + transactJobs = self.getTransactJobFromUser(user, date) + found = False + for job in transactJobs: + if job['accepted'] and job['answerd']: + found = True + break + if not found: + raise DayLocked("Day is locked. You can't delete the Job") db.deleteWorker(user, date) def lockUser(self, username, locked): diff --git a/geruecht/exceptions/__init__.py b/geruecht/exceptions/__init__.py index 4ef2dbf..307c48e 100644 --- a/geruecht/exceptions/__init__.py +++ b/geruecht/exceptions/__init__.py @@ -9,4 +9,6 @@ class DatabaseExecption(Exception): class LDAPExcetpion(Exception): pass class DayLocked(Exception): + pass +class TansactJobIsAnswerdException(Exception): pass \ No newline at end of file diff --git a/geruecht/user/routes.py b/geruecht/user/routes.py index 4f4ed33..beaade9 100644 --- a/geruecht/user/routes.py +++ b/geruecht/user/routes.py @@ -48,7 +48,7 @@ def _saveConfig(**kwargs): retVal['creditList'] = {credit.year: credit.toJSON() for credit in accToken.user.geruechte} return jsonify(retVal) except Exception as err: - return jsonify({"error": err}), 409 + return jsonify({"error": str(err)}), 409 @user.route("/user/job", methods=['POST']) @login_required(groups=[USER]) @@ -100,9 +100,9 @@ def _addUser(**kwargs): print(retVal) return jsonify(retVal) except DayLocked as err: - return jsonify({'error': err}), 403 + return jsonify({'error': str(err)}), 403 except Exception as err: - return jsonify({'error': err}), 409 + return jsonify({'error': str(err)}), 409 @user.route("/user/deleteJob", methods=['POST']) @login_required(groups=[USER]) @@ -119,6 +119,118 @@ def _deletJob(**kwargs): userController.deleteWorker(user.uid, date, True) return jsonify({"ok": "ok"}) except DayLocked as err: - return jsonify({"error": err}), 403 + return jsonify({"error": str(err)}), 403 except Exception as err: - return jsonify({"error": err}), 409 \ No newline at end of file + return jsonify({"error": str(err)}), 409 + +@user.route("/user/transactJob", methods=['POST']) +@login_required(groups=[USER]) +def _transactJob(**kwargs): + try: + if 'accToken' in kwargs: + accToken = kwargs['accToken'] + user = accToken.user + data = request.get_json() + year = data['year'] + month = data['month'] + day = data['day'] + username = data['user'] + date = datetime(year, month, day, 12) + to_user = userController.getUser(username) + retVal = userController.setTransactJob(user, to_user, date) + retVal['from_user'] = retVal['from_user'].toJSON() + retVal['to_user'] = retVal['to_user'].toJSON() + retVal['date'] = {'year': year, 'month': month, 'day': day} + print(retVal) + return jsonify(retVal) + except Exception as err: + return jsonify({"error": str(err)}), 409 + +@user.route("/user/answerTransactJob", methods=['POST']) +@login_required(groups=[USER]) +def _answer(**kwargs): + try: + if 'accToken' in kwargs: + accToken = kwargs['accToken'] + user = accToken.user + data = request.get_json() + year = data['year'] + month = data['month'] + day = data['day'] + answer = data['answer'] + username = data['username'] + date = datetime(year, month, day, 12) + from_user = userController.getUser(username) + retVal = userController.answerdTransactJob(from_user, user, date, answer) + retVal['from_user'] = retVal['from_user'].toJSON() + retVal['to_user'] = retVal['to_user'].toJSON() + retVal['date'] = {'year': year, 'month': month, 'day': day} + print(retVal) + return jsonify(retVal) + except Exception as err: + return jsonify({"error": str(err)}), 409 + +@user.route("/user/jobRequests", methods=['POST']) +@login_required(groups=[USER]) +def _requests(**kwargs): + try: + if 'accToken' in kwargs: + accToken = kwargs['accToken'] + user = accToken.user + data = request.get_json() + year = data['year'] + month = data['month'] + day = data['day'] + date = datetime(year, month, day, 12) + retVal = userController.getAllTransactJobToUser(user, date) + for data in retVal: + data['from_user'] = data['from_user'].toJSON() + data['to_user'] = data['to_user'].toJSON() + data_date = data['date'] + data['date'] = {'year': data_date.year, 'month': data_date.month, 'day': data_date.day} + print(retVal) + return jsonify(retVal) + except Exception as err: + return jsonify({"error": str(err)}), 409 + +@user.route("/user/getTransactJobs", methods=['POST']) +@login_required(groups=[USER]) +def _getTransactJobs(**kwargs): + try: + if 'accToken' in kwargs: + accToken = kwargs['accToken'] + user = accToken.user + data = request.get_json() + year = data['year'] + month = data['month'] + day = data['day'] + date = datetime(year, month, day, 12) + retVal = userController.getAllTransactJobFromUser(user, date) + for data in retVal: + data['from_user'] = data['from_user'].toJSON() + data['to_user'] = data['to_user'].toJSON() + data_date = data['date'] + data['date'] = {'year': data_date.year, 'month': data_date.month, 'day': data_date.day} + print(retVal) + return jsonify(retVal) + except Exception as err: + return jsonify({"error": str(err)}), 409 + +@user.route("/user/deleteTransactJob", methods=['POST']) +@login_required(groups=[USER]) +def _deleteTransactJob(**kwargs): + try: + if 'accToken' in kwargs: + accToken = kwargs['accToken'] + from_user = accToken.user + data = request.get_json() + year = data['year'] + month = data['month'] + day = data['day'] + username = data['username'] + date = datetime(year, month, day, 12) + to_user = userController.getUser(username) + userController.deleteTransactJob(from_user, to_user, date) + return jsonify({"ok": "ok"}) + except Exception as err: + return jsonify({"error": str(err)}), 409 \ No newline at end of file