Beispiel #1
0
def add_ride_request(transaction, ride_request, location, user_id, event=None):
    """ Description
        This method saves rideRequest and update user's eventSchedule.
        The method corresponds to use case "Create Ride Request".
        Note that transaction.commit() is not required after this method is called if this method is decorated
            by @transactional.

    :param transaction:
    :param ride_request:
    :param location:
    :param user_id:
    :return:
    """

    # Set the firestoreRef of the rideRequest
    RideRequestGenericDao().create(ride_request)
    # Saves RideRequest Object to Firestore
    RideRequestGenericDao().set_with_transaction(transaction, ride_request, ride_request.get_firestore_ref())
    # [START] Update the user's eventSchedule
    user_ref = UserDao().get_ref(user_id)
    # Build the eventSchedule for user
    event_schedule = gravitate.domain.event_schedule.actions.create_event_schedule(
        ride_request, location, event)
    UserDao.add_to_event_schedule_with_transaction(
        transaction, user_ref=user_ref, event_ref=ride_request.event_ref, event_schedule=event_schedule)
Beispiel #2
0
def update_in_orbit_event_schedule(transaction: Transaction,
                                   ride_request: Type[RideRequest],
                                   orbit: Orbit, event: Event,
                                   location: Location):
    """ Populate eventSchedule (client view model)
    :param transaction:
    :param ride_request:
    :param orbit:
    :param event:
    :param location:
    :return:
    """

    # update eventSchedule
    user_id = ride_request.user_id
    user_ref = UserDao().get_ref(user_id)
    event_ref = event.get_firestore_ref()

    event_schedule = event_schedule_actions.create_event_schedule_orbit(
        ride_request=ride_request, location=location, orbit=orbit)
    UserDao().add_to_event_schedule_with_transaction(
        transaction,
        user_ref=user_ref,
        event_ref=event_ref,
        event_schedule=event_schedule)
 def get(self, uid):
     # Check Firestore to see if UID Already Exists
     if UserDao().user_id_exists(uid):
         user = UserDao().get_user_by_id(uid)
         userDict = user.to_dict()
         return userDict, 200
     else:
         errorResponseDict = {"error": "User Does not Exist"}
         return errorResponseDict, 400
Beispiel #4
0
def saveUser(user, transaction: Transaction = None):
    if user.get_firestore_ref():
        if transaction is None:
            raise Exception('transaction is not provided. ')
        UserDao().set_user_with_transaction(transaction, user,
                                            user.get_firestore_ref())
        fireauthutils.update_user(user)

    else:
        newRef = UserDao().create_user(user)
        user.set_firestore_ref(newRef)
Beispiel #5
0
    def testUserCollectionExists(self):
        """
        TODO: add setUp to create the user specified in uid
        :return:
        """
        uid = "1GFLeGxBaaUvudqh3XYbFv2sRHx2"
        user = UserDao().get_user_by_id(uid)
        self.assertEqual(user.uid, userDict["uid"])
        self.assertEqual(user.membership, userDict["membership"])
        self.assertEqual(user.phone_number, userDict["phone_number"])
        self.assertEqual(user.photo_url, userDict["photo_url"])
        self.assertEqual(user.display_name, userDict["display_name"])
        self.assertEqual(user.pickupAddress, userDict["pickupAddress"])

        print(json.dumps(user.to_dict()))
Beispiel #6
0
def update_not_in_orbit_event_schedule(transaction: Transaction,
                                       ride_request: RideRequest, event: Event,
                                       location: Location):
    # update eventSchedule
    user_id = ride_request.user_id
    user_ref = UserDao().get_ref(user_id)
    event_ref = event.get_firestore_ref()

    event_schedule = event_schedule_actions.create_event_schedule(
        ride_request, location)
    UserDao().add_to_event_schedule_with_transaction(
        transaction,
        user_ref=user_ref,
        event_ref=event_ref,
        event_schedule=event_schedule)
Beispiel #7
0
 def testGetUserId(self):
     user = UserDao().get_user_by_id(userDict["uid"])
     self.assertEquals(userDict['display_name'], user.display_name)
     self.assertEquals(userDict['phone_number'], user.phone_number)
     self.assertEquals(userDict['uid'], user.uid)
     self.assertEquals(userDict['membership'], user.membership)
     self.assertEquals(userDict['photo_url'], user.photo_url)
     self.assertEquals(userDict['pickupAddress'], user.pickupAddress)
