示例#1
0
 def mark_as_complete(transaction: Transaction, task_id):
     ref: DocumentReference = db.collection('groupTasks').document(task_id)
     d = ref.get(ref, transaction)
     m = GroupTaskModel.from_dict(d)
     if not m.in_process:
         raise ValueError("task_id: {} is not in process. ".format(task_id))
     if m.completed:
         raise ValueError("task_id: {} is already completed. ".format(task_id))
     m.in_process = False
     m.completed = True
     transaction.set(m.to_dict())
示例#2
0
 def start_by_id(transaction: Transaction, task_id):
     ref: DocumentReference = db.collection('groupTasks').document(task_id)
     d = ref.get(ref, transaction)
     m = GroupTaskModel.from_dict(d)
     if m.in_process:
         raise ValueError("task_id: {} is already being processed. ".format(task_id))
     if m.completed:
         raise ValueError("task_id: {} is already completed. ".format(task_id))
     m.in_process = True
     transaction.set(m.to_dict())
     return m
示例#3
0
    def add_to_event_schedule_with_transaction(
            transaction: Transaction,
            user_ref: str = None,
            event_ref: DocumentReference = None,
            event_schedule: AirportEventSchedule = None):
        """ Description
            Add a event schedule to users/<userId>/eventSchedule
                Note that the toEventRideRequestRef will be overwritten without warning if already set.
                (Same for fromEventRideRequestRef.)
        :type transaction:Transaction:
        :param transaction:Transaction:
        :type user_ref:str:
        :param user_ref:str:
        :type event_ref:str:
        :param event_ref:str:
        :type event_schedule:dict:
        :param event_schedule:dict:
        :raises:
        :rtype:
        """

        # userRef: DocumentReference = db.collection(u'users').document(userRef)

        # Get the CollectionReference of the collection that contains AirportEventSchedule's
        event_schedules_ref: CollectionReference = user_ref.collection(
            u'eventSchedules')

        # Retrieve document id to be used as the key
        event_id = event_ref.id
        # eventId = 'testeventid1'
        # warnings.warn("Using mock/test event id. Must replace before release. ")

        # Get the DocumentReference for the AirportEventSchedule
        event_schedule_ref: DocumentReference = event_schedules_ref.document(
            event_id)
        event_schedule_dict = event_schedule.to_dict()
        transaction.set(
            event_schedule_ref, event_schedule_dict,
            merge=True)  # So that 'fromEventRideRequestRef' is not overwritten
示例#4
0
    def set_with_transaction(transaction: Transaction, newRideRequest: Type[RideRequest],
                             rideRequestRef: DocumentReference):
        """ Description
            Note that a read action must have taken place before anything is set with that transaction. 

        :type transaction:Transaction:
        :param transaction:Transaction:

        :type newRideRequest:Type[RideRequest]:
        :param newRideRequest:Type[RideRequest]:

        :type rideRequestRef:DocumentReference:
        :param rideRequestRef:DocumentReference:

        :raises:

        :rtype:
        """
        return transaction.set(rideRequestRef, newRideRequest.to_dict())
    def set_with_transaction(transaction: Transaction,
                             newEventSchedule: Type[AirportEventSchedule],
                             eventScheduleRef: DocumentReference):
        """ Description
            Note that a read action must have taken place before anything is set with that transaction.

        :type self:
        :param self:

        :type transaction:Transaction:
        :param transaction:Transaction:

        :type newEventSchedule:Type[AirportEventSchedule]:
        :param newEventSchedule:Type[AirportEventSchedule]:

        :type eventScheduleRef:DocumentReference:
        :param eventScheduleRef:DocumentReference:

        :raises:

        :rtype:
        """
        raise NotImplementedError  # TODO: fix
        return transaction.set(eventScheduleRef, newEventSchedule)
示例#6
0
    def set_with_transaction(transaction: Transaction,
                             newLocation: Type[Location],
                             locationRef: DocumentReference):
        """ Description
            Note that a read action must have taken place before anything is set with that transaction.

        :type self:
        :param self:

        :type transaction:Transaction:
        :param transaction:Transaction:

        :type newLocation:Type[Location]:
        :param newLocation:Type[Location]:

        :type locationRef:DocumentReference:
        :param locationRef:DocumentReference:

        :raises:

        :rtype:
        """
        locationDict = newLocation.to_dict()
        return transaction.set(locationRef, locationDict)
示例#7
0
 def _set_with_transaction(transaction: Transaction,
                           newLocation: Type[Location],
                           locationRef: DocumentReference):
     return transaction.set(locationRef, newLocation)
示例#8
0
 def set_with_transaction(self, transaction: Transaction, new_user: User,
                          user_ref: DocumentReference):
     transaction.set(user_ref, new_user)
示例#9
0
 def set_user_with_transaction(transaction: Transaction,
                               newUser: Type[User],
                               userRef: DocumentReference):
     transaction.set(userRef, newUser.to_firestore_dict())
示例#10
0
 def set_with_transaction(transaction: Transaction, newOrbit: Orbit,
                          orbitRef: DocumentReference):
     """ Description
         Note that a read action must have taken place before anything is set with that transaction. 
     """
     return transaction.set(orbitRef, newOrbit.to_dict())