Example #1
0
    def put(self, shopcart_id, item_id):
        """
        Update a Shopcart item
        This endpoint will update a Shopcart item based the body that is posted
        """
        logger.info("Request to update Shopcart item with id: %s", item_id)
        check_content_type("application/json")

        shopcart_item = ShopcartItem.find(item_id)

        if shopcart_item is None or shopcart_item.sid != shopcart_id:
            logger.info(
                "Shopcart item with ID [%s] not found in shopcart [%s].", item_id, shopcart_id
            )
            api.abort(
                status.HTTP_404_NOT_FOUND,
                "Shopcart item with id '{}' was not found.".format(item_id)
            )

        data = api.payload
        data["sid"] = shopcart_id
        data["id"] = item_id
        shopcart_item.deserialize(data)
        shopcart_item.update()

        logger.info("Shopcart item with ID [%s] updated.", shopcart_item.id)
        return shopcart_item.serialize(), status.HTTP_200_OK
Example #2
0
    def delete(self, shopcart_id, item_id):
        """
        Delete a ShopcartItem
        This endpoint will delete a ShopcartItem based the id specified in the path
        """
        logger.info(
            'Request to delete ShopcartItem with id: %s from Shopcart %s', item_id, shopcart_id
        )
        check_content_type("application/json")

        shopcart_item = ShopcartItem.find(item_id)

        if shopcart_item is not None and shopcart_item.sid == shopcart_id:
            shopcart_item.delete()

        logger.info('ShopcartItem with id: %s has been deleted', item_id)
        return "", status.HTTP_204_NO_CONTENT
Example #3
0
    def get(self, shopcart_id, item_id):
        """
        Get a shopcart item
        This endpoint will return an item in the shop cart
        """
        logger.info("Request to get an item in a shopcart")
        check_content_type("application/json")

        shopcart_item = ShopcartItem.find(item_id)

        if shopcart_item is None or shopcart_item.sid != shopcart_id:
            logger.info(
                "Shopcart item with ID [%s] not found in shopcart [%s].", item_id, shopcart_id
            )
            api.abort(
                status.HTTP_404_NOT_FOUND,
                "Shopcart item with ID [%s] not found in shopcart [%s]." % (item_id, shopcart_id)
            )

        logger.info("Fetched shopcart item with ID [%s].", item_id)
        return shopcart_item.serialize(), status.HTTP_200_OK