Ejemplo n.º 1
0
def display_all_wishlists():
    # """ Display wishlists of all customers if created"""
    """
    Retrieve a list of Wishlists of all customers
    This endpoint will return all Wishlists of all customers
    ---
    tags:
      - Wishlists
    description: The Wishlists endpoint allows you to query all Wishlists of all customers
    responses:
      200:
        description: All Wishlists retrieved
        schema:
          id: Wishlist
          properties:
            Customer ID:
              type: integer
              description: ID of customer
            Wishlist:
              type: array
              items:
                type: object
                properties:
                  wishlist name:
                    type: string
                    description: the Wishlists's name
                  Product list:
                    type: array
                    items:
                      type: string
                    description: the list of products in a Wishlist
      404:
        description: Not Found (No wishlist created for any customer)
    """
    if Customer.display_all():
        message = [Customer.find_by_custid(k) for k in Customer.redis.keys()]
        return make_response(jsonify(message), status.HTTP_200_OK)
    else:
        message = {'Error': 'No wishlist created for any customer'}
        return make_response(jsonify(message), status.HTTP_404_NOT_FOUND)
Ejemplo n.º 2
0
def query_wishlist(cust_id):
    # """ List the wishlist with the provided name"""
    """
    Retrieve a list of Wishlists
    This endpoint will return all Wishlists based on the customer ID specified in the path and the optional wishlist name
    ---
    tags:
      - Wishlists
    description: The Wishlists endpoint allows you to query Wishlists
    parameters:
      - name: cust_id
        in: path
        description: ID of customer who wants to view a list of his/her Wishlists
        required: true
        type: integer
      - name: name
        in: query
        description: Name of the wishlist the customer wants to view
        required: false
        type: string
    responses:
      200:
        description: A list of Wishlists retrieved
        schema:
          id: Wishlist
          properties:
            Customer ID:
              type: integer
              description: ID of customer
            Wishlist:
              type: array
              items:
                type: object
                properties:
                  wishlist name:
                    type: string
                    description: the Wishlists's name
                  Product list:
                    type: array
                    items:
                      type: string
                    description: the list of products in a Wishlist
      404:
        description: Not Found (either customer ID or wishlist ID is not valid, no record found)
    """
    if Customer.check_custid(cust_id):
        query_name = request.args.get('name')
        if query_name:
            message = Customer.find_by_name(cust_id, query_name)
            if message:
                return make_response(jsonify(message), status.HTTP_200_OK)
            else:
                message = {'Error': 'Wishlist with the given name not found'}
                return make_response(jsonify(message),
                                     status.HTTP_404_NOT_FOUND)
        else:
            message = Customer.find_by_custid(cust_id)
            return make_response(jsonify(message), status.HTTP_200_OK)
    else:
        message = {'Invalid': 'Invalid customer ID'}
        return make_response(jsonify(message), status.HTTP_404_NOT_FOUND)