def create_cupcake(): """ Add a cupcake and returndata about new cupcake Returns JSON: { cupcake: [ { id, flavor, rating, size, image } ] } """ data = request.json cupcake = Cupcake(flavor=data['flavor'], rating=data['rating'], size=data['size'], image=data['image'] or None) db.session.add(cupcake) db.session.commit() # POST requests should return HTTP status of 201 return (jsonify(cupcake=cupcake.to_dict()), 201)
def create_cupcake(): data = request.json new_cupcake = Cupcake(flavor=data['flavor'], rating=data['rating'], size=data['size'], image=data['image'] or None) db.session.add(new_cupcake) db.session.commit() response_json = jsonify(cupcake=new_cupcake.to_dict()) return (response_json, 201)
def create_cupcake(): """Create a cupcake from data and return it""" cupcake = Cupcake(flavor=request.json['flavor'], rating=request.json['rating'], size=request.json['size'], image=request.json['image'] or None) db.session.add(cupcake) db.session.commit() return (jsonify(cupcake=cupcake.to_dict()), 201)
def add_cupcake(): data = request.json cupcake = Cupcake(flavor=data['flavor'], rating=data['rating'], size=data['size'], image=data['image'] or None) db.session.add(cupcake) db.session.commit() return (jsonify(cupcake=cupcake.to_dict()), 201)
def create_cupcake(): """Adds cupcake, and returns data about new cupcake.""" data = request.json cupcake = Cupcake(flavor=data['flavor'], rating=data['rating'], size=data['size'], image=data['image'] or None) db.session.add(cupcake) db.session.commit() res_json = jsonify(cupcake=cupcake.to_dict()) return (res_json, 201)
def make_cupcake(): """Returns JSON like: {cupcake: [{id, flavor, rating, size, image}]} """ flavor = request.json['flavor'] rating = request.json['rating'] size = request.json['size'] image = request.json['image'] or None new_cupcake = Cupcake( flavor=flavor, rating=rating, size=size, image=image ) db.session.add(new_cupcake) db.session.commit() cupcake_json = jsonify(cupcake=new_cupcake.to_dict()) # POST requests should return HTTP status of 201 CREATED return (cupcake_json, 201)