diff --git a/geruecht/controller/databaseController/dbJobKindController.py b/geruecht/controller/databaseController/dbJobKindController.py index c243f0d..d131eb3 100644 --- a/geruecht/controller/databaseController/dbJobKindController.py +++ b/geruecht/controller/databaseController/dbJobKindController.py @@ -101,6 +101,26 @@ class Base: self.db.connection.rollback() raise DatabaseExecption("Something went worng with Databes: {}".format(err)) + def getJobKindDate(self, date, job_kind): + try: + cursor = self.db.connection.cursor() + cursor.execute("select * from job_kind_dates where daydate='{}' and job_kind={}".format(date, job_kind['id'])) + item = cursor.fetchone() + if item: + item['job_kind'] = self.getJobKind(item['job_kind']) if item['job_kind'] != None else None + item['daydate'] = {'year': item['daydate'].year, 'month': item['daydate'].month, 'day': item['daydate'].day} + else: + item = { + 'job_kind': self.getJobKind(1), + 'daydate': {'year': date.year, 'month': date.month, 'day': date.day}, + 'maxpersons': 2 + } + return item + except Exception as err: + traceback.print_exc() + self.db.connection.rollback() + raise DatabaseExecption("Something went worng with Databes: {}".format(err)) + def deleteJobKindDates(self, jobkinddates): try: cursor = self.db.connection.cursor() diff --git a/geruecht/controller/databaseController/dbWorkerController.py b/geruecht/controller/databaseController/dbWorkerController.py index 7a2e917..3d7652d 100644 --- a/geruecht/controller/databaseController/dbWorkerController.py +++ b/geruecht/controller/databaseController/dbWorkerController.py @@ -22,14 +22,18 @@ class Base: cursor.execute("select * from bardienste where startdatetime='{}'".format(date)) data = cursor.fetchall() retVal = [] - # for work in data: - # 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} - # job_kind = self.getJobKind(work['job_kind']) if work['job_kind'] != None else None - # retVal.append({'user': user, 'startdatetime': startdatetime, 'enddatetime': enddatetime, 'start': start, 'job_kind': job_kind}) - # return retVal + 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}, "job_kind": self.getJobKind(work['job_kind']) if work['job_kind'] != None else None} 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 getWorkersWithJobKind(self, date, job_kind): + try: + cursor = self.db.connection.cursor() + cursor.execute("select * from bardienste where startdatetime='{}' and job_kind={} {}".format(date, job_kind['id'], "or job_kind='null'" if job_kind['id'] is 1 else '')) + data = cursor.fetchall() + retVal = [] 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}, "job_kind": self.getJobKind(work['job_kind']) if work['job_kind'] != None else None} for work in data] except Exception as err: traceback.print_exc() diff --git a/geruecht/controller/mainController/mainWorkerController.py b/geruecht/controller/mainController/mainWorkerController.py index 4ae0d16..91a3068 100644 --- a/geruecht/controller/mainController/mainWorkerController.py +++ b/geruecht/controller/mainController/mainWorkerController.py @@ -32,7 +32,7 @@ class Base: user = self.getUser(username) debug.debug("user is {{ {} }}".format(user)) debug.debug("check if user has job on date") - if (not db.getWorker(user, date)): + if (not db.getWorker(user, date) and len(db.getWorkersWithJobKind(date, job_kind)) < db.getJobKindDate(date.date(), job_kind)['maxpersons']): debug.debug("set job to user") db.setWorker(user, date, job_kind=job_kind) retVal = self.getWorker(date, username=username)