user kann jobrequest updaten, erstellen oder löschen
This commit is contained in:
parent
dcc9c5ee14
commit
b0f09969a5
|
@ -1,6 +1,6 @@
|
||||||
from ..mainController import Singleton
|
from ..mainController import Singleton
|
||||||
from geruecht import db
|
from geruecht import db
|
||||||
from ..databaseController import dbUserController, dbCreditListController, dbJobKindController, dbPricelistController, dbWorkerController, dbWorkgroupController, dbJobInviteController
|
from ..databaseController import dbUserController, dbCreditListController, dbJobKindController, dbPricelistController, dbWorkerController, dbWorkgroupController, dbJobInviteController, dbJobRequesController
|
||||||
from geruecht.exceptions import DatabaseExecption
|
from geruecht.exceptions import DatabaseExecption
|
||||||
import traceback
|
import traceback
|
||||||
from MySQLdb._exceptions import IntegrityError
|
from MySQLdb._exceptions import IntegrityError
|
||||||
|
@ -12,6 +12,7 @@ class DatabaseController(dbUserController.Base,
|
||||||
dbPricelistController.Base,
|
dbPricelistController.Base,
|
||||||
dbJobKindController.Base,
|
dbJobKindController.Base,
|
||||||
dbJobInviteController.Base,
|
dbJobInviteController.Base,
|
||||||
|
dbJobRequesController.Base,
|
||||||
metaclass=Singleton):
|
metaclass=Singleton):
|
||||||
'''
|
'''
|
||||||
DatabaesController
|
DatabaesController
|
||||||
|
|
|
@ -0,0 +1,97 @@
|
||||||
|
import traceback
|
||||||
|
|
||||||
|
from geruecht.exceptions import DatabaseExecption
|
||||||
|
|
||||||
|
|
||||||
|
class Base:
|
||||||
|
def getJobRequest(self, from_user, to_user, date, id=None):
|
||||||
|
try:
|
||||||
|
cursor = self.db.connection.cursor()
|
||||||
|
if id:
|
||||||
|
cursor.execute("select * from job_request where id={}".format(id))
|
||||||
|
else:
|
||||||
|
cursor.execute("select * from job_request 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}
|
||||||
|
retVal['job_kind'] = self.getJobKind(retVal['job_kind'])
|
||||||
|
return retVal
|
||||||
|
except Exception as err:
|
||||||
|
traceback.print_exc()
|
||||||
|
self.db.connection.rollback()
|
||||||
|
raise DatabaseExecption("Something went worng with Datatabase: {}".format(err))
|
||||||
|
|
||||||
|
def getJobRequestsFromUser(self, from_user, date):
|
||||||
|
try:
|
||||||
|
cursor = self.db.connection.cursor()
|
||||||
|
cursor.execute("select * from job_request 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}
|
||||||
|
item['job_kind'] = self.getJobKind(item['job_kind'])
|
||||||
|
return retVal
|
||||||
|
except Exception as err:
|
||||||
|
traceback.print_exc()
|
||||||
|
self.db.connection.rollback()
|
||||||
|
raise DatabaseExecption("Something went worng with Datatabase: {}".format(err))
|
||||||
|
|
||||||
|
def getJobRequestsToUser(self, to_user, date):
|
||||||
|
try:
|
||||||
|
cursor = self.db.connection.cursor()
|
||||||
|
cursor.execute("select * from job_request 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}
|
||||||
|
item['job_kind'] = self.getJobKind(item['job_kind'])
|
||||||
|
return retVal
|
||||||
|
except Exception as err:
|
||||||
|
traceback.print_exc()
|
||||||
|
self.db.connection.rollback()
|
||||||
|
raise DatabaseExecption("Something went worng with Datatabase: {}".format(err))
|
||||||
|
|
||||||
|
def setJobRequest(self, from_user, to_user, date, job_kind):
|
||||||
|
try:
|
||||||
|
cursor = self.db.connection.cursor()
|
||||||
|
cursor.execute("insert into job_request (from_user, to_user, on_date, job_kind) values ({}, {}, '{}', {})".format(from_user['id'], to_user['id'], date, job_kind['id']))
|
||||||
|
self.db.connection.commit()
|
||||||
|
return self.getJobRequest(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 updateJobRequest(self, jobrequest):
|
||||||
|
try:
|
||||||
|
cursor = self.db.connection.cursor()
|
||||||
|
cursor.execute("update job_request set watched={}, answered={} where id={}".format(jobrequest['watched'], jobrequest['answered'], jobrequest['id']))
|
||||||
|
self.db.connection.commit()
|
||||||
|
return self.getJobRequest(None, None, None, jobrequest['id'])
|
||||||
|
except Exception as err:
|
||||||
|
traceback.print_exc()
|
||||||
|
self.db.connection.rollback()
|
||||||
|
raise DatabaseExecption("Something went worng with Datatabase: {}".format(err))
|
||||||
|
|
||||||
|
def updateAllJobRequest(self, jobrequest):
|
||||||
|
try:
|
||||||
|
cursor = self.db.connection.cursor()
|
||||||
|
cursor.execute("update job_request set answered={}, accepted={} where from_user={} and on_date='{}'".format(jobrequest['answered'], jobrequest['accepted'], jobrequest['from_user']['id'], jobrequest['on_date']))
|
||||||
|
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 deleteJobRequest(self, jobrequest):
|
||||||
|
try:
|
||||||
|
cursor = self.db.connection.cursor()
|
||||||
|
cursor.execute("delete from job_request where id={}".format(jobrequest['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))
|
|
@ -46,6 +46,16 @@ class Base:
|
||||||
self.db.connection.rollback()
|
self.db.connection.rollback()
|
||||||
raise DatabaseExecption("Something went worng with Datatabase: {}".format(err))
|
raise DatabaseExecption("Something went worng with Datatabase: {}".format(err))
|
||||||
|
|
||||||
|
def changeWorker(self, from_user, to_user, date):
|
||||||
|
try:
|
||||||
|
cursor = self.db.connection.cursor()
|
||||||
|
cursor.execute("update bardienste set user_id={} where user_id={} and startdatetime='{}'".format(to_user['id'], from_user['id'], date))
|
||||||
|
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 deleteAllWorkerWithJobKind(self, date, job_kind):
|
def deleteAllWorkerWithJobKind(self, date, job_kind):
|
||||||
try:
|
try:
|
||||||
cursor = self.db.connection.cursor()
|
cursor = self.db.connection.cursor()
|
||||||
|
|
|
@ -5,7 +5,7 @@ import geruecht.controller.emailController as ec
|
||||||
from geruecht.model.user import User
|
from geruecht.model.user import User
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from geruecht.logger import getDebugLogger
|
from geruecht.logger import getDebugLogger
|
||||||
from ..mainController import mainJobKindController, mainCreditListController, mainPricelistController, mainUserController, mainWorkerController, mainWorkgroupController, mainJobInviteController
|
from ..mainController import mainJobKindController, mainCreditListController, mainPricelistController, mainUserController, mainWorkerController, mainWorkgroupController, mainJobInviteController, mainJobRequestController
|
||||||
|
|
||||||
db = dc.DatabaseController()
|
db = dc.DatabaseController()
|
||||||
ldap = lc.LDAPController()
|
ldap = lc.LDAPController()
|
||||||
|
@ -21,6 +21,7 @@ class MainController(mainJobKindController.Base,
|
||||||
mainWorkerController.Base,
|
mainWorkerController.Base,
|
||||||
mainWorkgroupController.Base,
|
mainWorkgroupController.Base,
|
||||||
mainJobInviteController.Base,
|
mainJobInviteController.Base,
|
||||||
|
mainJobRequestController.Base,
|
||||||
metaclass=Singleton):
|
metaclass=Singleton):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
from datetime import date, time, datetime
|
||||||
|
|
||||||
|
import geruecht.controller.databaseController as dc
|
||||||
|
from geruecht import getDebugLogger
|
||||||
|
|
||||||
|
db = dc.DatabaseController()
|
||||||
|
debug = getDebugLogger()
|
||||||
|
|
||||||
|
class Base:
|
||||||
|
def getJobRequests(self, from_user, to_user, date):
|
||||||
|
debug.info("get JobRequests from_user {{ {} }} to_user {{ {} }} on date {{ {} }}".format(from_user, to_user, date))
|
||||||
|
if from_user is None:
|
||||||
|
retVal = db.getJobRequestsToUser(to_user, date)
|
||||||
|
elif to_user is None:
|
||||||
|
retVal = db.getJobRequestsFromUser(from_user, date)
|
||||||
|
else:
|
||||||
|
raise Exception("from_user {{ {} }} and to_user {{ {} }} are None".format(from_user, to_user))
|
||||||
|
return retVal
|
||||||
|
|
||||||
|
def setJobRequests(self, data):
|
||||||
|
debug.info("set new JobRequests data {{ {} }}".format(data))
|
||||||
|
retVal = []
|
||||||
|
for jobRequest in data:
|
||||||
|
from_user = jobRequest['from_user']
|
||||||
|
to_user = jobRequest['to_user']
|
||||||
|
on_date = date(jobRequest['date']['year'], jobRequest['date']['month'], jobRequest['date']['day'])
|
||||||
|
debug.info("set new JobRequest from_user {{ {} }}, to_user {{ {} }}, on_date {{ {} }}")
|
||||||
|
retVal.append(db.setJobRequest(from_user, to_user, on_date))
|
||||||
|
debug.debug("seted JobRequests are {{ {} }}".format(retVal))
|
||||||
|
return retVal
|
||||||
|
|
||||||
|
def updateJobRequests(self, data):
|
||||||
|
debug.info("update JobRequest data {{ {} }}".format(data))
|
||||||
|
if data['accepted']:
|
||||||
|
self.changeWorker(data['from_user'], data['to_user'], datetime.combine(data['on_date'], time(12)))
|
||||||
|
db.updateAllJobRequest(data)
|
||||||
|
return db.updateJobRequest(data)
|
||||||
|
|
||||||
|
def deleteJobRequest(self, jobRequest):
|
||||||
|
debug.info("delete JobRequest {{ {} }}".format(jobRequest))
|
||||||
|
db.deleteJobRequest(jobRequest)
|
|
@ -39,6 +39,10 @@ class Base:
|
||||||
debug.debug("worker on date is {{ {} }}".format(retVal))
|
debug.debug("worker on date is {{ {} }}".format(retVal))
|
||||||
return retVal
|
return retVal
|
||||||
|
|
||||||
|
def changeWorker(self, from_user, to_user, date):
|
||||||
|
debug.info("change worker from {{ {} }} to {{ {} }} on {{ {} }}".format(from_user, to_user, date))
|
||||||
|
db.changeWorker(from_user, to_user, date)
|
||||||
|
|
||||||
def deleteWorker(self, username, date, userExc=False):
|
def deleteWorker(self, username, date, userExc=False):
|
||||||
debug.info(
|
debug.info(
|
||||||
"delete worker {{ {} }} on date {{ {} }}".format(username, date))
|
"delete worker {{ {} }} on date {{ {} }}".format(username, date))
|
||||||
|
|
|
@ -326,6 +326,63 @@ def _deleteJobInvite(**kwargs):
|
||||||
retVal = mainController.getJobInvites(data['from_user'], None, datetime.now().date())
|
retVal = mainController.getJobInvites(data['from_user'], None, datetime.now().date())
|
||||||
debug.debug("return {{ {} }}".format(retVal))
|
debug.debug("return {{ {} }}".format(retVal))
|
||||||
return jsonify(retVal)
|
return jsonify(retVal)
|
||||||
|
except Exception as err:
|
||||||
|
debug.debug("exception", exc_info=True)
|
||||||
|
return jsonify({"error": str(err)}), 500
|
||||||
|
|
||||||
|
|
||||||
|
@user.route("/user/getJobRequests", methods=['POST'])
|
||||||
|
@login_required(groups=[USER])
|
||||||
|
def _getJobRequests(**kwargs):
|
||||||
|
try:
|
||||||
|
debug.info("/user/getJobRequests")
|
||||||
|
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.getJobRequests(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/JobRequests", methods=['PUT', 'POST'])
|
||||||
|
@login_required(groups=[USER])
|
||||||
|
def _JobRequests(**kwargs):
|
||||||
|
try:
|
||||||
|
debug.info("/user/JobRequests")
|
||||||
|
data = request.get_json()
|
||||||
|
data['on_date'] = date(data['on_date']['year'], data['on_date']['month'], data['on_date']['day'])
|
||||||
|
if request.method == 'PUT':
|
||||||
|
mainController.setJobRequests(data)
|
||||||
|
retVal = mainController.getJobRequests(kwargs['accToken'].user.toJSON(), None, datetime.now().date())
|
||||||
|
debug.debug("return {{ {} }}".format(retVal))
|
||||||
|
if request.method == 'POST':
|
||||||
|
retVal = mainController.updateJobRequests(data)
|
||||||
|
|
||||||
|
return jsonify(retVal)
|
||||||
|
except Exception as err:
|
||||||
|
debug.debug("exception", exc_info=True)
|
||||||
|
return jsonify({"error": str(err)}), 500
|
||||||
|
|
||||||
|
@user.route("/user/deleteJobRequest", methods=['POST'])
|
||||||
|
@login_required(groups=[USER])
|
||||||
|
def _deleteJobRequest(**kwargs):
|
||||||
|
try:
|
||||||
|
debug.info("/user/deleteJobRequest")
|
||||||
|
data = request.get_json()
|
||||||
|
mainController.deleteJobRequest(data)
|
||||||
|
retVal = mainController.getJobRequests(data['from_user'], None, datetime.now().date())
|
||||||
|
debug.debug("return {{ {} }}".format(retVal))
|
||||||
|
return jsonify(retVal)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
debug.debug("exception", exc_info=True)
|
debug.debug("exception", exc_info=True)
|
||||||
return jsonify({"error": str(err)}), 500
|
return jsonify({"error": str(err)}), 500
|
Loading…
Reference in New Issue