def purge_test_database(): User.mdbc().remove() Ride.mdbc().remove() Terminal.mdbc().remove() User.setup_mongo_indexes() Ride.setup_mongo_indexes() Terminal.setup_mongo_indexes()
def decline_match(klass, ride_id, match_ride_id): ride = klass.get_ride(ride_id) match = klass.get_ride(match_ride_id) # ensure that both rides have STATUS_PENDING if (ride.get(Ride.A_STATUS) != Ride.STATUS_PENDING or match.get(Ride.A_STATUS) != Ride.STATUS_PENDING): return ApiResponse.RIDE_COULD_NOT_DECLINE_MATCH declined = Ride.decline_match(ride_id, match_ride_id) if not declined: return ApiResponse.RIDE_COULD_NOT_DECLINE_MATCH klass.notify_users(ride, match, action=Ride.ACTION_DECLINE) return ApiResponse.RIDE_MATCH_DECLINED
def accept_match(klass, ride_id, match_ride_id): ride = klass.get_ride(ride_id) match = klass.get_ride(match_ride_id) # ensure that both rides have STATUS_PENDING if (ride.get(Ride.A_STATUS) != Ride.STATUS_PENDING or match.get(Ride.A_STATUS) != Ride.STATUS_PENDING): return ApiResponse.RIDE_COULD_NOT_ACCEPT_MATCH matched = Ride.create_match(ride_id, match_ride_id) if not matched: return ApiResponse.RIDE_COULD_NOT_ACCEPT_MATCH klass.notify_users(ride, match, action=Ride.ACTION_ACCEPT) return ApiResponse.RIDE_MATCH_ACCEPTED
def request_match(klass, ride_id, match_ride_id): ride = klass.get_ride(ride_id) match = klass.get_ride(match_ride_id) match_currently_pending_id = match.get(Ride.A_PENDING_RIDE_ID) if match_currently_pending_id and match_currently_pending_id != ride_id: return ApiResponse.RIDE_CURRENTLY_PENDING # update the status of both ride ids to be STATUS_PENDING requested = Ride.request_match(ride_id, match_ride_id) if not requested: return ApiResponse.RIDE_COULD_NOT_REQUEST_MATCH klass.notify_users(ride, match, action=Ride.ACTION_REQUEST) return ApiResponse.RIDE_MATCH_REQUESTED
def get_matches_for_status_prepending(klass, ride_doc): # Get all rides that match ride_doc specs rides = Ride.get_matches(ride_doc) if not rides: return ApiResponse.RIDE_NO_MATCHES_FOUND # Get list of user_ids in rides user_ids = [r.get(Ride.A_USER_ID) for r in rides] # Make batch call to get all user info users = UserHelper.get_users_by_id(user_ids) # Append each ride with user info for ride in rides: user_id = ride.get(Ride.A_USER_ID) ride['user'] = users.get(user_id) return rides
def create_or_update_ride(klass, user_id, origin_venue, dest_lon, dest_lat, departure_time, ride_id=None, origin_pick_up=None): doc = { Ride.A_RIDE_ID:ride_id, Ride.A_USER_ID:user_id, Ride.A_ORIGIN_VENUE:origin_venue, Ride.A_ORIGIN_PICK_UP:origin_pick_up, Ride.A_DESTINATION_LON:dest_lon, Ride.A_DESTINATION_LAT:dest_lat, Ride.A_TIMESTAMP_DEPARTURE:departure_time } ride_id = Ride.create_or_update_ride(doc) if not ride_id: return ApiResponse.RIDE_COULD_NOT_CREATE else: return ride_id
import sys sys.path.append("../") from model.Ride import Ride Ride.update_status_of_expired_rides()
def get_ride(klass, ride_id): ride = Ride.get_ride(ride_id) if not ride: return ApiResponse.RIDE_NOT_FOUND else: return ride