Slide 11
Slide 11 text
class LoginViewModel(private val loginRepository: LoginRepository) :
ViewModel() {
fun login(username: String, token: String) {
viewModelScope.launch {
val jsonBody = "{ username: \"$username\", token: \"$token\"}"
// makeLoginRequestͷ࣮ߦIOεϨουͰߦΘΕΔ
// ͦͷؒɺUIεϨουϒϩοΫ͞Εͳ͍ͷͰɺϢʔβૢ࡞Λड͚͚ΒΕΔ
val result = loginRepository.makeLoginRequest(jsonBody)
// ݁ՌΛUIεϨουͰॲཧ͢Δ
when (result) {
is Result.Success -> ...
else -> ...
}
}
}
}