def put(self, wishlist_id, product_id):
        """
        Update a Wishlist Product
        This endpoint will update a Product in a Wishlist
        """
        app.logger.info(
            'Request to update a product with id: %s in wishlist: %s',
            product_id, wishlist_id)
        check_content_type('application/json')

        wishlist = Wishlist.find(wishlist_id)
        wishlist_product = WishlistProduct.find(wishlist_id, product_id)

        if not wishlist:
            api.abort(status.HTTP_404_NOT_FOUND, "Wishlist with id '{}' not found"\
                       .format(wishlist_id))
        elif not wishlist_product:
            api.abort(
                status.HTTP_404_NOT_FOUND, "Product with id '{}' not found in\
                      wishlist with id '{}'.".format(product_id, wishlist_id))

        body = request.get_json()
        app.logger.info('Body: %s', body)

        product_name = body.get('product_name', '')

        if product_name == '':
            api.abort(status.HTTP_400_BAD_REQUEST,
                      "Product needs a non-empty name.")

        wishlist_product.product_name = product_name
        wishlist_product.save()

        return wishlist_product.serialize(), status.HTTP_200_OK
    def put(self, wishlist_id):
        """
        Rename a Wishlist
        This endpoint will return a Wishlist based on it's id
        """
        app.logger.info('Request to rename a wishlist with id: %s',
                        wishlist_id)
        check_content_type('application/json')
        body = request.get_json()
        app.logger.info('Body: %s', body)

        name = body.get('name', '')

        if name == '':
            api.abort(400, "Invalid request: missing name")

        wishlist = Wishlist.find(wishlist_id)

        if not wishlist:
            api.abort(404, "No wishlist found.")

        wishlist.name = name
        wishlist.save()

        return wishlist.serialize(), status.HTTP_200_OK
    def delete(self, wishlist_id):
        """
        Delete a Wishlist

        This endpoint will delete a Wishlist based the id specified in the path
        """
        app.logger.info('Request to delete wishlist with id: %s', wishlist_id)
        wishlist = Wishlist.find(wishlist_id)
        if wishlist:
            wishlist.delete()
        return '', status.HTTP_204_NO_CONTENT
    def get(self, wishlist_id):
        """
        Retrieve a single Wishlist

        This endpoint will return a Wishlist based on it's id
        """
        app.logger.info("Request to Retrieve a wishlist with id [%s]",
                        wishlist_id)
        wishlist = Wishlist.find(wishlist_id)
        if not wishlist:
            api.abort(
                status.HTTP_404_NOT_FOUND,
                "Wishlist with id '{}' was not found.".format(wishlist_id))
        return wishlist.serialize(), status.HTTP_200_OK
    def post(self, wishlist_id):
        """
        This endpoint adds an item to a Wishlist. It expects the
        wishlist_id and product_id.
        """
        app.logger.info('Request to add item into wishlist')
        check_content_type('application/json')

        # checking if the wishlist exists:
        wishlist = Wishlist.find(wishlist_id)
        if not wishlist:
            api.abort(status.HTTP_404_NOT_FOUND,
                      "Wishlist with id '%s' was not found." % wishlist_id)
        wishlist_product = WishlistProduct()
        wishlist_product.wishlist_id = wishlist_id

        body = request.get_json()
        app.logger.info('Body: %s', body)

        product_name = body.get('product_name', '')
        product_id = body.get('product_id', 0)

        if product_name == '':
            raise DataValidationError('Invalid request: missing name')

        wishlist_product.product_name = product_name

        if product_id == 0:
            raise DataValidationError('Invalid request: missing product id')

        wishlist_product.product_id = product_id

        app.logger.info('Request to add %s item to wishlist %s' %
                        (wishlist_product.product_id, wishlist_id))

        wishlist_product.save()
        message = wishlist_product.serialize()

        location_url = api.url_for(ProductResource,
                                   wishlist_id=wishlist.id,
                                   product_id=wishlist_product.product_id,
                                   _external=True)

        return message, status.HTTP_201_CREATED, {'Location': location_url}
    def put(self, wishlist_id, product_id):
        """
            Move item from Wishlist to cart
            This endpoint will request to move and item in wishlist to cart
        """
        app.logger.info('Request to move item %s in wishlist %s to cart',
                        product_id, wishlist_id)
        wishlist = Wishlist.find(wishlist_id)
        if not wishlist:
            raise NotFound(
                "Wishlist with id '{}' was not found.".format(wishlist_id))

        wishlist_product = WishlistProduct.find(wishlist_id, product_id)
        if ((not wishlist_product)
                or (wishlist_product.wishlist_id != wishlist_id)):
            raise NotFound(
                "Wishlist Product with id '{}' was not found in Wishlist \
                            with id '{}'.".format(product_id, wishlist_id))

        wishlist_product.add_to_cart(wishlist.customer_id)
        wishlist_product.delete()

        return '', status.HTTP_204_NO_CONTENT