def get_wishlist_list(): """ Returns the Wishlists by searching the keywords of wishlist_name or the customer_id. This function returns a wishlist based on wishlist_name or customer id. If the customer_id and the wishlist id parameters are empty, returns all the wishlists in the database --- tags: - Wishlist produces: - application/json definitions: Wishlist: type: object properties: id: type: integer customer_id: type: integer wishlist_name: type: string parameters: - name: keyword in: query description: the name of the wishlist type: string - name: query in: query description: the id of the customer type: integer responses: 200: description: A Wishlist schema: $ref: '#/definitions/Wishlist' """ query_lists = [] customer_id = request.args.get('customer_id') keyword = request.args.get('keyword') if keyword: query_lists = Wishlist.find_by_wishlist_name(keyword) elif customer_id: query_lists = Wishlist.find_by_customer_id(customer_id) else: """ Returns all of the Wishlists """ query_lists = Wishlist.all() results = [wishlist.serialize() for wishlist in query_lists] return make_response(jsonify(results), status.HTTP_200_OK)
def wishlists(): """ The route for accessing all wishlist resources or creating a new wishlist resource via a POST. """ wishlistsList = [] wishlistsList = Wishlist.all() wishlistsList = [ wishlist.serialize_wishlist() for wishlist in wishlistsList ] return make_response(json.dumps(wishlistsList, indent=4), status.HTTP_200_OK)
def wishlists(): """ Retrieve a list of Wishlists This endpoint will return all wishlists --- tags: - Wishlists responses: 200: description: An array of Wishlists schema: type: array items: schema: id: Wishlist properties: user_id: type: string description: Unique ID of the user(created by the user) name: type: string description: Wishlist Name(created by the user) created: type: string format: date-time description: The time at which the wishlist was created deleted: type: boolean description: Flag to be set when a wishlist is deleted items: type: object properties: wishlist_item_id: type: object properties: item_id: type: string item_description: type: string description: Dictionary to store objects in a wishlist id: type: integer description: Unique ID of the wishlist assigned internally by the server """ wishlistsList = [] wishlistsList = Wishlist.all() wishlistsList = [ wishlist.serialize_wishlist() for wishlist in wishlistsList ] return make_response(json.dumps(wishlistsList, indent=4), status.HTTP_200_OK)
def search_wishlists(): """ The route for searching items with specific keyword or ID. http://0.0.0.0:5000/wishlists/search?q=Apple&user_id=123 """ data = {} data['query'] = request.args.get('q', None) data['uid'] = request.args.get('user_id', None) if data['uid'] is None: return make_response(jsonify("Error: userid is missing"), status.HTTP_400_BAD_REQUEST) wishlists_list = [] returned_items = [] wishlists_list = Wishlist.all() for wl in wishlists_list: item = wl.search_items(data) if item: returned_items.append(item) message = 'Search results for keyword \"%s\" in wishlists with user ID \"%s\"' % ( data['query'], data['uid']) ret = {message: returned_items} return make_response(jsonify(ret), status.HTTP_200_OK)
def get_wishlist_list(): """ Returns the Wishlists by searching the keywords of wishlist_name --- tags: - Wishlist produces: - application/json parameters: - name: keyword in: query description: the name of the wishlist type: string required: true responses: 200: description: An Item schema: $ref: '#/definitions/Wishlist' """ query_lists = [] keyword = request.args.get('keyword') if keyword: query_lists = Wishlist.find_by_wishlist_name(keyword) else: """ Returns all of the Wishlists """ query_lists = Wishlist.all() results = [wishlist.serialize() for wishlist in query_lists] return make_response(jsonify(results), status.HTTP_200_OK)
def search_wishlists(): """ Search a Wishlist Item This endpoint will return a Wishlist Item based on the query parameters --- tags: - Wishlist Items consumes: - application/json produces: - application/json parameters: - name: q in: query description: Query to be searched type: string - name: user_id in: query description: User ID whose wishlists would be searched type: String required: true responses: 200: description: Wishlist items matching with the query schema: type: object properties: Search results for keyword \"q\" in wishlists user ID \"user_id\": type: array items: schema: id: Wishlist properties: Results from wishlist with ID \"wishlist_id\": type: array items: type: object properties: item_id: type: string description: ID of the item matching item_description: type: string description: Description of the item 400: description: userid is missing """ data = {} data['query'] = request.args.get('q', None) data['uid'] = request.args.get('user_id', None) if data['uid'] is None: return make_response(jsonify("Error: userid is missing"), status.HTTP_400_BAD_REQUEST) wishlists_list = [] returned_items = [] wishlists_list = Wishlist.all() for wl in wishlists_list: item = wl.search_items(data) if item: returned_items.append(item) message = 'Search results for keyword \"%s\" in wishlists with user ID \"%s\"' % ( data['query'], data['uid']) ret = {message: returned_items} return make_response(jsonify(ret), status.HTTP_200_OK)