def menulist(): if request.method == "POST": id = str(request.data.get('id', '')) if id: menu = Menu(id=id, title=request.data.get("title"), nodes=request.data.get("nodes"), label=request.data.get("label")) menu.save() response = jsonify({ 'id': menu.id, 'title': menu.title, 'nodes': menu.nodes, 'label': menu.label, 'date_created': menu.date_created, 'date_modified': menu.date_modified }) response.status_code = 201 return response else: # GET menus = Menu.get_all() results = [] for menu in menus: obj = { 'count': menu.count, 'id': menu.id, 'title': menu.title, 'nodes': menu.nodes, 'label': menu.label, 'date_created': menu.date_created, 'date_modified': menu.date_modified } results.append(obj) response = jsonify(results) response.status_code = 200 return response
def delete(current_user, self): """Clear all the contents in menu""" if not current_user.type_admin: response = jsonify( {"message": "Not authorized to perform this function!"}) response.status_code = 401 return response menu = Menu.get_all() if not menu: response = jsonify({"message": "Menu not set yet!"}) response.status_code = 404 return response try: Menu.clear() response = jsonify({"message": "Menu cleared succesfully"}) response.status_code = 200 return response except Exception as e: response = jsonify({"message": e}) response.status_code = 200 return response
def get(current_user, self): menu = Menu.get_all() if not menu: response = jsonify({"message": "Menu not set yet!"}) response.status_code = 404 return response res = [] for meal in menu: meal_obj = { meal.id: { 'meal_name': meal.m_name, 'category': meal.category, 'price': meal.price } } res.append(meal_obj) response = jsonify(res) response.status_code = 200 return response