Exemplo n.º 1
0
def post_cupcake():
    """Post cupcake"""
    new_cupcake = Cupcake(flavor=request.json["flavor"], size=request.json['size'], rating=request.json['rating'],image=request.json['image'])
    db.session.add(new_cupcake)
    db.session.commit()
    response_json = jsonify(cupcake=new_cupcake.serialize_cupcake())
    return (response_json,201)
Exemplo n.º 2
0
def create_cupcake():
    new_cupcake = Cupcake(
        flavor=request.json["flavor"],
        size=request.json["size"],
        rating=request.json["rating"],
        image=request.json["image"],
    )
    db.session.add(new_cupcake)
    db.session.commit()
    return (jsonify(cupcake=new_cupcake.serialize_cupcake()), 201)
Exemplo n.º 3
0
def create_cupcake():
    cupcake = Cupcake(flavor=request.json.get('flavor'),
                      size=request.json.get('size'),
                      rating=request.json.get('rating'),
                      image=request.json.get(
                          'image', 'https://tinyurl.com/demo-cupcake'))

    db.session.add(cupcake)
    db.session.commit()

    serialized = cupcake.serialize_cupcake()

    return (jsonify(cupcake=serialized), 201)
Exemplo n.º 4
0
def create_cupcake():
    """This view function creates cupcake in the cupcakes db and returns JSON"""

    flavor = request.json["flavor"]
    size = request.json["size"]
    rating = request.json["rating"]
    image = request.json["image"]

    new_cupcake = Cupcake(flavor=flavor, size=size, rating=rating, image=image)

    db.session.add(new_cupcake)
    db.session.commit()

    serialized = new_cupcake.serialize_cupcake()

    # We return with status code 201 ---- return tuple (json, status_code)
    return (jsonify(cupcake=serialized), 201)
Exemplo n.º 5
0
def add_cupcake():
    new_cupcake=Cupcake(flavor=request.json['flavor'], size=request.json['size'], rating=request.json['rating'], image=request.json['image'])
    db.session.add(new_cupcake)
    db.session.commit()
    resp_json = jsonify(cupcake=new_cupcake.serialize_cupcake())
    return (resp_json, 201)