feat(data): Add Data Layer for User Collections (Watchlist, Liked, Lists)
What does this MR do?
This MR establishes the entire backend foundation for all user-specific movie collections as defined in the project requirements. It provides a complete, tested, and robust data layer for managing a user's watchlist, liked movies, and custom-named lists.
Architectural Components:
-
Room Database Schema:
-
MovieEntityis updated withisLikedandisInWatchlistboolean flags. - A full many-to-many relationship is implemented for custom lists (
UserListEntity<->UserListMovieCrossRef<->MovieEntity). - The database version is incremented to
2with a destructive migration strategy for development.
-
-
Data Access Objects (DAOs):
-
MovieDaoprovides methods for toggling liked/watchlist status and retrieving these collections. -
UserListDaoprovides methods for creating custom lists and managing their contents.
-
-
Repository Layer:
- A new
UserCollectionsRepositoryis introduced to abstract away all database logic. It provides a clean, suspendable API (e.g.,likeMovie(movie),getWatchlist()) for the application's ViewModels.
- A new
How has this been tested?
The correctness of this feature is ensured by two layers of testing:
-
Instrumented Test (
DatabaseCollectionsTest): Verifies the entire Room database schema, including entities, DAOs, primary keys, and relationships, by running real database operations on a device. -
Unit Test (
UserCollectionsRepositoryImplTest): Uses mock DAOs to verify the business logic within the repository implementation, ensuring it calls the correct DAO methods with the correct parameters.
Why was this change needed?
This is a cornerstone feature of the application. With this data layer in place, the UI dev can now build the functionality for the movie details screen (like/watchlist buttons) and the user profile screens (viewing their collections). This MR unblocks a significant portion of future feature development.