Beispiel #1
0
    def get(self, place_id):
        """Returns average rating for given place id. 0 if there are no ratings."""
        response_object = {}
        place = get_place_by_id(place_id)

        if not place:
            places_namespace.abort(404, f"Place {place_id} does not exist")
        rating = get_rating_by_id(place_id)
        return {"rating": int(rating)}, 200
Beispiel #2
0
    def delete(self, place_id):
        """"Deletes a place."""
        response_object = {}
        place = get_place_by_id(place_id)

        if not place:
            places_namespace.abort(404, f"Place {place_id} does not exist")

        delete_place(place)

        response_object["message"] = f"{place.name} was removed!"
        return response_object, 200
Beispiel #3
0
 def delete(self, place_id):
     """Removes place from user favorites."""
     was_successful, session_token = extract_token(request)
     response_object = {}
     if not was_successful:
         response_object["message"] = session_token
         return response_object, 400
     request_user = get_user_by_session_token(session_token)
     if request_user is None:
         response_object["message"] = "Unauthorized user."
         return response_object, 400
     place = get_place_by_id(place_id)
     if place is None:
         response_object["message"] = "Invalid place id."
         return response_object, 400
     # place_id and user is valid.
     remove_favorite(request_user, place)
     response_object["message"] = "Removed location from favorite!"
     return response_object, 201
Beispiel #4
0
    def put(self, place_id):
        """Updates a place."""
        post_data = request.get_json()
        lat = post_data.get("lat")
        lon = post_data.get("lon")
        name = post_data.get("name")
        types = post_data.get("types")
        response_object = {}

        place = get_place_by_id(place_id)
        if not place:
            places_namespace.abort(404, f"Place {place_id} does not exist")

        if get_place_by_name(name):
            response_object["message"] = "Sorry. That place already exists."
            return response_object, 400

        update_place(place, lat, lon, name, types)

        response_object["message"] = f"{place.id} was updated!"
        return response_object, 200
Beispiel #5
0
 def get(self, place_id):
     """Returns a single place."""
     place = get_place_by_id(place_id)
     if not place:
         places_namespace.abort(404, f"Place {place_id} does not exist")
     return place, 200