示例#1
0
def remove_single_cart():
    current_user = User.get_by_id(get_jwt_identity())

    if current_user:
        name = request.form.get("name")
        ingredient = Ingredient.get(name=name)
        delete = Cart.delete().where(Cart.ingredient_id==ingredient.id, Cart.user_id == current_user.id)
        delete.execute()
        return jsonify({"data":"Ingredient has been removed from cart!"})
    else:
        return error
示例#2
0
def new_cart():
    current_user = User.get_by_id(get_jwt_identity())
    if current_user:
        name = request.form.get("name")
        ingredient = Ingredient.get(name=name)
        quantity = request.form.get("quantity")
        amount = int(quantity)*ingredient.price
        cart = Cart(quantity=quantity, amount=amount, user_id = current_user.id, ingredient_id = ingredient.id)
        if cart.save():
            return jsonify({"message" : "Ingredient has been successfully added into cart!"})
        else:
            return jsonify({"message": "Ingredient exists in cart already!"})
    else:
        return error