Пример #1
0
def update_drink(payload, drink_id):
    drink = Drink.get_by_id(drink_id)

    if drink is None:
        abort(404)

    data = request.get_json()
    title = data.get("title", None)
    recipe = json.dumps(data.get("recipe", None))

    if title is None or recipe is None:
        abort(400)

    drink.title = title
    drink.recipe = recipe
    result = drink.insert()

    if result["error"]:
        abort(500)

    return (
        jsonify({
            "drinks": [Drink.get_by_id(drink_id).long()],
            "success": True,
        }),
        200,
    )
Пример #2
0
def delete_drink(payload, drink_id):
    drink = Drink.get_by_id(drink_id)

    if drink is None:
        abort(404)

    result = drink.delete()

    if result["error"]:
        abort(500)

    return jsonify({
        "delete": drink_id,
        "success": True,
    })
Пример #3
0
def create_drink(payload):
    data = request.get_json()
    drink = Drink(**data)
    result = drink.insert()

    if result["error"]:
        abort(500)

    _id = result["id"]

    return (
        jsonify({
            "drinks": [Drink.get_by_id(_id).long()],
            "success": True,
        }),
        200,
    )