def add_wishlist(): """ The route for adding new wishlists, specified by userID and name of the wishlist. You can check the POST requests using CURL. Example: curl -i -H 'Content-Type: application/json' -X POST -d '{"name":"Xynazog","user_id":123}' http://127.0.0.1:5000/wishlists H is for headers, X is used to specify HTTP Method, d is used to pass a message. In location headers, if _external set to True, an absolute URL is generated. """ data = request.get_json() if is_valid(data, 'wishlist'): wishl = Wishlist() wishl.deserialize_wishlist(data) wishl.save_wishlist() message = wishl.serialize_wishlist() return make_response(jsonify(message), status.HTTP_201_CREATED, {'Location': wishl.self_url()}) else: message = {'error': 'Wishlist data was not valid'} return make_response(jsonify(message), status.HTTP_400_BAD_REQUEST)
def add_wishlist(): """ Creates a Wishlist This endpoint will create a Wishlist based on the data in the body that is posted --- tags: - Wishlists consumes: - application/json produces: - application/json parameters: - in: body name: body required: true schema: id: data required: - name - category properties: name: type: string description: name for the Wishlist user_id: type: string description: Unique ID of the user(created by the user) responses: 201: description: Wishlist created 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 description: Original ID of the item item_description: type: string description: Description of the item description: Dictionary to store objects in a wishlist id: type: integer description: Unique ID of the wishlist assigned internally by the server 400: description: Bad Request (the posted data was not valid) """ data = request.get_json() if is_valid(data, 'wishlist'): wishl = Wishlist() wishl.deserialize_wishlist(data) wishl.save_wishlist() message = wishl.serialize_wishlist() return make_response(jsonify(message), status.HTTP_201_CREATED, {'Location': wishl.self_url()}) else: message = {'error': 'Wishlist data was not valid'} return make_response(jsonify(message), status.HTTP_400_BAD_REQUEST)