annazwicker / cat-partners

Generating an application for Cat Partners so they can track their feeding schedule.
0 stars 0 forks source link

Simplifying database access #48

Open JaydenBea opened 6 months ago

JaydenBea commented 6 months ago

An class that simplifies access to information needed in the database is quite desirable. It abstracts database access, allowing changes to be done without requiring mass rewrites, and will make things overall easier.

The FirebaseHelper class initializes elements needed for access, including all collection references, but I'm going to make another class between this one and classes responsible for presenting UI to the user. The Snapshots class will contain methods and variables that are needed by various components of the database, and simplify their use.

JaydenBea commented 6 months ago

12:00pm (start)

The first thing the class needs is Future variables for the various Streams and lists needed by different pages. Of note:

Something I need to find is whether lists of QueryDocumentSnapshots (the latter three) will dynamically update like Streams do. It would be important for the Admin page in particular that the lists update after stations/cats are added/removed.

JaydenBea commented 6 months ago

12:25pm (since 12pm)

There is a distinct difference between getting the results of, say, a query that returns a Future with a list of QueryDocumentSnapshots (FirebaseHelper().usersRef.get()) and a Stream (FirebaseHelper.usersRef.snapshots()). Both are asynchronous operations that takes some time to complete. However, where a Future does the operation once and returns an unchanging value, a Stream's values can update over time. Where a Future will return a list of users as they were at the time of Query completion, a Stream will react to changes in the database after data is originally fetched.

For now, I'm going to add variables for both Stream and Future versions of each collection.

JaydenBea commented 6 months ago

1pm (Since 12:25pm)

Added Streams and Futures for all four collections, including initializing functions for the three. The initializers use a common function with a generic typing. The list of stations is sorted by ID.

Working on adding getters that, when given a DocumentReference, returns the DocumentSnapshot of the document referenced by the snapshot. I'm also trying to give this dynamic typing for redundancy's sake.

JaydenBea commented 6 months ago

1:30pm (since 1pm)

Added a generic getter as described above. This was done by introducing Model, an abstract class that the other models (UserDoc, Entry, Station, Cat) all extend. The abstract class itself has no methods. It could include toJson, but not fromJson, as the latter is a constructor.

JaydenBea commented 6 months ago

2pm (since 1:30pm)

Added functions from FeederDataSource and confirmed the functionality of the items in Snapshots.

JaydenBea commented 5 months ago

8:20pm (start)

JaydenBea commented 5 months ago

8:50pm (since 8:20pm)

JaydenBea commented 5 months ago

9:08pm (since 8:50pm)