CategoryEntryRelation

This commit is contained in:
Florian 2025-01-14 09:22:47 +01:00
parent 560c427610
commit 7726ed13f0
6 changed files with 25 additions and 8 deletions

View File

@ -7,6 +7,6 @@ import androidx.room.PrimaryKey
data class CategoryEntity( data class CategoryEntity(
@PrimaryKey(autoGenerate = true) @PrimaryKey(autoGenerate = true)
val _id: Int = 0, val _id: Int = 0,
val categoryname: String, val categoryName: String,
val icon: Int val icon: Int
) )

View File

@ -0,0 +1,15 @@
package at.xaxa.ledger.data.db
import androidx.room.Embedded
import androidx.room.Relation
import at.xaxa.ledger.data.Entry
import java.util.Locale.Category
data class EntryCategoryRelation(
@Embedded val category: Category,
@Relation(
parentColumn = "categoryName",
entityColumn = "categoryName"
)
val entry: Entry
)

View File

@ -5,6 +5,7 @@ import androidx.room.Delete
import androidx.room.Insert import androidx.room.Insert
import androidx.room.OnConflictStrategy import androidx.room.OnConflictStrategy
import androidx.room.Query import androidx.room.Query
import androidx.room.Transaction
import androidx.room.Update import androidx.room.Update
import at.xaxa.ledger.data.db.Category.CategoryEntity import at.xaxa.ledger.data.db.Category.CategoryEntity
import at.xaxa.ledger.data.db.Entry.EntryEntity import at.xaxa.ledger.data.db.Entry.EntryEntity
@ -18,6 +19,10 @@ interface LedgerDao {
@Insert(onConflict = OnConflictStrategy.IGNORE) @Insert(onConflict = OnConflictStrategy.IGNORE)
suspend fun addEntry(entryEntity: EntryEntity) suspend fun addEntry(entryEntity: EntryEntity)
@Transaction
@Query("SELECT * FROM _transaction WHERE categoryName = :categoryName")
suspend fun getEntryWithCategoryName(categoryName: String): List<EntryCategoryRelation>
@Update @Update
suspend fun updateCategory(categoryEntity: CategoryEntity) suspend fun updateCategory(categoryEntity: CategoryEntity)

View File

@ -4,7 +4,6 @@ import android.content.Context
import androidx.room.Database import androidx.room.Database
import androidx.room.Room import androidx.room.Room
import androidx.room.RoomDatabase import androidx.room.RoomDatabase
import at.xaxa.ledger.data.db.Category.CategoryEntity
import at.xaxa.ledger.data.db.Entry.EntryEntity import at.xaxa.ledger.data.db.Entry.EntryEntity

View File

@ -5,6 +5,7 @@ import androidx.lifecycle.createSavedStateHandle
import androidx.lifecycle.viewmodel.initializer import androidx.lifecycle.viewmodel.initializer
import androidx.lifecycle.viewmodel.viewModelFactory import androidx.lifecycle.viewmodel.viewModelFactory
import at.xaxa.ledger.LedgerApplication import at.xaxa.ledger.LedgerApplication
import at.xaxa.ledger.ui.edit.EditViewModel
import at.xaxa.ledger.ui.home.HomeViewModel import at.xaxa.ledger.ui.home.HomeViewModel
@ -14,9 +15,9 @@ object AppViewModelProvider {
HomeViewModel((this[APPLICATION_KEY] as LedgerApplication).entryRepository) HomeViewModel((this[APPLICATION_KEY] as LedgerApplication).entryRepository)
} }
initializer { /*initializer {
AddViewModel(this.createSavedStateHandle(), (this[APPLICATION_KEY] as LedgerApplication).entryRepository) AddViewModel(this.createSavedStateHandle(), (this[APPLICATION_KEY] as LedgerApplication).entryRepository)
} }*/
initializer { initializer {
EditViewModel(this.createSavedStateHandle(), (this[APPLICATION_KEY] as LedgerApplication).entryRepository) EditViewModel(this.createSavedStateHandle(), (this[APPLICATION_KEY] as LedgerApplication).entryRepository)

View File

@ -1,16 +1,13 @@
package at.xaxa.ledger.ui.home package at.xaxa.ledger.ui.home
import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import at.xaxa.ledger.data.Entry import at.xaxa.ledger.data.Entry
import at.xaxa.ledger.data.EntryRepository import at.xaxa.ledger.data.EntryRepository
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
data class EntryListUIState(val entry: List<Entry>) data class EntryListUIState(val entry: List<Entry>)