Beispiel #8
0
def get_pickup_address(user_id) -> str:
    """
    This method returns the default pickup address of a user.
    :param user_id:
    :return:
    """
    user: User = UserDao().get_user_by_id(user_id)
    pickup_address = user.pickupAddress
    return pickup_address
    def post(self, uid):
        """ Description
            This method handles POST request to handle use case "create ride request"

        :param uid:
        :return:
        """
        requestJson = request.get_json()
        requestForm = json.loads(requestJson) if (
            type(requestJson) != dict) else requestJson

        validateForm = UserCreationValidateForm(data=requestForm)

        # POST REQUEST
        if validateForm.validate():

            # Transfer data from validateForm to an internal representation of the form
            form = UserCreationForm()
            validateForm.populate_obj(form)
            userDict = fillUserDictWithForm(form)

            # Create User Object
            newUser: User = User.from_dict(userDict)

            userId = newUser.uid
            userRef = UserDao().userCollectionRef.document(document_id=userId)
            newUser.set_firestore_ref(userRef)
            transaction = db.transaction()

            # Saves User Object to Firestore
            userutils.saveUser(newUser, transaction=transaction)
            userRef = UserDao().userCollectionRef.document(userId)
            transaction.commit()

            responseDict = {"userId": newUser.get_firestore_ref().id}

            return responseDict, 200
        else:
            print(validateForm.errors)
            return validateForm.errors, 400
Beispiel #10
0
 def testUpdateUser(self):
     auth.update_user(userDict["uid"],
                      phone_number="+17777777779",
                      display_name="Zixuan Rao",
                      disabled=False,
                      app=context.Context.firebaseApp)
     user = UserDao().get_user_by_id(userDict["uid"])
     self.assertEquals("Zixuan Rao", user.display_name)
     self.assertEquals("+17777777779", user.phone_number)
     self.assertEquals(userDict['uid'], user.uid)
     self.assertEquals(userDict['membership'], user.membership)
     self.assertEquals(userDict['photo_url'], user.photo_url)
     self.assertEquals(userDict['pickupAddress'], user.pickupAddress)
Beispiel #11
0
    def delete(self, rideRequestId, uid):
        """
        Replaces POST "/deleteRideRequest"
        :param rideRequestId:
        :param uid:
        :return:
        """

        user_id = uid
        user_ref = UserDao().get_ref(user_id)
        ride_request_ref = RideRequestGenericDao(
        ).rideRequestCollectionRef.document(rideRequestId)

        response_dict = {}
        ride_request = RideRequestGenericDao().get(ride_request_ref)
        event_id = ride_request.event_ref.id

        print("userId: {}, rideRequestId: {}, eventId: {}".format(
            user_id, rideRequestId, event_id))

        # Validate that the ride request is not matched to an orbit
        request_completion = ride_request.request_completion
        if request_completion:
            raise service_errors.RequestAlreadyMatchedError

        try:
            # Delete in User's Event Schedule
            EventScheduleGenericDao(
                userRef=user_ref).delete_event_by_id(event_id)
            # Delete in RideRequest Collection
            RideRequestGenericDao().delete(ride_request_ref)
            response_dict = {"success": True}

        except Exception as e:
            err_str = str(e)
            response_dict = {
                "error":
                "Error occurred deleting rideRequest and eventSchedule: " +
                err_str
            }
            print(response_dict)
            return response_dict, 500

        return response_dict, 200
Beispiel #12
0
def getMemberProfilePhotoUrls(orbit: Orbit) -> [str]:
    """ Description
        [Assigned to Leon]
        Don't have to follow the method signature, but the signature is required to get other code working.
        Orbits can be obtained through any other ways, and buildEventSchedule can be called from elsewhere.

    :raises:

    :rtype:
    """
    # Must go through each userTicketPair (key = userIDs)
    photo_urls = []
    if CTX.testing:
        warnings.warn(
            "Using testing mode, skipping member profile photo urls evaluation. "
        )
        return photo_urls

    for uid in orbit.user_ticket_pairs:
        user = UserDao().get_user_by_id(uid)
        photo_url = user.photo_url
        photo_urls.append(photo_url)

    return photo_urls
Beispiel #13
0
 def testCreateTempTesting(self):
     userRef: firestore.DocumentReference = UserDao().create_user(self.user)
     self.user.set_firestore_ref(userRef)
     print("userRef = {}".format(userRef))
Beispiel #14
0
 def setUp(self):
     self.user = UserDao().get_user_by_id('SQytDq13q00e0N3H4agR')
Beispiel #15
0
 def testGetUser(self):
     uid = userDict["uid"]
     user = UserDao().get_user_by_id(uid)
     print(user.to_dict())
Beispiel #16
0
def getUser(uid: string):
    UserDao().get_user_by_id(uid)
Beispiel #17
0
def editUser(user, transaction: Transaction = None):
    if user.get_firestore_ref():
        if transaction is None:
            raise Exception('transaction is not provided.')
    else:
        UserDao().get_user_by_id(user.userId)