def delete_one_review(review_id): """Example endpoint deleting one review Deletes a review based on the place_id --- definitions: Review: type: object Color: type: string items: $ref: '#/definitions/Color' responses: 200: description: An empty dictionary schema: $ref: '#/definitions/City' examples: {} """ review = storage.get("Review", review_id) if review is None: abort(404) storage.delete(review) return jsonify({}), 200
def delete_one_review(review_id): """Example endpoint deleting one review Deletes a review based on the place_id --- definitions: Review: type: object Color: type: string items: $ref: '#/definitions/Color' responses: 200: description: An empty dictionary schema: $ref: '#/definitions/City' examples: {} """ review = storage.get("Review", review_id) if review is None: abort(404) storage.delete(review) return jsonify({}), 200
def state_by_id(state_id=None): """ Access the api call with on a specific state object returns a 404 if not found. - DELETE: Removes the state object - PUT: Updates the state object - GET: Default, return the state object. """ if state_id not in storage.all('State'): abort(404) if request.method == 'DELETE': storage.delete(storage.get('State', state_id)) storage.save() return (jsonify({})) if request.method == 'PUT': put_obj = request.get_json() if put_obj is None: return ("Not a JSON", 400) instance = storage.get('State', state_id) for attrib in put_obj: setattr(instance, attrib, put_obj[attrib]) instance.save() return (jsonify(instance.to_json())) """ Default: GET""" instance = storage.get('State', state_id) return (jsonify(instance.to_json()))
def delete_one_city(city_id): """Example endpoint deleting one city Deletes a state based on the city_id --- definitions: City: type: object Color: type: string items: $ref: '#/definitions/Color' responses: 200: description: An empty dictionary schema: $ref: '#/definitions/City' examples: {} """ city = storage.get("City", city_id) if city is None: abort(404) storage.delete(city) return jsonify({})
def delete_amenity(amenity_id=None): """Example endpoint deleting one amenity Deletes a review based on the amenity_id --- definitions: Amenity: type: object Color: type: string items: $ref: '#/definitions/Color' responses: 200: description: An empty dictionary schema: $ref: '#/definitions/City' examples: {} """ amenity = storage.get("Amenity", amenity_id) if amenity is None: abort(404) storage.delete(amenity) return jsonify({}), 200
def delete_place(place_id=None): """Example endpoint deleting one place Deletes a place based on the place_id of the JSON body --- definitions: Place: type: object Color: type: string items: $ref: '#/definitions/Color' responses: 200: description: An empty dictionary schema: $ref: '#/definitions/City' examples: {} """ place = storage.get("Place", place_id) if place is None: abort(404) storage.delete(place) return jsonify({}), 200
def delete_state(state_id=None): """Example endpoint deleting one state Deletes a state based on the state_id --- definitions: State: type: object Color: type: string items: $ref: '#/definitions/Color' responses: 200: description: An empty dictionary schema: $ref: '#/definitions/State' examples: {} """ if state_id is None: abort(404) state = storage.get("State", state_id) if state is None: abort(404) storage.delete(state) return jsonify({}), 200
def place_by_id(place_id=None): """ Access the api call with on a specific state object returns a 404 if not found. - DELETE: Removes the state object - PUT: Updates the state object - GET: Default, return the state object. """ if place_id not in storage.all('Place'): abort(404) if request.method == 'DELETE': storage.delete(storage.get('Place', place_id)) storage.save() return (jsonify({})) if request.method == 'PUT': put_obj = request.get_json() if put_obj is None: return ("Not a JSON", 400) instance = storage.get('Place', place_id) ignore_keys = ['id', 'user_id', 'city_id', 'created_at', 'updated_at'] for attrib in put_obj: if attrib not in ignore_keys: setattr(instance, attrib, put_obj[attrib]) instance.save() return (jsonify(instance.to_json())) """ Default: GET""" instance = storage.get('Place', place_id) return (jsonify(instance.to_json()))
def all_reviews(review_id=None): """ Access the api call with on a place object to get its reviews returns a 404 if not found. - GET: Default, gets a review at <review_id>, status 200 - DELETE: Deletes the review at id. Returns '{}', status 200 - PUT: """ if review_id not in storage.all('Review'): abort(404) if request.method == 'DELETE': storage.delete(storage.get('Review', review_id)) storage.save() return (jsonify({})) if request.method == 'PUT': put_obj = request.get_json() if put_obj is None: return ("Not a JSON", 400) instance = storage.get('Review', review_id) ignore_keys = ['id', 'user_id', 'place_id', 'updated_at'] for attrib in put_obj: if attrib not in ignore_keys: setattr(instance, attrib, put_obj[attrib]) instance.save() return (jsonify(instance.to_json())) """ Default: GET """ instance_get = storage.get('Review', review_id) return (jsonify(instance_get.to_json()))
def delete_user(user_id=None): """Example endpoint deleting one user Deletes a user based on the user_id --- definitions: User: type: object Color: type: string items: $ref: '#/definitions/Color' responses: 200: description: An empty dictionary schema: $ref: '#/definitions/User' examples: {} """ user = storage.get("User", user_id) if user is None: abort(404) storage.delete(user) return jsonify({}), 200
def get_city_obj(city_id=None): """ API call to interact with a specific city object returns a 404 if city_id is not found. - DELETE method: Deletes the resource and returns {}, status 200 - PUT method: Updates the resource with the supplied json, status 201 - GET method: Default, returns the city object """ if city_id not in storage.all('City'): abort(404) if request.method == 'DELETE': storage.delete(storage.get('City', city_id)) storage.save() return (jsonify({})) if request.method == 'PUT': put_obj = request.get_json() if put_obj is None: return ("Not a JSON", 400) instance = storage.get('City', city_id) ignore_keys = ['id', 'state_id', 'created_at', 'updated_at'] for attrib in put_obj: if attrib not in ignore_keys: setattr(instance, attrib, put_obj[attrib]) instance.save() return (jsonify(instance.to_json())) """ Default: GET """ city_get = storage.get('City', city_id) return (jsonify(city_get.to_json()))
def delete_one_city(city_id): """Example endpoint deleting one city Deletes a state based on the city_id --- definitions: City: type: object Color: type: string items: $ref: '#/definitions/Color' responses: 200: description: An empty dictionary schema: $ref: '#/definitions/City' examples: {} """ city = storage.get("City", city_id) if city is None: abort(404) storage.delete(city) return jsonify({})
def delete_amenity(amenity_id=None): """Example endpoint deleting one amenity Deletes a review based on the amenity_id --- definitions: Amenity: type: object Color: type: string items: $ref: '#/definitions/Color' responses: 200: description: An empty dictionary schema: $ref: '#/definitions/City' examples: {} """ amenity = storage.get("Amenity", amenity_id) if amenity is None: abort(404) storage.delete(amenity) return jsonify({}), 200
def user_by_id(user_id=None): """ Access the api call with on a specific user object returns a 404 if not found. Delete method removes the object Defaults is to return the user object. """ if user_id not in storage.all('User'): abort(404) if request.method == 'DELETE': storage.delete(storage.get('User', user_id)) storage.save() return (jsonify({})) if request.method == 'PUT': put_obj = request.get_json() if put_obj is None: return ("Not a JSON", 400) instance = storage.get('User', user_id) ignore_keys = ['id', 'email', 'created_at', 'updated_at'] for attrib in put_obj: if attrib not in ignore_keys: setattr(instance, attrib, put_obj[attrib]) instance.save() return (jsonify(instance.to_json())) """Default: GET request returns the object in json form""" instance = storage.get('User', user_id) return (jsonify(instance.to_json()))
def manipulate_amenties_place(place_id=None): """ Access the api call with on a place object to get its amenities returns a 404 if not found. - DELETE: Deletes the link between Amenity objects and Place objects If the Amenity is not linked to the Place before the request, raise a 404 error Returns an empty dictionary with the status code 200 - POST: Link a Amenity object to a Place If the Amenity is already linked to the Place, return the Amenity with the status code 200 Returns the Amenity with the status code 201 """ if place_id not in storage.all('Place'): abort(404) if amenity_id not in storage.all('Amenity'): abort(404) if request.method == 'DELETE': storage.delete(storage.get('Place', place_id)) storage.save() return (jsonify({})) if request.method == 'POST': post_obj = request.get_json() if post_obj is None: return ("Not a JSON", 400) if 'name' not in post_obj: return ("Missing name", 400) new_obj = City(**post_obj) new_obj.state_id = state_id new_obj.save() return (jsonify(new_obj.to_json()), 201)
def delete_place(place_id): """Delete a Place object by it's ID.""" try: storage.delete(storage.get('Place', place_id)) storage.save() return jsonify({}), 200 except: abort(404)
def delete_amenity(amenity_id): """Delete an Amenity object by it's ID.""" amenity = storage.get("Amenity", amenity_id) if amenity is None: abort(404) storage.delete(amenity) storage.save() return jsonify({}), 200
def delete_review(review_id): """Delete a Review object by it's ID.""" try: storage.delete(storage.get('Review', review_id)) storage.save() return jsonify({}), 200 except: abort(404)
def delete_city(city_id): """Delete a City object by it's ID.""" city = storage.get('City', city_id) if city is None: abort(404) storage.delete(city) storage.save() return jsonify({}), 200
def delete_user(user_id): """Delete a User object by it's ID.""" user = storage.get("User", user_id) if user is None: abort(404) storage.delete(user) storage.save() return jsonify({}), 200
def delete_one_review(review_id): """ deleting one review """ review = storage.get("Review", review_id) if review is None: abort(404) storage.delete(review) return jsonify({}), 200
def delete_place(place_id=None): """ deleting place """ place = storage.get("Place", place_id) if place is None: abort(404) storage.delete(place) return jsonify({}), 200
def delete_user(user_id=None): """ deleting one user """ user = storage.get("User", user_id) if user is None: abort(404) storage.delete(user) return jsonify({}), 200
def delete_place(place_id=None): """ delete a place object by id """ place_object = storage.get(Place, place_id) if place_object is None: return jsonify({'Error': 'Not found'}), 404 storage.delete(place_object) storage.save() return jsonify({}), 200
def delete_place_by_id(place_id=None): """ delete a resource of my list of states """ place_object = storage.get(Place, place_id) if place_object is None: abort(404, "Not found") storage.delete(place_object) storage.save() return jsonify("{}"), 200
def delete_place(place_id=None): '''This is the 'delete_place' method. Deletes a Place object. ''' place = storage.get("Place", place_id) if place is None: abort(404) storage.delete(place) return jsonify({}), 200
def delete_user(user_id=None): """ delete a resource of my list of cities """ user_object = storage.get(User, user_id) if user_object is None: abort(404, "Not found") storage.delete(user_object) storage.save() return jsonify("{}"), 200
def delete_review(review_id): """delete review by id """ review = storage.get(Review, review_id) if review is None: return jsonify({'Error': 'Not found'}), 404 storage.delete(review) storage.save() return jsonify({}), 200
def delete_amenity(amenity_id=None): """ delete a resource of my list of states """ amenity_object = storage.get(Amenity, amenity_id) if amenity_object is None: return jsonify({'Error': 'Not found'}), 404 storage.delete(amenity_object) storage.save() return jsonify({}), 200
def delete_city(city_id=None): """ delete a city object by id """ city_object = storage.get(City, city_id) if city_object is None: return jsonify({'Error': 'Not found'}), 404 storage.delete(city_object) storage.save() return jsonify({}), 200
def delete_city(city_id=None): """ delete a resource of my list of states """ city_object = storage.get(City, city_id) if city_object is None: abort(404, "Not found") storage.delete(city_object) storage.save() return jsonify("{}"), 200
def delete_review_by_id(review_id=None): """ delete a resource of my list of review """ review_object = storage.get(Review, review_id) if review_object is None: abort(404, "Not found") storage.delete(review_object) storage.save() return jsonify("{}"), 200
def delete_single_review(review_id): '''This is the 'delete_single_review' method. Deletes a single Review object. ''' review = storage.get("Review", review_id) if review is None: abort(404) storage.delete(review) return jsonify({}), 200