def delete_product(cust_id, wishlist_id, pid): # """ delete product ID to a wishlist """ """ Delete a product from a Wishlist This endpoint will delete a product from 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 delete a product from 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 deleted required: true type: integer responses: 200: description: Product deleted from 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 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.deleteProduct(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)
def clear_wishlist(cust_id, wishlist_id): # """ Clear the contents of the wishlist with the given id""" """ Clear all products of a Wishlist This endpoint will clear all products of a Wishlist based on the customer id and Wishlist id specified in the path --- tags: - Wishlists parameters: - name: cust_id in: path description: ID of customer who wants to view his/her wishlist required: true type: integer - name: wishlist_id in: path description: ID of wishlist to be retrieved required: true type: integer responses: 200: description: Wishlist cleared 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 404: description: Not Found (either customer ID or wishlist ID is not valid, no record found) """ if Customer.check_custid(cust_id): message = Customer.find_by_id(cust_id, wishlist_id) if message: res = Customer.clear_list(cust_id, wishlist_id) return make_response(jsonify(message), status.HTTP_200_OK) else: message = {'Error': 'Wishlist with the 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)
def update_wishlist(cust_id, wishlist_id): # """ Update the wishlist name if it exists, otherwise returns not found """ """ Update a Wishlist This endpoint will update a Wishlist based on the customer id and Wishlist id specified in the path --- tags: - Wishlists consumes: - application/json produces: - application/json parameters: - name: cust_id in: path description: ID of customer who wants to update his/her wishlist required: true type: integer - name: wishlist_id in: path description: ID of wishlist to be updated required: true type: integer - in: body name: body required: true schema: type: object required: - name properties: name: type: string description: name for the Wishlist responses: 200: description: Wishlist updated 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.update(cust_id, wishlist_id, request.get_json()) 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)