-
Notifications
You must be signed in to change notification settings - Fork 1
Wyrther code review1 #25
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
base: master
Are you sure you want to change the base?
Changes from all commits
1198992
be5579e
7bb7a80
f673eae
c9a6a62
3196b6d
e3129d2
b77bdf1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,7 +7,7 @@ import kotlinx.coroutines.flow.Flow | |
| @Dao | ||
| interface MedicineDAO { | ||
| @Query("SELECT * FROM Medicine ORDER BY name ASC") | ||
| fun getAlphabetizedMedicine(): Flow<List<Medicine>> | ||
| fun getAllAlphabetizedMedicine(): Flow<List<Medicine>> | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just added All to the name of the function, as the query is fetching all rows from the Medicine DB |
||
|
|
||
| @Insert(onConflict = OnConflictStrategy.IGNORE) | ||
| suspend fun insert(medicine: Medicine) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,16 @@ | ||
| package com.medmapper.v33001.dto | ||
|
|
||
| import androidx.annotation.NonNull | ||
| import androidx.room.ColumnInfo | ||
| import androidx.room.Entity | ||
| import androidx.room.PrimaryKey | ||
|
|
||
| @Entity(tableName = "Medicine") | ||
| data class Medicine( | ||
| @PrimaryKey(autoGenerate = true) val medID: Int, | ||
| @ColumnInfo(name = "name") val name: String?, | ||
| @NonNull @ColumnInfo(name = "name") val name: String, | ||
| @ColumnInfo(name = "strength") val strength: String?, | ||
| @ColumnInfo(name = "start date") val startDate: String?, | ||
| @ColumnInfo(name = "prescription length") val lengthInDays: Int | ||
| @NonNull @ColumnInfo(name = "start date") val startDate: String, | ||
| @NonNull @ColumnInfo(name = "prescription length") val lengthInDays: Int | ||
| //,@ColumnInfo() val endDate: Date = startDate | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added non nulls, as the name of the medication, start date, and start day should be required values. |
||
| ) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,17 +5,21 @@ import com.medmapper.v33001.dao.MedicineDAO | |
| import com.medmapper.v33001.dto.Medicine | ||
| import kotlinx.coroutines.flow.Flow | ||
|
|
||
| // Declares teh DAO as private property in the constructor. Pass in the DAO | ||
| // instead of the whole database, because you only need access to the DAO | ||
| /** | ||
| * Declares the DAO as private property in the constructor. | ||
| * Pass in the DAO instead of the whole database, because you only need access to the DAO | ||
| */ | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added kdoc above the class There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good. |
||
| class MedicineRepository(private val medicineDAO: MedicineDAO) { | ||
|
|
||
| // Room executes all queries on a separate thread. | ||
| // Observed Flow will notify the observer when the data has changed. | ||
| val allMedicines: Flow<List<Medicine>> = medicineDAO.getAlphabetizedMedicine() | ||
| // Room executes all queries on a separate thread. | ||
| // Observed Flow will notify the observer when the data has changed. | ||
|
|
||
| val allMedicines: Flow<List<Medicine>> = medicineDAO.getAllAlphabetizedMedicine() | ||
|
|
||
| // By default Room runs suspend queries off the main thread, therefore | ||
| // we don't need to implement anything else to ensure we're not doing | ||
| // long running database work off the main thread | ||
|
|
||
| // By default Room runs suspend queries off the main thread, therefore | ||
| // we don't need to implement anything else to ensure we're not doing | ||
| // long running database work off the main thread | ||
| @Suppress("RedundantSuspendModifier") | ||
| @WorkerThread | ||
| suspend fun insert(medicine: Medicine) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,13 +7,16 @@ import androidx.room.RoomDatabase | |
| import com.medmapper.v33001.dao.MedicineDAO | ||
| import com.medmapper.v33001.dto.Medicine | ||
|
|
||
| /** | ||
| * | ||
| */ | ||
|
Comment on lines
+10
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Empty KDoc does not add value. |
||
| @Database(entities = arrayOf(Medicine::class), version = 1, exportSchema = false) | ||
| public abstract class MedicineRoomDatabase : RoomDatabase() { | ||
|
|
||
| abstract fun medicineDao(): MedicineDAO | ||
|
|
||
| //Singleton prevents multiple instances of database opening at the same time. | ||
| companion object { | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved comment out of the actual code block and added a blank kdoc section for future documentation. Since it is a public class, there should be some documentation for it. |
||
| // Singleton prevents multiple instances of database opening at the same time. | ||
| @Volatile | ||
| private var INSTANCE: MedicineRoomDatabase? = null | ||
| fun getDatabase(context: Context): MedicineRoomDatabase { | ||
|
|
||
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.
Added version variable to make it a little easier to update any room dependencies.
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.
Good idea. Dependencies are like whack a mole in Android.