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