def pizzas(): if request.method == "POST": flavour = str(request.data.get('flavour', '')) size = str(request.data.get('size', '')) price = str(request.data.get('cost', '899')) crust = str(request.data.get('crust', '')) toppings = str(request.data.get('toppings', '')) if flavour: pizza = Pizza(flavour=flavour, size=size, price=price, crust=crust, toppings=toppings) pizza.save_pizza() response = jsonify({ 'id': pizza.id, 'flavour': pizza.flavour, 'size': pizza.size, 'price': pizza.price, 'crust': pizza.crust, 'toppings': pizza.toppings }) response.status_code = 201 return response else: pizzas = Pizza.get_all() results = [] for pizza in pizzas: obj = { 'id': pizza.id, 'flavour': pizza.flavour, 'size': pizza.size, 'price': pizza.price, 'crust': pizza.crust, 'toppings': pizza.toppings } results.append(obj) response = jsonify(results) return response
def pizzas(): if request.method == "POST": name = str(request.data.get('name', '')) size = str(request.data.get('size', '')) price = str(request.data.get('price', '')) crust = str(request.data.get('crust', '')) if name: piza = Pizza(name=name, size=size, price=price, crust=crust) piza.save() response = jsonify({ 'id': piza.id, 'name': piza.name, 'size': piza.size, 'price': piza.price, 'crust': piza.crust, }) response.status_code = 201 return response else: # GET piza = Pizza.get_all() results = [] results_obj = {} for items in piza: obj = { 'id': items.id, 'name': items.name, 'size': items.size, 'price': items.price, 'crust': items.crust, } results_obj["results"] = results results_obj.append(obj) response = jsonify(results_obj) response.status_code = 200 return response