TKK_E32230270/app/RiwayatViewModel.kt

26 lines
762 B
Kotlin

package com.adit.smartplant.viewmodel
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.adit.smartplant.model.RiwayatItem
import com.adit.smartplant.network.RetrofitClient
import kotlinx.coroutines.launch
class RiwayatViewModel : ViewModel() {
var riwayatList by mutableStateOf<List<RiwayatItem>>(emptyList())
private set
fun loadRiwayat(userId: Int) {
viewModelScope.launch {
try {
riwayatList = RetrofitClient.api.getRiwayat(userId)
} catch (e: Exception) {
e.printStackTrace()
}
}
}
}