Ejemplo n.º 1
0
def add_product(cust_id, wishlist_id, pid):
    # """ Add product ID to a wishlist """
    """
    Add a product to a Wishlist
    This endpoint will add a product to a wishlist based on the customer ID, Wishlist ID, an product ID specified in the path
    ---
    tags:
      - Wishlists
    parameters:
      - name: cust_id
        in: path
        description: ID of customer who wants to add a product to his/her wishlist
        required: true
        type: integer
      - name: wishlist_id
        in: path
        description: ID of wishlist to be updated
        required: true
        type: integer
      - name: pid
        in: path
        description: ID of product to be added
        required: true
        type: integer
    responses:
      200:
        description: Product added to a wishlist
        schema:
          id: Wishlist
          properties:
            Customer ID:
              type: integer
              description: ID of customer
            Wishlist:
              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
      400:
        description: Bad Request (the put data was not valid)
      404:
        description: Not Found (either customer ID or wishlist ID is not valid, no record found)
    """
    # TODO add products changes as well, for now just asses the wishlists
    if Customer.check_custid(cust_id):
        message = Customer.find_by_id(cust_id, wishlist_id)
        if message:
            result = Customer.addProduct(cust_id, wishlist_id, pid)
            res = Customer.find_by_id(cust_id, wishlist_id)
            return make_response(jsonify(res), status.HTTP_200_OK)
        else:
            message = {'Error': 'Wishlist with given ID not found'}
            return make_response(jsonify(message), status.HTTP_404_NOT_FOUND)
    else:
        message = {'Invalid': 'Invalid customer ID'}
        return make_response(jsonify(message), status.HTTP_404_NOT_FOUND)