def clear_shopcart (shopcart_id): """ Returns all of the items within the shopcart """ app.logger.info("Request to clear items from the shopping cart") shopcart = ShopCart.find_or_404(shopcart_id) results = [item.delete() for item in shopcart.items] return make_response("", status.HTTP_204_NO_CONTENT)
def list_items(shopcart_id): """ Returns all of the items within the shopcart """ app.logger.info("Request to list items from the shopping cart") shopcart = ShopCart.find_or_404(shopcart_id) results = [item.serialize() for item in shopcart.items] return make_response(jsonify(results), status.HTTP_200_OK)
def get_shopcarts(shopcart_id): """ Retrieve a single ShopCart This endpoint will return an ShopCart based on its id """ app.logger.info("Request for ShopCart with id: %s", shopcart_id) shopcart = ShopCart.find_or_404(shopcart_id) return make_response(jsonify(shopcart.serialize()), status.HTTP_200_OK)
def create_items(shopcart_id): """ Create an Item in a Shopcart This endpoint will add an item to a shopcart """ app.logger.info("Request to add an item to a shopcart") check_content_type("application/json") shopcart = ShopCart.find_or_404(shopcart_id) item = CartItem() item.deserialize(request.get_json()) shopcart.items.append(item) shopcart.save() message = item.serialize() return make_response(jsonify(message), status.HTTP_201_CREATED)