From 1445650101047a4714674ad33b5e1d33ebece409 Mon Sep 17 00:00:00 2001 From: gitsuhyun Date: Tue, 12 Nov 2024 00:41:45 +0900 Subject: [PATCH] =?UTF-8?q?#8=20[feat]=20:=20=EC=9C=A0=EC=A0=80=20?= =?UTF-8?q?=EB=A1=9C=EA=B7=B8=EC=9D=B8=20api=20=EC=97=B0=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/sopt/and/feature/login/LoginScreen.kt | 7 ++++ .../sopt/and/feature/login/LoginViewModel.kt | 38 +++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/app/src/main/java/org/sopt/and/feature/login/LoginScreen.kt b/app/src/main/java/org/sopt/and/feature/login/LoginScreen.kt index a150828..a039768 100644 --- a/app/src/main/java/org/sopt/and/feature/login/LoginScreen.kt +++ b/app/src/main/java/org/sopt/and/feature/login/LoginScreen.kt @@ -56,6 +56,7 @@ import org.sopt.and.R import org.sopt.and.core.designsystem.component.AuthTextField import org.sopt.and.core.designsystem.component.SocialLoginButtonGroup import org.sopt.and.core.designsystem.component.WavveLoginButton +import org.sopt.and.data.model.request.UserLoginRequest import org.sopt.and.feature.main.Routes import org.sopt.and.ui.theme.WavveTheme import org.sopt.and.utils.noRippleClickable @@ -187,6 +188,12 @@ fun LoginScreen( localEmail = localEmail, localPassword = localPassword, onSuccess = { email, password -> + viewModel.postUserLogin( + body = UserLoginRequest( + username = "email", + password = "password" + ) + ) onLoginSuccess(email, password) }, onFailure = { diff --git a/app/src/main/java/org/sopt/and/feature/login/LoginViewModel.kt b/app/src/main/java/org/sopt/and/feature/login/LoginViewModel.kt index 118dbb4..eb411d8 100644 --- a/app/src/main/java/org/sopt/and/feature/login/LoginViewModel.kt +++ b/app/src/main/java/org/sopt/and/feature/login/LoginViewModel.kt @@ -1,12 +1,50 @@ package org.sopt.and.feature.login +import android.util.Log +import androidx.compose.runtime.State +import androidx.compose.runtime.mutableStateOf import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import kotlinx.coroutines.launch +import org.sopt.and.data.ServicePool +import org.sopt.and.data.model.dto.ResponseUserTokenDto +import org.sopt.and.data.model.request.UserLoginRequest +import retrofit2.Call +import retrofit2.Callback +import retrofit2.Response class LoginViewModel : ViewModel() { + private val userService by lazy { ServicePool.userService } + + private val _userState = mutableStateOf(null) + val userState: State get() = _userState + + fun postUserLogin(body: UserLoginRequest) { + userService.postUserLogin( + body = body + ).enqueue(object : Callback { + override fun onResponse( + call: Call, + response: Response + ) { + if (response.isSuccessful) { + _userState.value = response.body() + Log.d("postUserLogin", response.body().toString()) + + } else { + val error = response.message() + Log.e("error", error.toString()) + } + } + + override fun onFailure(call: Call, t: Throwable) { + Log.e("failure", t.message.toString()) + } + }) + } + private val _email = MutableLiveData("") val email: LiveData get() = _email