Refactoring to use model classes instead of database entitites#1347
Refactoring to use model classes instead of database entitites#1347
Conversation
# Conflicts: # app/src/main/java/com/futsch1/medtimer/reminders/ReminderNotificationProcessor.kt # app/src/test/java/com/futsch1/medtimer/processortests/NotificationProcessorTest.kt # app/src/test/java/com/futsch1/medtimer/processortests/RefillProcessorTest.kt # app/src/test/java/com/futsch1/medtimer/processortests/RepeatProcessorTest.kt # app/src/test/java/com/futsch1/medtimer/processortests/ScheduleNextReminderNotificationProcessorTest.kt
Resolved conflicts by keeping entity naming convention (*Entity suffix) and adding mapper layer in ReminderEventRepository to bridge between database entities and domain model ReminderEvent.
# Conflicts: # app/src/main/java/com/futsch1/medtimer/database/MedicineRepository.kt # app/src/main/java/com/futsch1/medtimer/reminders/NotificationProcessor.kt # app/src/main/java/com/futsch1/medtimer/statistics/CalendarEventsViewModel.kt
2 new issues
|
app/src/main/java/com/futsch1/medtimer/database/TagRepository.kt
Outdated
Show resolved
Hide resolved
app/src/main/java/com/futsch1/medtimer/overview/model/PastReminderEvent.kt
Outdated
Show resolved
Hide resolved
app/src/main/java/com/futsch1/medtimer/overview/model/ScheduledReminderEvent.kt
Outdated
Show resolved
Hide resolved
app/src/main/java/com/futsch1/medtimer/database/dao/ReminderDao.kt
Outdated
Show resolved
Hide resolved
app/src/main/java/com/futsch1/medtimer/database/dao/ReminderEventDao.kt
Outdated
Show resolved
Hide resolved
|
@ThomasKiljanczykDev Android Tests still fail, so there's a few bugs left which I will fix. |
ThomasKiljanczykDev
left a comment
There was a problem hiding this comment.
I haven't reviewed everything, but some of these comment are disruptive enough that the code might change a lot.
I will continue the review once you address my current comments.
| private val reminderRepository: ReminderRepository, | ||
| private val reminderEventRepository: ReminderEventRepository, | ||
| private val tagRepository: TagRepository, | ||
| private val medicineDao: MedicineDao, |
There was a problem hiding this comment.
Why have you replaced repositories with dao?
The repositories were meant to abstract ALL the code from the db implementation.
With this mixed approach you're breaking this layer of abstraction
There was a problem hiding this comment.
I have moved this class into the database package for a reason: I consider the backup tightly coupled to the database implementation, so it is a database backup, not a model backup (also for the sake of compatibility). Since repositories interface is now based on the model classes, the backup requires a direct database access.
So I do not consider this breaking the abstraction.
|
|
||
| private fun createAndSave(fileContent: String?) { | ||
| val file = File(context.cacheDir, backupFilename) | ||
| val file = File(context.cacheDir, PathHelper.backupFilename) |
There was a problem hiding this comment.
Helper (and Util) is a very vague name which often leads to dumping a lot of unrelated code into a single class.
It would probably be better to give it some more sensible name
| val id: Int, | ||
| val color: Int, | ||
| val useColor: Boolean, | ||
| val notificationImportance: ReminderNotificationChannelManager.Importance, |
There was a problem hiding this comment.
You should probably extract the importance into NotificationImportance to make it independent from the channel manager. Channels themself are more part of the application layer
| ) : JSONBackup<FullMedicineEntity>(FullMedicineEntity::class.java) { | ||
| override fun createBackup(databaseVersion: Int, list: List<FullMedicineEntity>): JsonElement { | ||
| // Correct the medicines where the reminder's instructions are null in this loop | ||
| for (fullMedicine in list) { |
There was a problem hiding this comment.
You could use flatMap here instead of this for
|
|
||
| private suspend fun processTags(fullMedicine: FullMedicineEntity, medicineId: Int) { | ||
| for (tag in fullMedicine.tags) { | ||
| val tagId = tagDao.create(tag).toInt() |
There was a problem hiding this comment.
You should probably sort this ID casting nonsense.
It should be either int everywhere or long everywhere.
Long is the safer option since the performance impact should not be that noticeable and you get practically infinite possible values
There was a problem hiding this comment.
I do not see how: Room always returns long from @insert operations. I chose to use int as ID type some time ago and do not want to do a migration just to change this to long.
The repositories now always return int IDs, so towards the application it's int only. Internally, we have to do a cast, but I do not see how this hurts.
| } | ||
| } | ||
|
|
||
| private suspend fun processReminders(fullMedicine: FullMedicineEntity, medicineId: Int) { |
There was a problem hiding this comment.
You should accept the domain model and copy the reminders (with id reset)
There was a problem hiding this comment.
See my comment above: I'd like to keep the backup logic close to the database structure.
| @Entity | ||
| class Medicine() { | ||
| @Entity(tableName = "Medicine") | ||
| class MedicineEntity() { |
There was a problem hiding this comment.
You could move all the properties into the constructor so you create new entities more easily without for default values
Rename PathHelper.kt to ExportBackupPath.kt
Unified database id datatype handling Improve JSONBackup::createBackup
|
@ThomasKiljanczykDev |
|
@ThomasKiljanczykDev |
No description provided.