Beispiel #1
0
def add_place(name, phone, lat, lon, address, fs_id=None, yelp_id=None, wifi=None, plugs=None, exp=None):
    # ensure it has a fs_id or a yelp_id
    if not (fs_id or yelp_id):
        return ErrorResponse.POST_INVALID_ARGS_FS_ID_YELP_ID
    
    # Create a review dict
    review = make_review_dict(wifi, plugs, exp)  
    
    # Check if place already exists in the database
    if fs_id:
        spec = {Place.A_FS_ID: fs_id}
        place_dict = Place.mdbc().find_one(spec)
        
        # If place exists add a review to it
        if place_dict:
            place_id = place_dict.get(Place.A_FS_ID)
            return Place.review_place(place_id=place_id, review=review)
        
    # If place doesn't already exist in the database add it
    place_data = {
          Place.A_NAME: name,
          Place.A_FS_ID: fs_id,
          Place.A_YELP_ID: yelp_id,
          Place.A_ADDRESS: address,
          Place.A_LOCATION: [float(lat), float(lon)]
    }
    
    # Only add phone if it's not null
    if phone:
        place_data[Place.A_PHONE] = phone
    
    return Place.add_place(place_data=place_data, review=review)
Beispiel #2
0
def review_place(place_id, wifi=None, plugs=None, exp=None):
    review = make_review_dict(wifi, plugs, exp)
    return Place.review_place(place_id=place_id, review=review)