user können sich einladen, und austragen, jobinvites können geupdated werden
This commit is contained in:
parent
7bd7acc6bf
commit
efa0257cd0
|
@ -1,11 +1,18 @@
|
|||
from ..mainController import Singleton
|
||||
from geruecht import db
|
||||
from ..databaseController import dbUserController, dbCreditListController, dbJobKindController, dbJobTransactController, dbPricelistController, dbWorkerController, dbWorkgroupController
|
||||
from ..databaseController import dbUserController, dbCreditListController, dbJobKindController, dbPricelistController, dbWorkerController, dbWorkgroupController, dbJobInviteController
|
||||
from geruecht.exceptions import DatabaseExecption
|
||||
import traceback
|
||||
from MySQLdb._exceptions import IntegrityError
|
||||
|
||||
class DatabaseController(dbUserController.Base, dbCreditListController.Base, dbWorkerController.Base, dbWorkgroupController.Base, dbPricelistController.Base, dbJobTransactController.Base, dbJobKindController.Base, metaclass=Singleton):
|
||||
class DatabaseController(dbUserController.Base,
|
||||
dbCreditListController.Base,
|
||||
dbWorkerController.Base,
|
||||
dbWorkgroupController.Base,
|
||||
dbPricelistController.Base,
|
||||
dbJobKindController.Base,
|
||||
dbJobInviteController.Base,
|
||||
metaclass=Singleton):
|
||||
'''
|
||||
DatabaesController
|
||||
|
||||
|
|
|
@ -0,0 +1,84 @@
|
|||
import traceback
|
||||
|
||||
from geruecht.exceptions import DatabaseExecption
|
||||
|
||||
|
||||
class Base:
|
||||
def getJobInvite(self, from_user, to_user, date, id=None):
|
||||
try:
|
||||
cursor = self.db.connection.cursor()
|
||||
if id:
|
||||
cursor.execute("select * from job_invites where id={}".format(id))
|
||||
else:
|
||||
cursor.execute("select * from job_invites where from_user={} and to_user={} and on_date='{}'".format(from_user['id'], to_user['id'], date))
|
||||
retVal = cursor.fetchone()
|
||||
retVal['to_user'] = self.getUserById(retVal['to_user']).toJSON()
|
||||
retVal['from_user'] = self.getUserById(retVal['from_user']).toJSON()
|
||||
retVal['on_date'] = {'year': retVal['on_date'].year, 'month': retVal['on_date'].month, 'day': retVal['on_date'].day}
|
||||
return retVal
|
||||
except Exception as err:
|
||||
traceback.print_exc()
|
||||
self.db.connection.rollback()
|
||||
raise DatabaseExecption("Something went worng with Datatabase: {}".format(err))
|
||||
|
||||
def getJobInvitesFromUser(self, from_user, date):
|
||||
try:
|
||||
cursor = self.db.connection.cursor()
|
||||
cursor.execute("select * from job_invites where from_user={} and on_date>='{}'".format(from_user['id'], date))
|
||||
retVal = cursor.fetchall()
|
||||
for item in retVal:
|
||||
item['from_user'] = from_user
|
||||
item['to_user'] = self.getUserById(item['to_user']).toJSON()
|
||||
item['on_date'] = {'year': item['on_date'].year, 'month': item['on_date'].month, 'day': item['on_date'].day}
|
||||
return retVal
|
||||
except Exception as err:
|
||||
traceback.print_exc()
|
||||
self.db.connection.rollback()
|
||||
raise DatabaseExecption("Something went worng with Datatabase: {}".format(err))
|
||||
|
||||
def getJobInvitesToUser(self, to_user, date):
|
||||
try:
|
||||
cursor = self.db.connection.cursor()
|
||||
cursor.execute("select * from job_invites where to_user={} and on_date>='{}'".format(to_user['id'], date))
|
||||
retVal = cursor.fetchall()
|
||||
for item in retVal:
|
||||
item['from_user'] = self.getUserById(item['from_user']).toJSON()
|
||||
item['to_user'] = to_user
|
||||
item['on_date'] = {'year': item['on_date'].year, 'month': item['on_date'].month, 'day': item['on_date'].day}
|
||||
return retVal
|
||||
except Exception as err:
|
||||
traceback.print_exc()
|
||||
self.db.connection.rollback()
|
||||
raise DatabaseExecption("Something went worng with Datatabase: {}".format(err))
|
||||
|
||||
def setJobInvite(self, from_user, to_user, date):
|
||||
try:
|
||||
cursor = self.db.connection.cursor()
|
||||
cursor.execute("insert into job_invites (from_user, to_user, on_date) values ({}, {}, '{}')".format(from_user['id'], to_user['id'], date))
|
||||
self.db.connection.commit()
|
||||
return self.getJobInvite(from_user, to_user, date)
|
||||
except Exception as err:
|
||||
traceback.print_exc()
|
||||
self.db.connection.rollback()
|
||||
raise DatabaseExecption("Something went worng with Datatabase: {}".format(err))
|
||||
|
||||
def updateJobInvite(self, jobinvite):
|
||||
try:
|
||||
cursor = self.db.connection.cursor()
|
||||
cursor.execute("update job_invites set watched={} where id={}".format(jobinvite['watched'], jobinvite['id']))
|
||||
self.db.connection.commit()
|
||||
return self.getJobInvite(None, None, None, jobinvite['id'])
|
||||
except Exception as err:
|
||||
traceback.print_exc()
|
||||
self.db.connection.rollback()
|
||||
raise DatabaseExecption("Something went worng with Datatabase: {}".format(err))
|
||||
|
||||
def deleteJobInvite(self, jobinvite):
|
||||
try:
|
||||
cursor = self.db.connection.cursor()
|
||||
cursor.execute("delete from job_invites where id={}".format(jobinvite['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))
|
|
@ -1,110 +0,0 @@
|
|||
import traceback
|
||||
|
||||
from MySQLdb._exceptions import IntegrityError
|
||||
|
||||
from geruecht.exceptions import DatabaseExecption
|
||||
|
||||
|
||||
class Base:
|
||||
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))
|
||||
|
||||
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))
|
|
@ -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, mainJobTransactController, mainPricelistController, mainUserController, mainWorkerController, mainWorkgroupController
|
||||
from ..mainController import mainJobKindController, mainCreditListController, mainPricelistController, mainUserController, mainWorkerController, mainWorkgroupController, mainJobInviteController
|
||||
|
||||
db = dc.DatabaseController()
|
||||
ldap = lc.LDAPController()
|
||||
|
@ -16,11 +16,11 @@ debug = getDebugLogger()
|
|||
|
||||
class MainController(mainJobKindController.Base,
|
||||
mainCreditListController.Base,
|
||||
mainJobTransactController.Base,
|
||||
mainPricelistController.Base,
|
||||
mainUserController.Base,
|
||||
mainWorkerController.Base,
|
||||
mainWorkgroupController.Base,
|
||||
mainJobInviteController.Base,
|
||||
metaclass=Singleton):
|
||||
|
||||
def __init__(self):
|
||||
|
@ -48,6 +48,14 @@ class MainController(mainJobKindController.Base,
|
|||
debug.debug("lock days are {{ {} }}".format(retVal))
|
||||
return retVal
|
||||
|
||||
def getLockedDaysFromList(self, date_list):
|
||||
debug.info("get locked days from list {{ {} }}".format(date_list))
|
||||
retVal = []
|
||||
for on_date in date_list:
|
||||
day = datetime(on_date['on_date']['year'], on_date['on_date']['month'], on_date['on_date']['day'], 12)
|
||||
retVal.append(self.getLockedDay(day))
|
||||
return retVal
|
||||
|
||||
def getLockedDay(self, date):
|
||||
debug.info("get locked day on {{ {} }}".format(date))
|
||||
now = datetime.now()
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
from datetime import date
|
||||
|
||||
import geruecht.controller.databaseController as dc
|
||||
from geruecht import getDebugLogger
|
||||
|
||||
db = dc.DatabaseController()
|
||||
debug = getDebugLogger()
|
||||
|
||||
class Base:
|
||||
def getJobInvites(self, from_user, to_user, date):
|
||||
debug.info("get JobInvites from_user {{ {} }} to_user {{ {} }} on date {{ {} }}".format(from_user, to_user, date))
|
||||
if from_user is None:
|
||||
retVal = db.getJobInvitesToUser(to_user, date)
|
||||
elif to_user is None:
|
||||
retVal = db.getJobInvitesFromUser(from_user, date)
|
||||
else:
|
||||
raise Exception("from_user {{ {} }} and to_user {{ {} }} are None".format(from_user, to_user))
|
||||
return retVal
|
||||
|
||||
def setJobInvites(self, data):
|
||||
debug.info("set new JobInvites data {{ {} }}".format(data))
|
||||
retVal = []
|
||||
for jobInvite in data:
|
||||
from_user = jobInvite['from_user']
|
||||
to_user = jobInvite['to_user']
|
||||
on_date = date(jobInvite['date']['year'], jobInvite['date']['month'], jobInvite['date']['day'])
|
||||
debug.info("set new JobInvite from_user {{ {} }}, to_user {{ {} }}, on_date {{ {} }}")
|
||||
retVal.append(db.setJobInvite(from_user, to_user, on_date))
|
||||
debug.debug("seted JobInvites are {{ {} }}".format(retVal))
|
||||
return retVal
|
||||
|
||||
def updateJobInvites(self, data):
|
||||
debug.info("update JobInvites data {{ {} }}".format(data))
|
||||
return db.updateJobInvite(data)
|
||||
|
||||
def deleteJobInvite(self, jobInvite):
|
||||
debug.info("delete JobInvite {{ {} }}".format(jobInvite))
|
||||
db.deleteJobInvite(jobInvite)
|
|
@ -1,71 +0,0 @@
|
|||
import geruecht.controller.databaseController as dc
|
||||
import geruecht.controller.emailController as ec
|
||||
from geruecht.exceptions import TansactJobIsAnswerdException
|
||||
from geruecht.logger import getDebugLogger
|
||||
|
||||
db = dc.DatabaseController()
|
||||
emailController = ec.EmailController()
|
||||
debug = getDebugLogger()
|
||||
|
||||
class Base:
|
||||
def setTransactJob(self, from_user, to_user, date):
|
||||
debug.info("set transact job from {{ {} }} to {{ {} }} on {{ {} }}".format(
|
||||
from_user, to_user, date))
|
||||
jobtransact = db.setTransactJob(from_user, to_user, date.date())
|
||||
debug.debug("transact job is {{ {} }}".format(jobtransact))
|
||||
debug.info("send mail with transact job to user")
|
||||
emailController.sendMail(
|
||||
jobtransact['to_user'], 'jobtransact', jobtransact)
|
||||
return jobtransact
|
||||
|
||||
def getTransactJobFromUser(self, user, date):
|
||||
debug.info(
|
||||
"get transact job from user {{ {} }} on {{ {} }}".format(user, date))
|
||||
retVal = db.getTransactJobFromUser(user, date.date())
|
||||
debug.debug(
|
||||
"transact job from user {{ {} }} is {{ {} }}".format(user, retVal))
|
||||
return retVal
|
||||
|
||||
def getAllTransactJobFromUser(self, user, date):
|
||||
debug.info(
|
||||
"get all transact job from user {{ {} }} start on {{ {} }}".format(user, date))
|
||||
retVal = db.getAllTransactJobFromUser(user, date.date())
|
||||
debug.debug("all transact job are {{ {} }}".format(retVal))
|
||||
return retVal
|
||||
|
||||
def getAllTransactJobToUser(self, user, date):
|
||||
debug.info(
|
||||
"get all transact job from to_user {{ {} }} start on {{ {} }}".format(user, date))
|
||||
retVal = db.getAllTransactJobToUser(user, date.date())
|
||||
debug.debug("all transact job are {{ {} }}".format(retVal))
|
||||
return retVal
|
||||
|
||||
def getTransactJob(self, from_user, to_user, date):
|
||||
debug.info("get transact job from user {{ {} }} to user {{ {} }} on {{ {} }}".format(
|
||||
from_user, to_user, date))
|
||||
retVal = db.getTransactJob(from_user, to_user, date.date())
|
||||
debug.debug("transact job is {{ {} }}".format(retVal))
|
||||
return retVal
|
||||
|
||||
def deleteTransactJob(self, from_user, to_user, date):
|
||||
debug.info("delete transact job from user {{ {} }} to user {{ {} }} on {{ {} }}".format(
|
||||
from_user, to_user, date))
|
||||
transactJob = self.getTransactJob(from_user, to_user, date)
|
||||
debug.debug("transact job is {{ {} }}".format(transactJob))
|
||||
if transactJob['answerd']:
|
||||
debug.warning(
|
||||
"transactjob {{ {} }} can not delete because is answerd")
|
||||
raise TansactJobIsAnswerdException(
|
||||
"TransactJob is already answerd")
|
||||
db.deleteTransactJob(from_user, to_user, date.date())
|
||||
|
||||
def answerdTransactJob(self, from_user, to_user, date, answer):
|
||||
debug.info("answer transact job from user {{ {} }} to user {{ {} }} on {{ {} }} with answer {{ {} }}".format(
|
||||
from_user, to_user, date, answer))
|
||||
transactJob = db.updateTransactJob(
|
||||
from_user, to_user, date.date(), answer)
|
||||
debug.debug("transactjob is {{ {} }}".format(transactJob))
|
||||
if answer:
|
||||
debug.info("add worker on date {{ {} }}".format(date))
|
||||
self.addWorker(to_user.uid, date)
|
||||
return transactJob
|
|
@ -1,3 +1,5 @@
|
|||
from datetime import time, datetime
|
||||
|
||||
import geruecht.controller.databaseController as dc
|
||||
from geruecht.exceptions import DayLocked
|
||||
from geruecht.logger import getDebugLogger
|
||||
|
@ -47,19 +49,6 @@ class Base:
|
|||
lockedDay = self.getLockedDay(date)
|
||||
if lockedDay:
|
||||
if lockedDay['locked']:
|
||||
debug.debug(
|
||||
"day is locked, check if accepted transact job exists")
|
||||
transactJobs = self.getTransactJobFromUser(user, date)
|
||||
debug.debug(
|
||||
"transact job is {{ {} }}".format(transactJobs))
|
||||
found = False
|
||||
for job in transactJobs:
|
||||
if job['accepted'] and job['answerd']:
|
||||
debug.debug("accepted transact job exists")
|
||||
found = True
|
||||
break
|
||||
if not found:
|
||||
debug.debug("no accepted transact job found")
|
||||
raise DayLocked(
|
||||
"Day is locked. You can't delete the Job")
|
||||
db.deleteWorker(user, date)
|
|
@ -81,7 +81,7 @@ def _getStatus(**kwargs):
|
|||
|
||||
|
||||
@app.route('/getUsers', methods=['GET'])
|
||||
@login_required(groups=[MONEY, GASTRO, VORSTAND], bar=True)
|
||||
@login_required(groups=[USER], bar=True)
|
||||
def _getUsers(**kwargs):
|
||||
try:
|
||||
extern = True
|
||||
|
|
|
@ -2,7 +2,7 @@ from flask import Blueprint, request, jsonify
|
|||
from geruecht.decorator import login_required
|
||||
import geruecht.controller.mainController as mc
|
||||
from geruecht.model import USER
|
||||
from datetime import datetime, time
|
||||
from datetime import datetime, time, date
|
||||
from geruecht.exceptions import DayLocked
|
||||
from geruecht.logger import getDebugLogger, getCreditLogger, getJobsLogger
|
||||
|
||||
|
@ -113,6 +113,35 @@ def _getUsers(**kwrags):
|
|||
debug.debug("exception", exc_info=True)
|
||||
return jsonify({"error": str(err)}), 500
|
||||
|
||||
@user.route("/user/jobsOnDates", methods=['POST'])
|
||||
@login_required(groups=[USER])
|
||||
def _getJobsOnDates(**kwargs):
|
||||
debug.info("/user/jobsOnDates")
|
||||
try:
|
||||
data = request.get_json()
|
||||
lockedDays = mainController.getLockedDaysFromList(data)
|
||||
retVal = []
|
||||
for lockedDay in lockedDays:
|
||||
day = datetime.combine(lockedDay['daydate'], time(12))
|
||||
retDay = {
|
||||
"worker": mainController.getWorker(day),
|
||||
"day": {
|
||||
"date": {
|
||||
"year": day.year,
|
||||
"month": day.month,
|
||||
"day": day.day
|
||||
},
|
||||
"locked": lockedDay['locked']
|
||||
},
|
||||
"jobkinddate": mainController.getJobKindDates(day.date())
|
||||
}
|
||||
retVal.append(retDay)
|
||||
|
||||
debug.debug("return {{ {} }}".format(retVal))
|
||||
return jsonify(retVal)
|
||||
except Exception as err:
|
||||
debug.debug("exception", exc_info=True)
|
||||
return jsonify({"error": str(err)}), 500
|
||||
|
||||
@user.route("/user/job", methods=['POST'])
|
||||
@login_required(groups=[USER])
|
||||
|
@ -198,10 +227,11 @@ def _deletJob(**kwargs):
|
|||
year = data['year']
|
||||
date = datetime(year, month, day, 12)
|
||||
mainController.deleteWorker(user.uid, date, True)
|
||||
retVal = mainController.getWorker(date)
|
||||
debug.debug("return ok")
|
||||
jobL.info("Mitglied {} {} entfernt sich am {} aus dem Dienst".format(
|
||||
user.firstname, user.lastname, date.date()))
|
||||
return jsonify({"ok": "ok"})
|
||||
return jsonify(retVal)
|
||||
except DayLocked as err:
|
||||
debug.debug("exception", exc_info=True)
|
||||
return jsonify({"error": str(err)}), 403
|
||||
|
@ -209,148 +239,6 @@ def _deletJob(**kwargs):
|
|||
debug.debug("exception", exc_info=True)
|
||||
return jsonify({"error": str(err)}), 409
|
||||
|
||||
|
||||
@user.route("/user/transactJob", methods=['POST'])
|
||||
@login_required(groups=[USER])
|
||||
def _transactJob(**kwargs):
|
||||
debug.info("/user/transactJob")
|
||||
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 = mainController.getUser(username)
|
||||
retVal = mainController.setTransactJob(user, to_user, date)
|
||||
from_userl = retVal['from_user']
|
||||
to_userl = retVal['to_user']
|
||||
retVal['from_user'] = retVal['from_user'].toJSON()
|
||||
retVal['to_user'] = retVal['to_user'].toJSON()
|
||||
retVal['date'] = {'year': year, 'month': month, 'day': day}
|
||||
debug.debug("return {{ {} }}".format(retVal))
|
||||
jobL.info("Mitglied {} {} sendet Dienstanfrage an Mitglied {} {} am {}".format(
|
||||
from_userl.firstname, from_userl.lastname, to_userl.firstname, to_userl.lastname, date.date()))
|
||||
return jsonify(retVal)
|
||||
except Exception as err:
|
||||
debug.debug("exception", exc_info=True)
|
||||
return jsonify({"error": str(err)}), 409
|
||||
|
||||
|
||||
@user.route("/user/answerTransactJob", methods=['POST'])
|
||||
@login_required(groups=[USER])
|
||||
def _answer(**kwargs):
|
||||
debug.info("/user/answerTransactJob")
|
||||
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 = mainController.getUser(username)
|
||||
retVal = mainController.answerdTransactJob(
|
||||
from_user, user, date, answer)
|
||||
from_userl = retVal['from_user']
|
||||
to_userl = retVal['to_user']
|
||||
retVal['from_user'] = retVal['from_user'].toJSON()
|
||||
retVal['to_user'] = retVal['to_user'].toJSON()
|
||||
retVal['date'] = {'year': year, 'month': month, 'day': day}
|
||||
debug.debug("return {{ {} }}".format(retVal))
|
||||
jobL.info("Mitglied {} {} beantwortet Dienstanfrage von {} {} am {} mit {}".format(to_userl.firstname,
|
||||
to_userl.lastname, from_userl.firstname, from_userl.lastname, date.date(), 'JA' if answer else 'NEIN'))
|
||||
return jsonify(retVal)
|
||||
except Exception as err:
|
||||
debug.debug("exception", exc_info=True)
|
||||
return jsonify({"error": str(err)}), 409
|
||||
|
||||
|
||||
@user.route("/user/jobRequests", methods=['POST'])
|
||||
@login_required(groups=[USER])
|
||||
def _requests(**kwargs):
|
||||
debug.info("/user/jobRequests")
|
||||
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 = mainController.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}
|
||||
debug.debug("return {{ {} }}".format(retVal))
|
||||
return jsonify(retVal)
|
||||
except Exception as err:
|
||||
debug.debug("exception", exc_info=True)
|
||||
return jsonify({"error": str(err)}), 409
|
||||
|
||||
|
||||
@user.route("/user/getTransactJobs", methods=['POST'])
|
||||
@login_required(groups=[USER])
|
||||
def _getTransactJobs(**kwargs):
|
||||
debug.info("/user/getTransactJobs")
|
||||
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 = mainController.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}
|
||||
debug.debug("return {{ {} }}".format(retVal))
|
||||
return jsonify(retVal)
|
||||
except Exception as err:
|
||||
debug.debug("exception", exc_info=True)
|
||||
return jsonify({"error": str(err)}), 409
|
||||
|
||||
|
||||
@user.route("/user/deleteTransactJob", methods=['POST'])
|
||||
@login_required(groups=[USER])
|
||||
def _deleteTransactJob(**kwargs):
|
||||
debug.info("/user/deleteTransactJob")
|
||||
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 = mainController.getUser(username)
|
||||
mainController.deleteTransactJob(from_user, to_user, date)
|
||||
debug.debug("return ok")
|
||||
jobL.info("Mitglied {} {} entfernt Dienstanfrage an {} {} am {}".format(
|
||||
from_user.firstname, from_user.lastname, to_user.firstname, to_user.lastname, date.date()))
|
||||
return jsonify({"ok": "ok"})
|
||||
except Exception as err:
|
||||
debug.debug("exception", exc_info=True)
|
||||
return jsonify({"error": str(err)}), 409
|
||||
|
||||
|
||||
@user.route("/user/storno", methods=['POST'])
|
||||
@login_required(groups=[USER])
|
||||
def _storno(**kwargs):
|
||||
|
@ -384,4 +272,60 @@ def _storno(**kwargs):
|
|||
return jsonify(retVal)
|
||||
except Exception as err:
|
||||
debug.debug("exception", exc_info=True)
|
||||
return jsonify({"error": str(err)}), 409
|
||||
return jsonify({"error": str(err)}), 500
|
||||
|
||||
|
||||
@user.route("/user/getJobInvites", methods=['POST'])
|
||||
@login_required(groups=[USER])
|
||||
def _getJobInvites(**kwargs):
|
||||
try:
|
||||
debug.info("/user/getJobInvites")
|
||||
from_user = None
|
||||
to_user = None
|
||||
on_date = None
|
||||
|
||||
data = request.get_json()
|
||||
|
||||
if 'from_user' in data:
|
||||
from_user = data['from_user']
|
||||
if 'to_user' in data:
|
||||
to_user = data['to_user']
|
||||
on_date = date(data['date']['year'], data['date']['month'], data['date']['day'])
|
||||
retVal = mainController.getJobInvites(from_user, to_user, on_date)
|
||||
debug.debug("return {{ {} }}".format(retVal))
|
||||
return jsonify(retVal)
|
||||
except Exception as err:
|
||||
debug.debug("exception", exc_info=True)
|
||||
return jsonify({"error": str(err)}), 500
|
||||
|
||||
@user.route("/user/JobInvites", methods=['PUT', 'POST'])
|
||||
@login_required(groups=[USER])
|
||||
def _JobInvites(**kwargs):
|
||||
try:
|
||||
debug.info("/user/JobInvites")
|
||||
data = request.get_json()
|
||||
if request.method == 'PUT':
|
||||
mainController.setJobInvites(data)
|
||||
retVal = mainController.getJobInvites(kwargs['accToken'].user.toJSON(), None, datetime.now().date())
|
||||
debug.debug("return {{ {} }}".format(retVal))
|
||||
if request.method == 'POST':
|
||||
retVal = mainController.updateJobInvites(data)
|
||||
|
||||
return jsonify(retVal)
|
||||
except Exception as err:
|
||||
debug.debug("exception", exc_info=True)
|
||||
return jsonify({"error": str(err)}), 500
|
||||
|
||||
@user.route("/user/deleteJobInvite", methods=['POST'])
|
||||
@login_required(groups=[USER])
|
||||
def _deleteJobInvite(**kwargs):
|
||||
try:
|
||||
debug.info("/user/deleteJobInvite")
|
||||
data = request.get_json()
|
||||
mainController.deleteJobInvite(data)
|
||||
retVal = mainController.getJobInvites(data['from_user'], None, datetime.now().date())
|
||||
debug.debug("return {{ {} }}".format(retVal))
|
||||
return jsonify(retVal)
|
||||
except Exception as err:
|
||||
debug.debug("exception", exc_info=True)
|
||||
return jsonify({"error": str(err)}), 500
|
Loading…
Reference in New Issue