예제 #1
0
    def post_dish(jwt):
        """Adds a dish. Requires authentication and permission"""
        try:
            res = request.get_json()
            if not res:
                abort(404)

            if 'name' in res and 'ingredient' in res:
                ing = res.pop('ingredient')
                dish = Dish(**res)

                if ing:
                    for i in ing:
                        ingredient = Ingredient(**i, dish_id=dish.id)
                        dish.ingredient.append(ingredient)

                dish.insert()
                result = {"success": True, "result": dish.format()}
                return jsonify(result)
        except TypeError:
            print(sys.exc_info())
            abort(400)
예제 #2
0
def test_data(client):
    pizza = Dish(name='pizza', price=10)
    pizza.ingredient = [
        Ingredient(dish_id=pizza.id, name='tomato', allergen=''),
        Ingredient(dish_id=pizza.id, name='cheese', allergen='milk'),
        Ingredient(dish_id=pizza.id, name='flour', allergen='wheat'),
    ]
    pizza.insert()

    salad = Dish(name='salad', price=5)
    salad.ingredient = [
        Ingredient(dish_id=salad.id, name='potato', allergen=''),
        Ingredient(dish_id=salad.id, name='nuts', allergen='peanut'),
        Ingredient(dish_id=salad.id, name='kale', allergen=''),
    ]
    salad.insert()

    icecream = Dish(name='icecream', price=5)
    icecream.ingredient = [
        Ingredient(dish_id=icecream.id, name='cream', allergen='milk'),
    ]
    icecream.insert()
예제 #3
0
 def add_new_dishes(jwt):
     data = request.get_json()
     dish = Dish(data['name'], data['image_link'],
                 json.dumps(data['ingredients']))
     dish.insert()
     return jsonify({'success': True})