finished ##203

This commit is contained in:
Tim Gröger 2020-02-27 21:55:00 +01:00
parent f296986924
commit 3e61893baf
3 changed files with 42 additions and 0 deletions

View File

@ -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()

View File

@ -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)

View File

@ -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():