Add base models.

This commit is contained in:
ElEgEv 2023-11-11 17:29:21 +04:00
parent 542b673a1f
commit 63207fadd8
3 changed files with 66 additions and 0 deletions

View File

@ -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
}
}

View File

@ -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
)

View File

@ -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>
)