-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: TestScreen의 동작을 MyPage로 옮김
- Loading branch information
1 parent
e21b8a0
commit 8928f59
Showing
15 changed files
with
169 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
domain/src/main/java/com/susu/domain/usecase/LogoutUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.susu.domain.usecase | ||
|
||
import com.susu.core.common.runCatchingIgnoreCancelled | ||
import com.susu.domain.repository.LoginRepository | ||
import com.susu.domain.repository.TokenRepository | ||
import javax.inject.Inject | ||
|
||
class LogoutUseCase @Inject constructor( | ||
private val loginRepository: LoginRepository, | ||
private val tokenRepository: TokenRepository, | ||
) { | ||
suspend operator fun invoke() = runCatchingIgnoreCancelled { | ||
loginRepository.logout() | ||
tokenRepository.deleteTokens() | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
domain/src/main/java/com/susu/domain/usecase/WithdrawUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.susu.domain.usecase | ||
|
||
import com.susu.core.common.runCatchingIgnoreCancelled | ||
import com.susu.domain.repository.LoginRepository | ||
import com.susu.domain.repository.TokenRepository | ||
import javax.inject.Inject | ||
|
||
class WithdrawUseCase @Inject constructor( | ||
private val loginRepository: LoginRepository, | ||
private val tokenRepository: TokenRepository, | ||
) { | ||
suspend operator fun invoke() = runCatchingIgnoreCancelled { | ||
loginRepository.withdraw() | ||
tokenRepository.deleteTokens() | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
feature/loginsignup/src/main/java/com/susu/feature/loginsignup/VoteScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.susu.feature.loginsignup | ||
|
||
import androidx.compose.material3.Button | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
|
||
@Composable | ||
fun VoteScreen( | ||
navigateToLogin: () -> Unit | ||
) { | ||
Button(onClick = navigateToLogin) { | ||
Text("대충 회원가입 투표") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 0 additions & 12 deletions
12
feature/loginsignup/src/main/java/com/susu/feature/loginsignup/test/TestContract.kt
This file was deleted.
Oops, something went wrong.
33 changes: 0 additions & 33 deletions
33
feature/loginsignup/src/main/java/com/susu/feature/loginsignup/test/TestScreen.kt
This file was deleted.
Oops, something went wrong.
38 changes: 0 additions & 38 deletions
38
feature/loginsignup/src/main/java/com/susu/feature/loginsignup/test/TestViewModel.kt
This file was deleted.
Oops, something went wrong.
13 changes: 13 additions & 0 deletions
13
feature/mypage/src/main/java/com/susu/feature/mypage/MyPageContract.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.susu.feature.mypage | ||
|
||
import com.susu.core.ui.base.SideEffect | ||
import com.susu.core.ui.base.UiState | ||
|
||
interface MyPageContract { | ||
sealed class MyPageEffect : SideEffect { | ||
data object NavigateToLogin : MyPageEffect() | ||
data class ShowToast(val msg: String) : MyPageEffect() | ||
} | ||
|
||
object MyPageState : UiState | ||
} |
34 changes: 29 additions & 5 deletions
34
feature/mypage/src/main/java/com/susu/feature/mypage/MyPageScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,52 @@ | ||
package com.susu.feature.mypage | ||
|
||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.PaddingValues | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material3.Button | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.dp | ||
import androidx.hilt.navigation.compose.hiltViewModel | ||
import com.susu.core.designsystem.theme.SusuTheme | ||
|
||
@Composable | ||
fun MyPageScreen( | ||
padding: PaddingValues, | ||
viewModel: MyPageViewModel = hiltViewModel(), | ||
navigateToLogin: () -> Unit, | ||
) { | ||
Text( | ||
modifier = Modifier.padding(padding), | ||
text = "마이 페이지", | ||
) | ||
LaunchedEffect(key1 = viewModel.sideEffect) { | ||
viewModel.sideEffect.collect { sideEffect -> | ||
when (sideEffect) { | ||
MyPageContract.MyPageEffect.NavigateToLogin -> navigateToLogin() | ||
is MyPageContract.MyPageEffect.ShowToast -> { | ||
//TODO: UI 작업 시 에러 메세지 표시 | ||
navigateToLogin() | ||
} | ||
} | ||
} | ||
} | ||
|
||
Column { | ||
Button(onClick = viewModel::logout) { | ||
Text(text = "로그아웃") | ||
} | ||
Button( | ||
onClick = viewModel::withdraw, | ||
) { | ||
Text(text = "탈퇴") | ||
} | ||
} | ||
} | ||
|
||
@Preview | ||
@Composable | ||
fun MyPageScreenPreview() { | ||
SusuTheme { | ||
MyPageScreen(padding = PaddingValues(0.dp)) | ||
MyPageScreen(padding = PaddingValues(0.dp)) {} | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
feature/mypage/src/main/java/com/susu/feature/mypage/MyPageViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.susu.feature.mypage | ||
|
||
import androidx.lifecycle.viewModelScope | ||
import com.kakao.sdk.user.UserApiClient | ||
import com.susu.core.ui.base.BaseViewModel | ||
import com.susu.domain.usecase.LogoutUseCase | ||
import com.susu.domain.usecase.WithdrawUseCase | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import kotlinx.coroutines.launch | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class MyPageViewModel @Inject constructor( | ||
private val logoutUseCase: LogoutUseCase, | ||
private val withdrawUseCase: WithdrawUseCase, | ||
) : BaseViewModel<MyPageContract.MyPageState, MyPageContract.MyPageEffect>(MyPageContract.MyPageState) { | ||
|
||
fun logout() { | ||
UserApiClient.instance.logout { error -> | ||
if (error != null) { | ||
postSideEffect(MyPageContract.MyPageEffect.ShowToast(error.message ?: "에러 발생했지만 토큰은 삭제됨")) | ||
} else { | ||
viewModelScope.launch { | ||
logoutUseCase().onSuccess { | ||
postSideEffect(MyPageContract.MyPageEffect.NavigateToLogin) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
fun withdraw() { | ||
UserApiClient.instance.unlink { error -> | ||
if (error != null) { | ||
postSideEffect(MyPageContract.MyPageEffect.ShowToast(error.message ?: "에러 발생했지만 토큰은 삭제됨")) | ||
} else { | ||
viewModelScope.launch { | ||
withdrawUseCase().onSuccess { | ||
postSideEffect(MyPageContract.MyPageEffect.NavigateToLogin) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.