Package com.example.breeze_seas
Class EventDB
java.lang.Object
com.example.breeze_seas.EventDB
EventDB
This class manages queries for use by the event class.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceCallback interface for when adding an event.static interfaceCallback interface when updating an event document in the database.static interfaceCallbacks fired by the realtime events collection listener.static interfaceCallback interface when loading all events from the database.static interfaceCallback interface when loading a single event document from the database. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddEvent(Event event, EventDB.AddEventCallback callback) Add an event collection to databasestatic voiddeleteEvent(Event event, EventDB.EventMutationCallback callback) Deletes an event and all of its data from the database.static StringGenerate a new document ID from database.static voidgetAllEvents(EventDB.LoadEventsCallback callback) Fetches all events from the database.static voidgetAllEventsOrganizedByCoOrganizer(User user, EventDB.LoadEventsCallback callback) Fetch all events that the user is co-organizing.static com.google.firebase.firestore.QueryMethod to obtain query for all events that the user is a co-organizer for.static voidgetAllEventsOrganizedByOrganizer(User user, EventDB.LoadEventsCallback callback) Fetch all events that the user is organizing (the original organizer)static com.google.firebase.firestore.QueryMethod to obtain query for all events that the user is the original organizer for.static voidgetAllEventsOrganizedByUser(User user, EventDB.LoadEventsCallback callback) Fetch all events that the user is organizing (any kind of organizer)static com.google.firebase.firestore.QueryMethod to obtain all events that the user is any kind of organizer for.static com.google.firebase.firestore.QueryMethod to obtain query for all events.static voidgetAllJoinableEvents(User user, EventDB.LoadEventsCallback callback) Fetch all events that the current user is able to join.static com.google.firebase.firestore.QueryMethod to obtain query for all joinable public events for given user.static voidgetEventById(String eventId, EventDB.LoadSingleEventCallback callback) Fetches an event based on documentIDstatic com.google.firebase.firestore.CollectionReferenceReturns the event CollectionReference used in the database.static com.google.firebase.firestore.QuerygetExploreEventsQuery(User user) Method to obtain query for all joinable public events for given user.static voidAttaches a real-time listener to the entire "events" collection.static voidDetaches the realtime collection listener.static voidupdateEvent(Event event, EventDB.EventMutationCallback callback) Modifies an event collection from the database.
-
Method Details
-
genNewEventId
Generate a new document ID from database.- Returns:
- the new document ID
-
getEventRef
public static com.google.firebase.firestore.CollectionReference getEventRef()Returns the event CollectionReference used in the database.- Returns:
- CollectionReference to the events collection
-
addEvent
Add an event collection to database- Parameters:
event- Event object to add to databasecallback- Callback method to run after firebase transaction
-
updateEvent
Modifies an event collection from the database.- Parameters:
event- The event object to modifiy.callback- Callback method to run after firebase transaction.
-
deleteEvent
Deletes an event and all of its data from the database.Fetches every document in the event's "participants" and "comments" subcollections, then uses a
WriteBatchto delete all participant documents, all comment documents, the event's poster image (if one exists), and the event document itself. Either everything is deleted or nothing is.- Parameters:
event- The event to delete.callback- Callback fired once all deletes are committed, or on failure.
-
startEventsListen
Attaches a real-time listener to the entire "events" collection. Any add, modify, or delete on any event document fires the appropriate callback.- Parameters:
callback- Receives individual change events or errors.
-
stopEventsListen
public static void stopEventsListen()Detaches the realtime collection listener. -
getEventById
Fetches an event based on documentID- Parameters:
eventId- The event document to fetch for.callback- Callback method to run after firebase transaction.
-
getAllEventsQuery
public static com.google.firebase.firestore.Query getAllEventsQuery()Method to obtain query for all events.- Returns:
- Query for all events.
-
getAllEvents
Fetches all events from the database.- Parameters:
callback- Callback method to run after firebase transaction.
-
getExploreEventsQuery
Method to obtain query for all joinable public events for given user. This is EXPLICITLY meant to be used in the explore fragment.- Parameters:
user- User to get query for.- Returns:
- Query for all joinable events for user.
-
getAllJoinableEventsQuery
Method to obtain query for all joinable public events for given user. This is meant for a one time fetch use case.- Parameters:
user- User to get query for.- Returns:
- Query for all joinable events for user.
-
getAllJoinableEvents
Fetch all events that the current user is able to join. Registration is open and is not the organizer for event- Parameters:
user- User to find joinable events frcallback- Callback method to run after firebase transaction.
-
getAllEventsOrganizedByUserQuery
Method to obtain all events that the user is any kind of organizer for.- Parameters:
user- User that is an organizer.- Returns:
- Query for all events that is organized by the user.
-
getAllEventsOrganizedByUser
Fetch all events that the user is organizing (any kind of organizer)- Parameters:
user- User to check the id of organizers.callback- Callback method to run after firebase transaction.
-
getAllEventsOrganizedByOrganizerQuery
Method to obtain query for all events that the user is the original organizer for.- Parameters:
user- User that is the original organizer.- Returns:
- Query for all events that is originally organized by the user.
-
getAllEventsOrganizedByOrganizer
Fetch all events that the user is organizing (the original organizer)- Parameters:
user- User to check the id of organizers.callback- Callback method to run after firebase transaction.
-
getAllEventsOrganizedByCoOrganizerQuery
public static com.google.firebase.firestore.Query getAllEventsOrganizedByCoOrganizerQuery(User user) Method to obtain query for all events that the user is a co-organizer for.- Parameters:
user- User that is the co-organizer.- Returns:
- Query for all events that is being co-organized by user.
-
getAllEventsOrganizedByCoOrganizer
public static void getAllEventsOrganizedByCoOrganizer(User user, EventDB.LoadEventsCallback callback) Fetch all events that the user is co-organizing.- Parameters:
user- User to check the id of organizers.callback- Callback method to run after firebase transaction.
-