Skip to content

Instantly share code, notes, and snippets.

package com.example.spendly1
import androidx.room.*
import kotlinx.coroutines.flow.Flow
@Dao
interface UserDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertUser(user: User)//cохранение нового пользователя
@Query("SELECT EXISTS(SELECT * FROM users WHERE login = :login)")
@ttyhyjj
ttyhyjj / User.kt
Created May 23, 2026 09:54
spendly
package com.example.spendly1
import androidx.room.Entity
import androidx.room.PrimaryKey
@Entity(tableName = "users")//превращает класс в таблицу
data class User (
@PrimaryKey(autoGenerate = true) val id: Int = 0,//индентификатор для каждой строки
val password: String,//пароль
val firstName: String? = null,//имя
package com.example.spendly1
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch
import java.util.Calendar
package com.example.spendly1
import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.Query
import kotlinx.coroutines.flow.Flow
@Dao
interface GoalDao {
@ttyhyjj
ttyhyjj / Goal.kt
Created May 23, 2026 09:24
spendly
package com.example.spendly1
import androidx.room.Entity
import androidx.room.PrimaryKey
@Entity(tableName = "goals")
data class Goal(
@PrimaryKey(autoGenerate = true) val id: Int = 0,
val userLogin: String,//привязка к пользователю
val title: String,//название цели
package com.example.spendly1
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
package com.example.spendly1
import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
@Database(entities = [User::class, Transaction::class, Goal::class], version = 4)
abstract class AppDatabase : RoomDatabase() {
abstract fun userDao(): UserDao
package com.example.spendly1
import com.example.spendly1.Transaction
import com.example.spendly1.CategorySum
import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.Query
import kotlinx.coroutines.flow.Flow
@Dao
package com.example.spendly1
import androidx.room.Entity
import androidx.room.PrimaryKey
@Entity(tableName = "transactions")//бд
data class Transaction(
@PrimaryKey(autoGenerate = true) val id : Int = 0,//присваивание новой записи ID
val userLogin: String,//логин
val title: String,//название
package com.example.spendly1
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier