finished ##250 and ##249
This commit is contained in:
parent
381cc1c028
commit
c9fe61b1dc
|
@ -573,6 +573,70 @@ class DatabaseController(metaclass=Singleton):
|
|||
self.db.connection.rollback()
|
||||
raise DatabaseExecption("Something went worng with Databes: {}".format(err))
|
||||
|
||||
def getAllWorkgroups(self):
|
||||
try:
|
||||
cursor = self.db.connection.cursor()
|
||||
cursor.execute('select * from workgroup')
|
||||
list = cursor.fetchall()
|
||||
for item in list:
|
||||
if item['boss'] != None:
|
||||
item['boss']=self.getUserById(item['boss'])
|
||||
return list
|
||||
except Exception as err:
|
||||
traceback.print_exc()
|
||||
self.db.connection.rollback()
|
||||
raise DatabaseExecption("Something went worng with Databes: {}".format(err))
|
||||
|
||||
def getWorkgroup(self, name):
|
||||
try:
|
||||
cursor = self.db.connection.cursor()
|
||||
if type(name) == str:
|
||||
sql = "select * from workgroup where name='{}'".format(name)
|
||||
elif type(name) == int:
|
||||
sql = 'select * from workgroup where id={}'.format(name)
|
||||
else:
|
||||
raise DatabaseExecption("name as no type int or str. name={}, type={}".format(name, type(name)))
|
||||
cursor.execute(sql)
|
||||
retVal = cursor.fetchone()
|
||||
retVal['boss'] = self.getUserById(retVal['boss']) if retVal['boss'] != None else None
|
||||
return retVal
|
||||
except Exception as err:
|
||||
traceback.print_exc()
|
||||
self.db.connection.rollback()
|
||||
raise DatabaseExecption("Something went worng with Databes: {}".format(err))
|
||||
|
||||
def setWorkgroup(self, name, boss):
|
||||
try:
|
||||
cursor = self.db.connection.cursor()
|
||||
cursor.execute("insert into workgroup (name, boss) values ('{}', {})".format(name, boss['id']))
|
||||
self.db.connection.commit()
|
||||
return self.getWorkgroup(name)
|
||||
except Exception as err:
|
||||
traceback.print_exc()
|
||||
self.db.connection.rollback()
|
||||
raise DatabaseExecption("Something went worng with Databes: {}".format(err))
|
||||
|
||||
def updateWorkgroup(self, workgroup):
|
||||
try:
|
||||
cursor = self.db.connection.cursor()
|
||||
cursor.execute("update workgroup set name='{}', boss={} where id={}".format(workgroup['name'], workgroup['boss']['id'], workgroup['id']))
|
||||
self.db.connection.commit()
|
||||
return self.getWorkgroup(workgroup['id'])
|
||||
except Exception as err:
|
||||
traceback.print_exc()
|
||||
self.db.connection.rollback()
|
||||
raise DatabaseExecption("Something went worng with Databes: {}".format(err))
|
||||
|
||||
def deleteWorkgroup(self, workgroup):
|
||||
try:
|
||||
cursor = self.db.connection.cursor()
|
||||
cursor.execute("delete from workgroup where id={}".format(workgroup['id']))
|
||||
self.db.connection.commit()
|
||||
except Exception as err:
|
||||
traceback.print_exc()
|
||||
self.db.connection.rollback()
|
||||
raise DatabaseExecption("Something went worng with Databes: {}".format(err))
|
||||
|
||||
if __name__ == '__main__':
|
||||
db = DatabaseController()
|
||||
user = db.getUser('jhille')
|
||||
|
|
|
@ -23,6 +23,35 @@ class UserController(metaclass=Singleton):
|
|||
debug.debug("init UserController")
|
||||
pass
|
||||
|
||||
def getAllWorkgroups(self):
|
||||
debug.info("get all workgroups")
|
||||
retVal = db.getAllWorkgroups()
|
||||
debug.debug("workgroups are {{ {} }}".format(retVal))
|
||||
return retVal
|
||||
|
||||
def getWorkgroups(self, name):
|
||||
debug.info("get Workgroup {{ {} }}".format(name))
|
||||
retVal = db.getWorkgroup(name)
|
||||
debug.debug("workgroup is {{ {} }} is {{ {} }}".format(name, retVal))
|
||||
return retVal
|
||||
|
||||
def setWorkgroup(self, name, boss):
|
||||
debug.info("set workgroup {{ {} }} with boss {{ {} }}".format(name, boss))
|
||||
retVal = db.setWorkgroup(name, boss)
|
||||
debug.debug(
|
||||
"seted workgroup {{ {} }} is {{ {} }}".format(name, retVal))
|
||||
return retVal
|
||||
|
||||
def deleteWorkgroup(self, workgroup):
|
||||
debug.info("delete workgroup {{ {} }}".format(workgroup))
|
||||
db.deleteWorkgroup(workgroup)
|
||||
|
||||
def updateWorkgroup(self, workgroup):
|
||||
debug.info("update workgroup {{ {} }}".format(workgroup))
|
||||
retVal = db.updateWorkgroup(workgroup)
|
||||
debug.debug("updated workgroup is {{ {} }}".format(retVal))
|
||||
return retVal
|
||||
|
||||
def getAllStatus(self):
|
||||
debug.info("get all status for user")
|
||||
retVal = db.getAllStatus()
|
||||
|
|
|
@ -197,6 +197,74 @@ def _deletUser(**kwargs):
|
|||
debug.debug("exception", exc_info=True)
|
||||
return jsonify({"error": str(err)}), 500
|
||||
|
||||
@vorstand.route("/wgm/getAllWorkgroups", methods=['GET'])
|
||||
@login_required(bar=True)
|
||||
def _getAllWorkgroups(**kwargs):
|
||||
try:
|
||||
debug.info("get all workgroups")
|
||||
retVal = userController.getAllWorkgroups()
|
||||
for item in retVal:
|
||||
item['boss'] = item['boss'].toJSON() if item['boss'] != None else None
|
||||
debug.info("return all workgroups {{ {} }}".format(retVal))
|
||||
return jsonify(retVal)
|
||||
except Exception as err:
|
||||
debug.warning("exception in get all workgroups.", exc_info=True)
|
||||
return jsonify({"error": str(err)}), 500
|
||||
|
||||
@vorstand.route("/wgm/getWorkgroup", methods=['POST'])
|
||||
@login_required(bar=True)
|
||||
def _getWorkgroup(**kwargs):
|
||||
try:
|
||||
debug.info("get workgroup")
|
||||
data = request.get_json()
|
||||
name = data['name']
|
||||
debug.info("get workgroup {{ {} }}".format(name))
|
||||
retVal = userController.getWorkgroups(name)
|
||||
debug.info(
|
||||
"return workgroup {{ {} }} : {{ {} }}".format(name, retVal))
|
||||
retVal['boss'] = retVal['boss'].toJSON() if retVal['boss'] != None else None
|
||||
return jsonify(retVal)
|
||||
except Exception as err:
|
||||
debug.warning("exception in get workgroup.", exc_info=True)
|
||||
return jsonify({"error": str(err)}), 500
|
||||
|
||||
@vorstand.route("/wgm/workgroup", methods=['POST', 'PUT', 'DELETE'])
|
||||
@login_required(groups=[MONEY, GASTRO, VORSTAND])
|
||||
def _workgroup(**kwargs):
|
||||
debug.info("/wgm/workgroup")
|
||||
try:
|
||||
data = request.get_json()
|
||||
if request.method == 'PUT':
|
||||
name = data['name']
|
||||
boss = None
|
||||
if 'boss' in data:
|
||||
boss = data['boss']
|
||||
retVal = userController.setWorkgroup(name, boss)
|
||||
retVal['boss'] = retVal['boss'].toJSON() if retVal['boss'] != None else None
|
||||
debug.debug("return {{ {} }}".format(retVal))
|
||||
if request.method == 'POST':
|
||||
retVal = userController.updateWorkgroup(data)
|
||||
retVal['boss'] = retVal['boss'].toJSON() if retVal['boss'] != None else None
|
||||
debug.debug("return {{ {} }}".format(retVal))
|
||||
return jsonify(retVal)
|
||||
except Exception as err:
|
||||
debug.debug("exception", exc_info=True)
|
||||
return jsonify({"error": str(err)}), 500
|
||||
|
||||
@vorstand.route("/wgm/deleteWorkgroup", methods=['POST'])
|
||||
@login_required(groups=[VORSTAND])
|
||||
def _deleteWorkgroup(**kwargs):
|
||||
try:
|
||||
data = request.get_json()
|
||||
debug.info("/wgm/deleteWorkgroup")
|
||||
userController.deleteWorkgroup(data)
|
||||
retVal = {"ok": "ok"}
|
||||
debug.debug("return ok")
|
||||
return jsonify(retVal)
|
||||
except Exception as err:
|
||||
debug.debug("exception", exc_info=True)
|
||||
return jsonify({"error": str(err)}), 500
|
||||
|
||||
|
||||
@vorstand.route("/sm/lockDay", methods=['POST'])
|
||||
@login_required(groups=[MONEY, GASTRO, VORSTAND])
|
||||
|
|
Loading…
Reference in New Issue