diff --git a/geruecht/controller/databaseController.py b/geruecht/controller/databaseController.py index b9c2ba3..124acbd 100644 --- a/geruecht/controller/databaseController.py +++ b/geruecht/controller/databaseController.py @@ -368,6 +368,31 @@ class DatabaseController(metaclass=Singleton): self.db.connection.rollback() raise DatabaseExecption("Something went wrong with Database: {}".format(err)) + def getPriceList(self): + try: + cursor = self.db.connection.cursor() + cursor.execute("select * from pricelist") + return cursor.fetchall() + except Exception as err: + traceback.print_exc() + self.db.connection.rollback() + raise DatabaseExecption("Something went wrong with Database: {}".format(err)) + + def getDrinkType(self, name): + try: + cursor = self.db.connection.cursor() + if type(name) == str: + sql = 'select * from drink_type where name={}'.format(name) + if type(name) == int: + sql = 'select * from drink_type where id={}'.format(name) + else: + raise DatabaseExecption("name as no type int or str. name={}, type={}".format(name, type(name))) + cursor.execute(sql) + return cursor.fetchone() + 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() diff --git a/geruecht/controller/userController.py b/geruecht/controller/userController.py index 852662f..f0a0d0e 100644 --- a/geruecht/controller/userController.py +++ b/geruecht/controller/userController.py @@ -17,6 +17,13 @@ class UserController(metaclass=Singleton): def __init__(self): pass + def getPricelist(self): + list = db.getPriceList() + for element in list: + type = db.getDrinkType(element['type']) + element['type'] = type['name'] + return list + def setTransactJob(self, from_user, to_user, date): jobtransact = db.setTransactJob(from_user, to_user, date.date()) emailController.sendMail(jobtransact['to_user'], 'jobtransact', jobtransact) diff --git a/geruecht/routes.py b/geruecht/routes.py index bd71ea5..2cc7c4d 100644 --- a/geruecht/routes.py +++ b/geruecht/routes.py @@ -29,6 +29,16 @@ def _valid(): return jsonify(accToken.user.toJSON()) return jsonify({"error": "permission denied"}), 401 +@app.route("/pricelist", methods=['GET']) +def _getPricelist(): + try: + retVal = userController.getPricelist() + print(retVal) + return jsonify(retVal) + except Exception as err: + return jsonify({"error": str(err)}) + + @app.route("/login", methods=['POST']) def _login():