From 78c17dc38e15421f8735015fb6955cb51e8a2c5c Mon Sep 17 00:00:00 2001 From: LEE YOU BIN Date: Thu, 18 Jul 2024 05:28:14 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[FEAT/#119]=20=EB=A7=88=EC=9D=B4=ED=8E=98?= =?UTF-8?q?=EC=9D=B4=EC=A7=80=20=EC=A0=95=EB=B3=B4=20=EC=84=9C=EB=B2=84?= =?UTF-8?q?=ED=86=B5=EC=8B=A0=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/datasource/MyPageDataSource.kt | 4 +++ .../datasourceimpl/MyPageDataSourceImpl.kt | 4 +++ .../data/dto/response/MyPageResponseDto.kt | 15 ++++++++ .../repositoryimpl/MyPageRepositoryImpl.kt | 9 ++++- .../com/terning/data/service/MyPageService.kt | 6 ++++ .../entity/response/MyPageProfileModel.kt | 6 ++++ .../domain/repository/MyPageRepository.kt | 8 +++-- .../com/terning/feature/mypage/MyPageRoute.kt | 26 +++++++++++--- .../com/terning/feature/mypage/MyPageState.kt | 5 ++- .../terning/feature/mypage/MyPageViewModel.kt | 35 +++++++++++++++---- .../onboarding/signin/SignInViewModel.kt | 2 ++ 11 files changed, 106 insertions(+), 14 deletions(-) create mode 100644 data/src/main/java/com/terning/data/dto/response/MyPageResponseDto.kt create mode 100644 domain/src/main/java/com/terning/domain/entity/response/MyPageProfileModel.kt diff --git a/data/src/main/java/com/terning/data/datasource/MyPageDataSource.kt b/data/src/main/java/com/terning/data/datasource/MyPageDataSource.kt index b92bb80a5..5eee61e1b 100644 --- a/data/src/main/java/com/terning/data/datasource/MyPageDataSource.kt +++ b/data/src/main/java/com/terning/data/datasource/MyPageDataSource.kt @@ -1,9 +1,13 @@ package com.terning.data.datasource +import com.terning.data.dto.BaseResponse import com.terning.data.dto.NonDataBaseResponse +import com.terning.data.dto.response.MyPageResponseDto interface MyPageDataSource { suspend fun postLogout(): NonDataBaseResponse suspend fun deleteQuit(): NonDataBaseResponse + + suspend fun getProfile(): BaseResponse } \ No newline at end of file diff --git a/data/src/main/java/com/terning/data/datasourceimpl/MyPageDataSourceImpl.kt b/data/src/main/java/com/terning/data/datasourceimpl/MyPageDataSourceImpl.kt index f70adf162..d1636d0d5 100644 --- a/data/src/main/java/com/terning/data/datasourceimpl/MyPageDataSourceImpl.kt +++ b/data/src/main/java/com/terning/data/datasourceimpl/MyPageDataSourceImpl.kt @@ -1,7 +1,9 @@ package com.terning.data.datasourceimpl import com.terning.data.datasource.MyPageDataSource +import com.terning.data.dto.BaseResponse import com.terning.data.dto.NonDataBaseResponse +import com.terning.data.dto.response.MyPageResponseDto import com.terning.data.service.MyPageService import javax.inject.Inject @@ -11,4 +13,6 @@ class MyPageDataSourceImpl @Inject constructor( override suspend fun postLogout(): NonDataBaseResponse = myPageService.postLogout() override suspend fun deleteQuit(): NonDataBaseResponse = myPageService.deleteQuit() + + override suspend fun getProfile(): BaseResponse = myPageService.getProfile() } \ No newline at end of file diff --git a/data/src/main/java/com/terning/data/dto/response/MyPageResponseDto.kt b/data/src/main/java/com/terning/data/dto/response/MyPageResponseDto.kt new file mode 100644 index 000000000..a43b1d72c --- /dev/null +++ b/data/src/main/java/com/terning/data/dto/response/MyPageResponseDto.kt @@ -0,0 +1,15 @@ +package com.terning.data.dto.response + +import com.terning.domain.entity.response.MyPageProfileModel +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class MyPageResponseDto( + @SerialName("name") + val name: String, + @SerialName("authType") + val authType: String +) + +fun MyPageResponseDto.toMyPageProfileModel() = MyPageProfileModel(name = name, authType = authType) diff --git a/data/src/main/java/com/terning/data/repositoryimpl/MyPageRepositoryImpl.kt b/data/src/main/java/com/terning/data/repositoryimpl/MyPageRepositoryImpl.kt index 447f7de68..d58702e35 100644 --- a/data/src/main/java/com/terning/data/repositoryimpl/MyPageRepositoryImpl.kt +++ b/data/src/main/java/com/terning/data/repositoryimpl/MyPageRepositoryImpl.kt @@ -1,6 +1,8 @@ package com.terning.data.repositoryimpl import com.terning.data.datasource.MyPageDataSource +import com.terning.data.dto.response.toMyPageProfileModel +import com.terning.domain.entity.response.MyPageProfileModel import com.terning.domain.repository.MyPageRepository import javax.inject.Inject @@ -13,7 +15,12 @@ class MyPageRepositoryImpl @Inject constructor( } override suspend fun deleteQuit(): Result = - runCatching{ + runCatching { myPageDataSource.deleteQuit() } + + override suspend fun getProfile(): Result = + runCatching { + myPageDataSource.getProfile().result.toMyPageProfileModel() + } } \ No newline at end of file diff --git a/data/src/main/java/com/terning/data/service/MyPageService.kt b/data/src/main/java/com/terning/data/service/MyPageService.kt index 6d5da1fc2..26a7d76ca 100644 --- a/data/src/main/java/com/terning/data/service/MyPageService.kt +++ b/data/src/main/java/com/terning/data/service/MyPageService.kt @@ -1,7 +1,10 @@ package com.terning.data.service +import com.terning.data.dto.BaseResponse import com.terning.data.dto.NonDataBaseResponse +import com.terning.data.dto.response.MyPageResponseDto import retrofit2.http.DELETE +import retrofit2.http.GET import retrofit2.http.POST interface MyPageService { @@ -10,4 +13,7 @@ interface MyPageService { @DELETE("api/v1/auth/withdraw") suspend fun deleteQuit(): NonDataBaseResponse + + @GET("api/v1/mypage/profile") + suspend fun getProfile(): BaseResponse } \ No newline at end of file diff --git a/domain/src/main/java/com/terning/domain/entity/response/MyPageProfileModel.kt b/domain/src/main/java/com/terning/domain/entity/response/MyPageProfileModel.kt new file mode 100644 index 000000000..18815ba97 --- /dev/null +++ b/domain/src/main/java/com/terning/domain/entity/response/MyPageProfileModel.kt @@ -0,0 +1,6 @@ +package com.terning.domain.entity.response + +data class MyPageProfileModel( + val name: String, + val authType: String +) \ No newline at end of file diff --git a/domain/src/main/java/com/terning/domain/repository/MyPageRepository.kt b/domain/src/main/java/com/terning/domain/repository/MyPageRepository.kt index 2419f1b63..78e1329a9 100644 --- a/domain/src/main/java/com/terning/domain/repository/MyPageRepository.kt +++ b/domain/src/main/java/com/terning/domain/repository/MyPageRepository.kt @@ -1,7 +1,11 @@ package com.terning.domain.repository +import com.terning.domain.entity.response.MyPageProfileModel + interface MyPageRepository { - suspend fun postLogout() : Result + suspend fun postLogout(): Result + + suspend fun deleteQuit(): Result - suspend fun deleteQuit() : Result + suspend fun getProfile(): Result } \ No newline at end of file diff --git a/feature/src/main/java/com/terning/feature/mypage/MyPageRoute.kt b/feature/src/main/java/com/terning/feature/mypage/MyPageRoute.kt index 31ac78a82..bc9304f6d 100644 --- a/feature/src/main/java/com/terning/feature/mypage/MyPageRoute.kt +++ b/feature/src/main/java/com/terning/feature/mypage/MyPageRoute.kt @@ -46,6 +46,9 @@ fun MyPageRoute( var showLogoutBottomSheet by remember { mutableStateOf(false) } var showQuitBottomSheet by remember { mutableStateOf(false) } + var name by remember { mutableStateOf(state.name) } + var authType by remember { mutableStateOf(state.authType) } + if (showLogoutBottomSheet) { MyPageLogoutBottomSheet( onDismiss = { showLogoutBottomSheet = false }, @@ -64,7 +67,7 @@ fun MyPageRoute( ) } - when (state.isSuccess) { + when (state.isLogoutAndQuitSuccess) { is UiState.Success -> { viewModel.restartApp(context) } @@ -74,16 +77,31 @@ fun MyPageRoute( is UiState.Failure -> {} } + when (state.isGetSuccess) { + is UiState.Success -> { + name = state.name + authType = state.authType + } + + is UiState.Loading -> {} + is UiState.Empty -> {} + is UiState.Failure -> {} + } + MyPageScreen( onLogoutClick = { showLogoutBottomSheet = true }, - onQuitClick = { showQuitBottomSheet = true } + onQuitClick = { showQuitBottomSheet = true }, + name = name, + authType = authType ) } @Composable fun MyPageScreen( onLogoutClick: () -> Unit, - onQuitClick: () -> Unit + onQuitClick: () -> Unit, + name: String = "", + authType: String = "" ) { Scaffold( modifier = Modifier, @@ -96,7 +114,7 @@ fun MyPageScreen( modifier = Modifier.padding(top = paddingValues.calculateTopPadding()) ) { Text( - text = stringResource(id = R.string.my_page_name, "남지우"), + text = stringResource(id = R.string.my_page_name, name), modifier = Modifier.padding( top = 21.dp, start = 24.dp, diff --git a/feature/src/main/java/com/terning/feature/mypage/MyPageState.kt b/feature/src/main/java/com/terning/feature/mypage/MyPageState.kt index 58e86acae..de4e3daf9 100644 --- a/feature/src/main/java/com/terning/feature/mypage/MyPageState.kt +++ b/feature/src/main/java/com/terning/feature/mypage/MyPageState.kt @@ -3,5 +3,8 @@ package com.terning.feature.mypage import com.terning.core.state.UiState data class MyPageState( - val isSuccess: UiState = UiState.Loading + val isLogoutAndQuitSuccess: UiState = UiState.Loading, + val isGetSuccess : UiState = UiState.Loading, + val name: String = "", + val authType: String = "" ) \ No newline at end of file diff --git a/feature/src/main/java/com/terning/feature/mypage/MyPageViewModel.kt b/feature/src/main/java/com/terning/feature/mypage/MyPageViewModel.kt index b1eff6c6b..28fbab516 100644 --- a/feature/src/main/java/com/terning/feature/mypage/MyPageViewModel.kt +++ b/feature/src/main/java/com/terning/feature/mypage/MyPageViewModel.kt @@ -25,6 +25,10 @@ class MyPageViewModel @Inject constructor( private val tokenRepository: TokenRepository ) : ViewModel() { + init { + getProfile() + } + private val _state: MutableStateFlow = MutableStateFlow(MyPageState()) val state: StateFlow get() = _state.asStateFlow() @@ -33,7 +37,8 @@ class MyPageViewModel @Inject constructor( if (error == null) { postLogout() } else { - _state.value = _state.value.copy(isSuccess = UiState.Failure(error.toString())) + _state.value = + _state.value.copy(isLogoutAndQuitSuccess = UiState.Failure(error.toString())) } } } @@ -42,9 +47,10 @@ class MyPageViewModel @Inject constructor( viewModelScope.launch { myPageRepository.postLogout().onSuccess { tokenRepository.clearInfo() - _state.value = _state.value.copy(isSuccess = UiState.Success(true)) + _state.value = _state.value.copy(isLogoutAndQuitSuccess = UiState.Success(true)) }.onFailure { - _state.value = _state.value.copy(isSuccess = UiState.Failure(it.toString())) + _state.value = + _state.value.copy(isLogoutAndQuitSuccess = UiState.Failure(it.toString())) } } } @@ -65,7 +71,8 @@ class MyPageViewModel @Inject constructor( if (error == null) { deleteQuit() } else { - _state.value = _state.value.copy(isSuccess = UiState.Failure(error.toString())) + _state.value = + _state.value.copy(isLogoutAndQuitSuccess = UiState.Failure(error.toString())) } } } @@ -74,10 +81,26 @@ class MyPageViewModel @Inject constructor( viewModelScope.launch { myPageRepository.deleteQuit().onSuccess { tokenRepository.clearInfo() - _state.value = _state.value.copy(isSuccess = UiState.Success(true)) + _state.value = _state.value.copy(isLogoutAndQuitSuccess = UiState.Success(true)) + }.onFailure { + _state.value = + _state.value.copy(isLogoutAndQuitSuccess = UiState.Failure(it.toString())) + } + } + } + + private fun getProfile() { + viewModelScope.launch { + myPageRepository.getProfile().onSuccess { response -> + _state.value = _state.value.copy( + isGetSuccess = UiState.Success(true), + name = response.name, + authType = response.authType + ) }.onFailure { - _state.value = _state.value.copy(isSuccess = UiState.Failure(it.toString())) + _state.value = _state.value.copy(isGetSuccess = UiState.Failure(it.toString())) } } } + } \ No newline at end of file diff --git a/feature/src/main/java/com/terning/feature/onboarding/signin/SignInViewModel.kt b/feature/src/main/java/com/terning/feature/onboarding/signin/SignInViewModel.kt index e73645fcb..f35e2ed3e 100644 --- a/feature/src/main/java/com/terning/feature/onboarding/signin/SignInViewModel.kt +++ b/feature/src/main/java/com/terning/feature/onboarding/signin/SignInViewModel.kt @@ -1,6 +1,7 @@ package com.terning.feature.onboarding.signin import android.content.Context +import android.util.Log import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.kakao.sdk.auth.model.OAuthToken @@ -78,6 +79,7 @@ class SignInViewModel @Inject constructor( accessToken: String, authType: String = KAKAO, ) { + Log.d("LYB", accessToken) authRepository.postSignIn( accessToken, SignInRequestModel(authType = authType) From 118b69d4e5d705837dec997fd9200b83faecaf65 Mon Sep 17 00:00:00 2001 From: LEE YOU BIN Date: Thu, 18 Jul 2024 05:34:18 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[FEAT/#119]=20=EB=A1=9C=EA=B7=B8=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/terning/feature/onboarding/signin/SignInViewModel.kt | 2 -- 1 file changed, 2 deletions(-) diff --git a/feature/src/main/java/com/terning/feature/onboarding/signin/SignInViewModel.kt b/feature/src/main/java/com/terning/feature/onboarding/signin/SignInViewModel.kt index f35e2ed3e..e73645fcb 100644 --- a/feature/src/main/java/com/terning/feature/onboarding/signin/SignInViewModel.kt +++ b/feature/src/main/java/com/terning/feature/onboarding/signin/SignInViewModel.kt @@ -1,7 +1,6 @@ package com.terning.feature.onboarding.signin import android.content.Context -import android.util.Log import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.kakao.sdk.auth.model.OAuthToken @@ -79,7 +78,6 @@ class SignInViewModel @Inject constructor( accessToken: String, authType: String = KAKAO, ) { - Log.d("LYB", accessToken) authRepository.postSignIn( accessToken, SignInRequestModel(authType = authType)