aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/db/NotificationDb.kt
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2019-03-06 17:42:31 -0500
committerAllan Wang <me@allanwang.ca>2019-03-06 17:42:31 -0500
commit8b70d80070209eb19791eecf207a8fdefea17a4e (patch)
tree41ed8afcbe74d138fc6dbf601c5e6e33486e8969 /app/src/main/kotlin/com/pitchedapps/frost/db/NotificationDb.kt
parent9a1d9719ad6559054ea1bc4f21f8559559eb9cda (diff)
downloadfrost-8b70d80070209eb19791eecf207a8fdefea17a4e.tar.gz
frost-8b70d80070209eb19791eecf207a8fdefea17a4e.tar.bz2
frost-8b70d80070209eb19791eecf207a8fdefea17a4e.zip
Make db entities immutable
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/db/NotificationDb.kt')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/db/NotificationDb.kt64
1 files changed, 64 insertions, 0 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/db/NotificationDb.kt b/app/src/main/kotlin/com/pitchedapps/frost/db/NotificationDb.kt
index 5b501792..56c3c5ac 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/db/NotificationDb.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/db/NotificationDb.kt
@@ -16,6 +16,16 @@
*/
package com.pitchedapps.frost.db
+import androidx.room.Dao
+import androidx.room.Embedded
+import androidx.room.Entity
+import androidx.room.ForeignKey
+import androidx.room.Ignore
+import androidx.room.Index
+import androidx.room.Insert
+import androidx.room.Query
+import androidx.room.Relation
+import androidx.room.Transaction
import com.pitchedapps.frost.utils.L
import com.raizlabs.android.dbflow.annotation.ConflictAction
import com.raizlabs.android.dbflow.annotation.Database
@@ -32,6 +42,60 @@ import com.raizlabs.android.dbflow.sql.SQLiteType
import com.raizlabs.android.dbflow.sql.migration.AlterTableMigration
import com.raizlabs.android.dbflow.structure.BaseModel
+@Entity(
+ tableName = "notification_info",
+ foreignKeys = [ForeignKey(
+ entity = CookieEntity::class,
+ parentColumns = ["id"], childColumns = ["id"], onDelete = ForeignKey.CASCADE
+ )]
+)
+data class NotificationInfoEntity(
+ @androidx.room.PrimaryKey val id: Long,
+ val epoch: Long,
+ val epochIm: Long
+)
+
+@Entity(
+ tableName = "notifications",
+ foreignKeys = [ForeignKey(
+ entity = NotificationInfoEntity::class,
+ parentColumns = ["id"],
+ childColumns = ["userId"],
+ onDelete = ForeignKey.CASCADE
+ )],
+ indices = [Index("userId")]
+)
+data class NotificationEntity(
+ @androidx.room.PrimaryKey var id: Long,
+ val userId: Long,
+ val href: String,
+ val title: String?,
+ val text: String,
+ val timestamp: Long,
+ val profileUrl: String?
+) {
+ @Ignore
+ val notifId = Math.abs(id.toInt())
+}
+
+data class NotificationInfo(
+ @Embedded
+ val info: NotificationInfoEntity,
+ @Relation(parentColumn = "id", entityColumn = "userId")
+ val notifications: List<NotificationEntity> = emptyList()
+)
+
+@Dao
+interface NotificationDao {
+
+ @Query("SELECT * FROM notification_info WHERE id = :id")
+ fun selectById(id: Long): NotificationInfo?
+
+ @Transaction
+ @Insert
+ fun insertInfo(info: NotificationInfoEntity)
+}
+
/**
* Created by Allan Wang on 2017-05-30.
*/