Beispiel #1
0
def drinks_insert(payload):
    try:
        data = json.loads(request.data)
        drink = Drink()
        if data.get('title', '') is None or data.get('title', '') == '':
            abort(400, "title must be submitted")
        drink.title = data.get('title', '')
        if data.get('recipe', []) is None or data.get('recipe', []) == []:
            abort(400, "recipe must be submitted")
        drink.recipe = str(data.get('recipe'))
        drink.insert()
        return jsonify({'success': True, 'drinks': [drink.long()]}), 200
    except exc.SQLAlchemyError as e:
        abort(500, ','.join(e.orig.args))
Beispiel #2
0
def post_drinks(payload):
    data = request.get_json()
    new_title = data['title']
    new_recipe = data['recipe']
    if isinstance(new_recipe, dict):
        new_recipe = [new_recipe]
    try:
        drink = Drink()
        drink.title = new_title
        drink.recipe = json.dumps(new_recipe)
        drink.insert()
    except:
        abort(422)
    long_drinks = drink.long()
    return jsonify({'success': True, 'drinks': long_drinks})
def create_drink(payload):
    # Get the body
    req = request.get_json()
    try:
        # create new Drink
        drink = Drink()
        drink.title = req['title']
        # convert recipe to String
        drink.recipe = json.dumps(req['recipe'])
        # insert the new Drink
        drink.insert()

    except Exception:
        abort(400)

    return jsonify({'success': True, 'drinks': [drink.long()]})
Beispiel #4
0
def create_drink(payload):
    req = request.get_json()

    try:
        req_recipe = req['recipe']
        if isinstance(req_recipe, dict):
            req_recipe = [req_recipe]

        drink = Drink()

        drink.title = req['title']
        drink.recipe = json.dumps(req_recipe)

        drink.insert()

    except BaseException:
        abort(400)

    return jsonify({'success': True, 'drinks': [drink.long()]})