def delete_wishlist(wishlist_id): """ Delete a Wishlist This endpoint will delete a Wishlist based on the id specified in the path --- tags: - Wishlists description: Deletes a Wishlist from the database parameters: - name: wishlist_id in: path description: ID of the wishlist to delete type: integer required: true responses: 204: description: Wishlist deleted """ wl = Wishlist.find(wishlist_id) if wl: wl.delete() return make_response('', status.HTTP_204_NO_CONTENT) else: return make_response( jsonify(message='Wishlist with id %d could not be found' % wishlist_id), status.HTTP_204_NO_CONTENT)
def remove_wishlist_item(wishlist_id, item_id): """ Delete a Wishlist item This endpoint will delete an item based on the id specified in the path --- tags: - Wishlist Items description: Deletes a Wishlist Item from the database parameters: - name: wishlist_id in: path description: ID of the wishlist type: string required: true - name: item_id in: path description: ID of the item to be deleted type: string required: true responses: 204: description: Item deleted """ wl = Wishlist.find(wishlist_id) if not wl: return make_response( jsonify(message='Wishlist with id %d could not be found' % wishlist_id), status.HTTP_204_NO_CONTENT) try: wl.remove_item(item_id) wl.save_wishlist() return make_response('', status.HTTP_204_NO_CONTENT) except ItemException: message = {'error': 'Item %s was not found' % item_id} return make_response(jsonify(message), status.HTTP_204_NO_CONTENT)
def delete_wishlist(wishlist_id): """ The route for deleting a specific wishlist when the wishlist_id is specified. This only does a soft delete, i.e. update the deleted flag with "true" Example: curl -X DELETE http://127.0.0.1:5000/wishlists/1 """ wl = Wishlist.find(wishlist_id) if wl: wl.delete() return make_response('', status.HTTP_204_NO_CONTENT) else: return make_response( jsonify(message='Wishlist with id %d could not be found' % wishlist_id), status.HTTP_204_NO_CONTENT)
def remove_wishlist_item(wishlist_id, item_id): """ The route for removing a specific item in a wishlist, given a wishlist_id and the item_id Example: curl -X DELETE http://127.0.0.1:5000/wishlists/1/items/i123 """ wl = Wishlist.find(wishlist_id) if not wl: return make_response( jsonify(message='Wishlist with id %d could not be found' % wishlist_id), status.HTTP_204_NO_CONTENT) try: wl.remove_item(item_id) wl.save_wishlist() return make_response('', status.HTTP_204_NO_CONTENT) except ItemException: message = {'error': 'Item %s was not found' % item_id} return make_response(jsonify(message), status.HTTP_204_NO_CONTENT)