finished ##203
This commit is contained in:
parent
f296986924
commit
3e61893baf
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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():
|
||||
|
|
Loading…
Reference in New Issue