New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add data models, refactor local and network data sources #908
Conversation
app/src/main/java/com/example/android/architecture/blueprints/todoapp/data/ModelMappingExt.kt
Outdated
Show resolved
Hide resolved
app/src/main/java/com/example/android/architecture/blueprints/todoapp/data/ModelMappingExt.kt
Outdated
Show resolved
Hide resolved
app/src/main/java/com/example/android/architecture/blueprints/todoapp/data/ModelMappingExt.kt
Outdated
Show resolved
Hide resolved
...va/com/example/android/architecture/blueprints/todoapp/data/source/DefaultTasksRepository.kt
Show resolved
Hide resolved
...va/com/example/android/architecture/blueprints/todoapp/data/source/DefaultTasksRepository.kt
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Thanks @tunjid. Did you see my comments about the independent coroutines? This is the existing functionality - although it looks like new code it's actually exactly the same as how it works currently. I will address this in a separate PR if/when we redo the network data source and sync algorithm. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall LGTM
Hi. Who are you
…On Tue, 7 Mar 2023, 4:08 pm Manuel Vivo, ***@***.***> wrote:
***@***.**** commented on this pull request.
Overall LGTM
—
Reply to this email directly, view it on GitHub
<#908 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/A25RZENZBJZ3S6WA2O23TRLW24CJTANCNFSM6AAAAAAVO5EFEU>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
*/ | ||
|
||
// External to local | ||
fun Task.toLocalModel() = LocalTask( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: If this app were modularized, we would have the mappers in different modules. I'd expect these mappers to live in the boundaries between the components that use them. Some in data/source/local and some in data/source/network.
Here's what I've done and why:
Add internal data models
These are:
NetworkTask
represents a task obtained from the networkLocalTask
represents a task stored in a local Room databaseI've also added mapping functions to map between the two new models and the original
Task
model, which is exposed by the data layer to the UI layer. This is to more accurately mirror what would happen in a real app, where data obtained from a particular source needs to be mapped into a format which can be used by the rest of the app.They are in
ModelMappingExt.kt
, and could be converted to mapping classes if this is better practice.Local data source is now a Data Access Object
Having both the local and network data sources implement the same interface wasn't realistic (they wouldn't have the same CRUD methods). The local data source is now a DAO.
Task creation and updates are now handled by the task repository
I've moved the responsibility for creating and updating tasks into the task repo (with
createTask
andupdateTask
methods). Previously the UI layer (or any other layer) could create or update aTask
, then the repo would save it. This violates SSOT because it's possible to have tasks with UUIDs in memory which the repository hasn't ever seen. This way the UUID creation is encapsulated in the repository, although it does mean thecreate
andupdate
methods need updating each time a new editable field is added toTask
. Feedback welcome on this.Tidied a few other things up
FakeFailingTasksRemoteDataSource.kt
- it's not used anywhere and I got tired of having build failures every time I changed the data source interface which it implementsrepo.*blocking
convenience methods - tests have been updated to userunTest
instead