Начал 3 лабу
This commit is contained in:
parent
a2ac394189
commit
1cfd40ae3e
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="KotlinJpsPluginSettings">
|
||||
<option name="version" value="1.8.10" />
|
||||
<option name="version" value="1.8.20" />
|
||||
</component>
|
||||
</project>
|
@ -1,6 +1,7 @@
|
||||
plugins {
|
||||
id("com.android.application")
|
||||
id("org.jetbrains.kotlin.android")
|
||||
id("com.google.devtools.ksp")
|
||||
}
|
||||
|
||||
android {
|
||||
@ -67,4 +68,12 @@ dependencies {
|
||||
androidTestImplementation("androidx.compose.ui:ui-test-junit4")
|
||||
debugImplementation("androidx.compose.ui:ui-tooling")
|
||||
debugImplementation("androidx.compose.ui:ui-test-manifest")
|
||||
|
||||
// Room
|
||||
val room_version = "2.5.2"
|
||||
implementation("androidx.room:room-runtime:$room_version")
|
||||
annotationProcessor("androidx.room:room-compiler:$room_version")
|
||||
ksp("androidx.room:room-compiler:$room_version")
|
||||
implementation("androidx.room:room-ktx:$room_version")
|
||||
implementation("androidx.room:room-paging:$room_version")
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package com.example.mobileapp.database
|
||||
|
||||
import androidx.room.Database
|
||||
import androidx.room.RoomDatabase
|
||||
import com.example.mobileapp.database.entities.Mail
|
||||
import com.example.mobileapp.database.entities.Story
|
||||
import com.example.mobileapp.database.entities.User
|
||||
|
||||
@Database(entities = [User::class, Story::class, Mail::class], version = 1, exportSchema = false)
|
||||
abstract class MobileAppDataBase : RoomDatabase() {
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package com.example.mobileapp.database.dao
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Query
|
||||
import com.example.mobileapp.database.entities.Mail
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
@Dao
|
||||
interface MailDao {
|
||||
@Query("select * from mails")
|
||||
fun getAll(): Flow<List<Mail>>
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package com.example.mobileapp.database.dao
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Query
|
||||
import com.example.mobileapp.database.entities.Story
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
@Dao
|
||||
interface StoryDao {
|
||||
@Query("select * from stories")
|
||||
fun getAll(): Flow<List<Story>>
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package com.example.mobileapp.database.dao
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Query
|
||||
import com.example.mobileapp.database.entities.User
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
@Dao
|
||||
interface UserDao {
|
||||
@Query("select * from users")
|
||||
fun getAll():Flow<List<User>>
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package com.example.mobileapp.database.entities
|
||||
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
||||
import androidx.room.ForeignKey
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
@Entity(
|
||||
tableName = "mails",
|
||||
foreignKeys = [
|
||||
ForeignKey(
|
||||
entity = User::class,
|
||||
parentColumns = ["id"],
|
||||
childColumns = ["user_id"],
|
||||
onDelete = ForeignKey.RESTRICT,
|
||||
onUpdate = ForeignKey.RESTRICT
|
||||
)
|
||||
]
|
||||
)
|
||||
data class Mail(
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
var id: Int?,
|
||||
@ColumnInfo(name = "message")
|
||||
val message: String,
|
||||
@ColumnInfo(name="user_id")
|
||||
val userId: Int
|
||||
){
|
||||
override fun hashCode(): Int {
|
||||
return id ?: -1
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package com.example.mobileapp.database.entities
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
||||
import androidx.room.ForeignKey
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
@Entity(
|
||||
tableName = "stories",
|
||||
foreignKeys = [
|
||||
ForeignKey(
|
||||
entity = User::class,
|
||||
parentColumns = ["id"],
|
||||
childColumns = ["user_id"],
|
||||
onDelete = ForeignKey.RESTRICT,
|
||||
onUpdate = ForeignKey.RESTRICT
|
||||
)
|
||||
]
|
||||
)
|
||||
data class Story(
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
val id: Int?,
|
||||
@ColumnInfo(name = "title")
|
||||
val title: String,
|
||||
@ColumnInfo(name = "description")
|
||||
val description: String,
|
||||
@ColumnInfo(name = "cover")
|
||||
val cover: Bitmap,
|
||||
@ColumnInfo(name="user_id")
|
||||
val userId: Int
|
||||
){
|
||||
override fun hashCode(): Int {
|
||||
return id ?: -1
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package com.example.mobileapp.database.entities
|
||||
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
@Entity(tableName = "users")
|
||||
data class User(
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
var id: Int?,
|
||||
@ColumnInfo(name = "login")
|
||||
val login: String,
|
||||
@ColumnInfo(name = "password")
|
||||
val password: String,
|
||||
@ColumnInfo(name = "email")
|
||||
val email: String,
|
||||
){
|
||||
override fun hashCode(): Int {
|
||||
return id ?: -1
|
||||
}
|
||||
}
|
@ -2,4 +2,5 @@
|
||||
plugins {
|
||||
id("com.android.application") version "8.1.1" apply false
|
||||
id("org.jetbrains.kotlin.android") version "1.8.10" apply false
|
||||
id("com.google.devtools.ksp") version "1.8.20-1.0.11" apply false
|
||||
}
|
Loading…
Reference in New Issue
Block a user