def create_cupcake(): cupcake = Cupcake() cupcake.flavor = request.json.get('flavor') cupcake.size = request.json.get('size') cupcake.rating = request.json.get('rating') cupcake.image = request.json.get('image') if request.json.get( 'image') else None db.session.add(cupcake) db.session.commit() return jsonify(cupcake=cupcake.serializeCupcake()), 201
def create_cupcake(): """Create a new cupcake. Should return JSON {cupcake: {id, flavor, size, rating, image}}.""" new_cupcake = Cupcake() new_cupcake.flavor = request.json["flavor"] new_cupcake.size = request.json["size"] new_cupcake.rating = request.json["rating"] new_cupcake.image = request.json.get("image") or None db.session.add(new_cupcake) db.session.commit() serialized = new_cupcake.serialize() return (jsonify(cupcake=serialized), 201)