-
Notifications
You must be signed in to change notification settings - Fork 1
My Code Review Suggestions. #21
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
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 |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| <manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
|
||
| <application> | ||
|
|
||
| </application> | ||
|
|
||
| </manifest> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package com.medmapper.v33001.dao | ||
|
|
||
| import androidx.room.TypeConverter | ||
| import java.util.Date | ||
|
|
||
| class DateConverter { | ||
| @TypeConverter | ||
| fun fromTimestamp(value: Long?): Date? { | ||
| return value?.let { Date(it) } | ||
| } | ||
|
|
||
| @TypeConverter | ||
| fun dateToTimestamp(date: Date?): Long? { | ||
| return date?.time | ||
| } | ||
| } | ||
|
|
||
|
Comment on lines
+1
to
+17
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 the DateConverter.kt class file to enable Room to store and retrieve Date objects from the database (refer Medicine.kt). This ensures proper storage and retrieval of dates from the database. This is a common practice in Android development when working with Room databases. Source: https://developer.android.com/training/data-storage/room/referencing-data#type-converters |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,12 +6,17 @@ import kotlinx.coroutines.flow.Flow | |
|
|
||
| @Dao | ||
| interface MedicineDAO { | ||
|
|
||
| @Query("SELECT * FROM Medicine ORDER BY name ASC") | ||
| fun getAlphabetizedMedicine(): Flow<List<Medicine>> | ||
|
|
||
| @Insert(onConflict = OnConflictStrategy.IGNORE) | ||
| suspend fun insert(medicine: Medicine) | ||
|
|
||
| @Query("DELETE FROM Medicine") | ||
| suspend fun deleteAll() | ||
| @Delete | ||
| suspend fun delete(medicine: Medicine) | ||
|
|
||
| @Update | ||
| suspend fun update(medicine: Medicine) | ||
|
|
||
|
Comment on lines
+16
to
+21
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. Room provides specific annotations for DELETE and UPDATE. Using @delete and @update annotations instead of @query can make the code more concise and easier to read. Source: https://developer.android.com/training/data-storage/room/accessing-data |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,13 +3,16 @@ package com.medmapper.v33001.dto | |
| import androidx.room.ColumnInfo | ||
| import androidx.room.Entity | ||
| import androidx.room.PrimaryKey | ||
| import androidx.room.TypeConverters | ||
| import com.medmapper.v33001.dao.DateConverter | ||
|
|
||
| @Entity(tableName = "Medicine") | ||
| @TypeConverters(DateConverter::class) | ||
|
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. Room does not support non-primitive data types such as Date, so we need to define a TypeConverter to convert them to and from primitive data types that Room can handle. The @TypeConverter annotation can convert a custom type to a supported database type Source: https://developer.android.com/training/data-storage/room/referencing-data.html#type-converters |
||
| data class Medicine( | ||
| @PrimaryKey(autoGenerate = true) val medID: Int, | ||
| @ColumnInfo(name = "name") val name: String?, | ||
| @ColumnInfo(name = "strength") val strength: String?, | ||
| @ColumnInfo(name = "start date") val startDate: String?, | ||
| @ColumnInfo(name = "start_date") val startDate: String?, | ||
|
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. Column names should be lowercase, with words separated by underscores ("_"). Source: https://developer.android.com/training/data-storage/room/defining-data |
||
| @ColumnInfo(name = "prescription length") val lengthInDays: Int | ||
| //,@ColumnInfo() val endDate: Date = startDate | ||
| ) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,10 +4,13 @@ import android.content.Context | |
| import androidx.room.Database | ||
| import androidx.room.Room | ||
| import androidx.room.RoomDatabase | ||
| import androidx.room.TypeConverters | ||
| import com.medmapper.v33001.dao.DateConverter | ||
| import com.medmapper.v33001.dao.MedicineDAO | ||
| import com.medmapper.v33001.dto.Medicine | ||
|
|
||
| @Database(entities = arrayOf(Medicine::class), version = 1, exportSchema = false) | ||
| @Database(entities = [Medicine::class], version = 1, exportSchema = false) | ||
|
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. The spread operator * is preferred over arrayOf when passing vararg arguments because it avoids the overhead of creating an additional array. Source: https://kotlinlang.org/docs/functions.html#variable-number-of-arguments-varargs |
||
| @TypeConverters(DateConverter::class) | ||
| public abstract class MedicineRoomDatabase : RoomDatabase() { | ||
|
|
||
| abstract fun medicineDao(): MedicineDAO | ||
|
|
||
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.
Remove this file, as: