Add base models.
This commit is contained in:
parent
542b673a1f
commit
63207fadd8
@ -0,0 +1,40 @@
|
|||||||
|
package ru.ulstu.`is`.pmu.student.model
|
||||||
|
|
||||||
|
import androidx.room.ColumnInfo
|
||||||
|
import androidx.room.Entity
|
||||||
|
import androidx.room.Ignore
|
||||||
|
import androidx.room.PrimaryKey
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
data class User (
|
||||||
|
@PrimaryKey(autoGenerate = true)
|
||||||
|
val uid: Long?,
|
||||||
|
@ColumnInfo(name = "nickname")
|
||||||
|
val nickname: String,
|
||||||
|
@ColumnInfo(name = "email")
|
||||||
|
val email: String,
|
||||||
|
@ColumnInfo(name = "password")
|
||||||
|
val password: String,
|
||||||
|
@ColumnInfo(name = "balance")
|
||||||
|
val balance: Int
|
||||||
|
){
|
||||||
|
@Ignore
|
||||||
|
constructor(
|
||||||
|
nickname: String,
|
||||||
|
email: String,
|
||||||
|
password: String,
|
||||||
|
balance: Int
|
||||||
|
) : this(null, nickname, email, password, balance)
|
||||||
|
|
||||||
|
override fun equals(other: Any?): Boolean {
|
||||||
|
if (this === other) return true
|
||||||
|
if (javaClass != other?.javaClass) return false
|
||||||
|
other as Tank
|
||||||
|
if (uid != other.uid) return false
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun hashCode(): Int {
|
||||||
|
return (uid ?: -1) as Int
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
package ru.ulstu.`is`.pmu.student.model
|
||||||
|
|
||||||
|
import androidx.room.Entity
|
||||||
|
|
||||||
|
//many to many for user and tank
|
||||||
|
@Entity(primaryKeys = ["userId", "tankId"])
|
||||||
|
data class UserTankCrossRef(
|
||||||
|
val userId: Long,
|
||||||
|
val tankId: Long
|
||||||
|
)
|
@ -0,0 +1,16 @@
|
|||||||
|
package ru.ulstu.`is`.pmu.student.model
|
||||||
|
|
||||||
|
import androidx.room.Embedded
|
||||||
|
import androidx.room.Junction
|
||||||
|
import androidx.room.Relation
|
||||||
|
|
||||||
|
//для работы many to many для получения списка танков для пользователя
|
||||||
|
data class UserWithTanks(
|
||||||
|
@Embedded val user: User,
|
||||||
|
@Relation(
|
||||||
|
parentColumn = "userId",
|
||||||
|
entityColumn = "tankId",
|
||||||
|
associateBy = Junction(UserTankCrossRef::class)
|
||||||
|
)
|
||||||
|
val tanks: List<Tank>
|
||||||
|
)
|
Loading…
x
Reference in New Issue
Block a user