Skip to content

Commit 7d91f86

Browse files
author
ny2060
committed
FEAT: 마이페이지 탈퇴하기 api 연동
1 parent 174d249 commit 7d91f86

File tree

10 files changed

+130
-19
lines changed

10 files changed

+130
-19
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.plottwist.core.data.auth.di
22

3-
import com.plottwist.core.domain.auth.repository.LoginRepository
4-
import com.plottwist.core.data.auth.repository.LoginRepositoryImpl
3+
import com.plottwist.core.domain.auth.repository.AuthRepository
4+
import com.plottwist.core.data.auth.repository.AuthRepositoryImpl
55
import dagger.Binds
66
import dagger.Module
77
import dagger.hilt.InstallIn
@@ -12,5 +12,5 @@ import dagger.hilt.components.SingletonComponent
1212
abstract class LoginDataModule {
1313

1414
@Binds
15-
abstract fun bindLoginRepository(impl: LoginRepositoryImpl): LoginRepository
15+
abstract fun bindLoginRepository(impl: AuthRepositoryImpl): AuthRepository
1616
}

core/data/src/main/java/com/plottwist/core/data/auth/repository/LoginRepositoryImpl.kt renamed to core/data/src/main/java/com/plottwist/core/data/auth/repository/AuthRepositoryImpl.kt

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.plottwist.core.data.auth.repository
22

33
import com.plottwist.core.data.common.DeviceInfoProvider
4-
import com.plottwist.core.domain.auth.repository.LoginRepository
4+
import com.plottwist.core.domain.auth.repository.AuthRepository
55
import com.plottwist.core.domain.push.repository.PushRepository
66
import com.plottwist.core.network.model.auth.DeviceInfo
77
import com.plottwist.core.network.model.auth.GoogleLoginRequest
@@ -14,12 +14,12 @@ import kotlinx.coroutines.flow.firstOrNull
1414
import javax.inject.Inject
1515

1616

17-
class LoginRepositoryImpl @Inject constructor(
18-
private val loginService: AuthApiService,
17+
class AuthRepositoryImpl @Inject constructor(
18+
private val authApiService: AuthApiService,
1919
private val authDataSource: AuthDataSource,
2020
private val deviceInfoProvider: DeviceInfoProvider,
2121
private val pushRepository: PushRepository
22-
) : LoginRepository {
22+
) : AuthRepository {
2323

2424
override suspend fun googleLogin(accountId: String): Result<Boolean> {
2525
return try {
@@ -37,7 +37,7 @@ class LoginRepositoryImpl @Inject constructor(
3737
deviceInfo = deviceInfo
3838
)
3939

40-
val response = loginService.googleLogin(request)
40+
val response = authApiService.googleLogin(request)
4141

4242
if (response.success) {
4343
val result = response.data
@@ -68,4 +68,19 @@ class LoginRepositoryImpl @Inject constructor(
6868
override fun logout(): Flow<Unit> {
6969
return authDataSource.clear()
7070
}
71+
72+
override suspend fun deleteAccount(): Result<Boolean> {
73+
return try {
74+
val response = authApiService.deleteMember()
75+
76+
if (response.success) {
77+
authDataSource.clear()
78+
Result.success(true)
79+
} else {
80+
Result.failure(Exception("Fail Delete member"))
81+
}
82+
} catch (e: Exception) {
83+
Result.failure(e)
84+
}
85+
}
7186
}

core/domain/src/main/java/com/plottwist/core/domain/auth/repository/LoginRepository.kt renamed to core/domain/src/main/java/com/plottwist/core/domain/auth/repository/AuthRepository.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ package com.plottwist.core.domain.auth.repository
22

33
import kotlinx.coroutines.flow.Flow
44

5-
interface LoginRepository {
5+
interface AuthRepository {
66
suspend fun googleLogin(accountId: String): Result<Boolean>
77
fun checkLoginStatus(): Flow<Boolean>
88
fun logout(): Flow<Unit>
9+
suspend fun deleteAccount(): Result<Boolean>
910
}

core/domain/src/main/java/com/plottwist/core/domain/auth/usecase/CheckLoginStatusUseCase.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package com.plottwist.core.domain.auth.usecase
22

3-
import com.plottwist.core.domain.auth.repository.LoginRepository
3+
import com.plottwist.core.domain.auth.repository.AuthRepository
44
import kotlinx.coroutines.flow.Flow
55
import javax.inject.Inject
66

77
class CheckLoginStatusUseCase @Inject constructor(
8-
private val loginRepository: LoginRepository
8+
private val loginRepository: AuthRepository
99
) {
1010
operator fun invoke(): Flow<Boolean> {
1111
return loginRepository.checkLoginStatus()
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.plottwist.core.domain.auth.usecase
2+
3+
import com.plottwist.core.domain.auth.repository.AuthRepository
4+
import kotlinx.coroutines.flow.first
5+
import javax.inject.Inject
6+
7+
class DeleteAccountUseCase @Inject constructor(
8+
private val authRepository: AuthRepository
9+
) {
10+
11+
suspend fun deleteAccount() {
12+
authRepository.deleteAccount()
13+
}
14+
}

core/domain/src/main/java/com/plottwist/core/domain/auth/usecase/LoginUseCase.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package com.plottwist.core.domain.auth.usecase
22

3-
import com.plottwist.core.domain.auth.repository.LoginRepository
3+
import com.plottwist.core.domain.auth.repository.AuthRepository
44
import javax.inject.Inject
55

66
class LoginUseCase @Inject constructor(
7-
private val loginRepository: LoginRepository
7+
private val loginRepository: AuthRepository
88
) {
99

1010
suspend fun loginWithGoogle(accountId: String): Result<Boolean> {

core/domain/src/main/java/com/plottwist/core/domain/auth/usecase/LogoutUseCase.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package com.plottwist.core.domain.auth.usecase
22

3-
import com.plottwist.core.domain.auth.repository.LoginRepository
3+
import com.plottwist.core.domain.auth.repository.AuthRepository
44
import kotlinx.coroutines.flow.first
55
import javax.inject.Inject
66

77
class LogoutUseCase @Inject constructor(
8-
private val loginRepository: LoginRepository
8+
private val loginRepository: AuthRepository
99
) {
1010

1111
suspend fun logoutWithGoogle() {

feature/mypage/src/main/java/com/plottwist/feature/mypage/MyPageContract.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ sealed class MyPageAction {
1313
data object ClickTerms : MyPageAction()
1414
data object ClickPrivacyPolicy : MyPageAction()
1515
data object ClickLogout : MyPageAction()
16+
data object ClickDeleteAccount : MyPageAction()
1617
}
1718

1819
sealed class MyPageSideEffect {

feature/mypage/src/main/java/com/plottwist/feature/mypage/MyPageScreen.kt

Lines changed: 77 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,15 @@ import androidx.compose.foundation.layout.padding
1515
import androidx.compose.foundation.layout.size
1616
import androidx.compose.foundation.layout.width
1717
import androidx.compose.foundation.lazy.LazyColumn
18+
import androidx.compose.material3.AlertDialog
1819
import androidx.compose.material3.Text
20+
import androidx.compose.material3.TextButton
1921
import androidx.compose.runtime.Composable
2022
import androidx.compose.runtime.collectAsState
2123
import androidx.compose.runtime.getValue
24+
import androidx.compose.runtime.mutableStateOf
25+
import androidx.compose.runtime.remember
26+
import androidx.compose.runtime.setValue
2227
import androidx.compose.ui.Alignment
2328
import androidx.compose.ui.Modifier
2429
import androidx.compose.ui.graphics.Color
@@ -28,6 +33,7 @@ import androidx.compose.ui.unit.dp
2833
import androidx.hilt.navigation.compose.hiltViewModel
2934
import com.plottwist.core.designsystem.component.TukTopAppBar
3035
import com.plottwist.core.designsystem.component.TukTopAppBarType
36+
import com.plottwist.core.designsystem.foundation.TukColorTokens.CoralRed500
3137
import com.plottwist.core.designsystem.foundation.type.TukPretendardTypography
3238
import org.orbitmvi.orbit.compose.collectSideEffect
3339

@@ -43,6 +49,9 @@ fun MyPageScreen(
4349

4450
val state by viewModel.container.stateFlow.collectAsState()
4551

52+
var showLogoutDialog by remember { mutableStateOf(false)}
53+
var showDeleteAccountDialog by remember { mutableStateOf(false) }
54+
4655
viewModel.collectSideEffect { sideEffect ->
4756
when (sideEffect) {
4857
MyPageSideEffect.NavigateToEditName -> {
@@ -77,10 +86,74 @@ fun MyPageScreen(
7786
onUpdateClick = { viewModel.onAction(MyPageAction.ClickUpdateApp) },
7887
onTermsClick = { viewModel.onAction(MyPageAction.ClickTerms) },
7988
onPrivacyPolicyClick = { viewModel.onAction(MyPageAction.ClickPrivacyPolicy) },
80-
onLogoutClick = { viewModel.onAction(MyPageAction.ClickLogout) },
89+
onLogoutClick = { showLogoutDialog = true },
90+
onDeleteAccountClick = { showDeleteAccountDialog = true },
8191
onBackClick = onBackClick
8292
)
8393

94+
if (showLogoutDialog) {
95+
AlertDialog(
96+
onDismissRequest = { showLogoutDialog = false },
97+
text = {
98+
Text(
99+
text = "정말 로그아웃 하시겠어요?",
100+
style = TukPretendardTypography.body14R
101+
)
102+
},
103+
confirmButton = {
104+
TextButton(
105+
onClick = {
106+
showLogoutDialog = false
107+
viewModel.onAction(MyPageAction.ClickLogout)
108+
}
109+
) {
110+
Text(
111+
text = "확인",
112+
style = TukPretendardTypography.body14M,
113+
color = CoralRed500
114+
)
115+
}
116+
},
117+
dismissButton = {
118+
TextButton(onClick = { showLogoutDialog = false }) {
119+
Text(text = "취소", style = TukPretendardTypography.body14M)
120+
}
121+
}
122+
)
123+
}
124+
125+
// 탈퇴 다이얼로그
126+
if (showDeleteAccountDialog) {
127+
AlertDialog(
128+
onDismissRequest = { showDeleteAccountDialog = false },
129+
text = {
130+
Text(
131+
text = "정말 탈퇴하시겠어요? 탈퇴 후 데이터는 복구할 수 없습니다.",
132+
style = TukPretendardTypography.body14R
133+
)
134+
},
135+
confirmButton = {
136+
TextButton(
137+
onClick = {
138+
showDeleteAccountDialog = false
139+
viewModel.onAction(MyPageAction.ClickDeleteAccount)
140+
}
141+
) {
142+
Text(
143+
text = "확인",
144+
style = TukPretendardTypography.body14M,
145+
color = CoralRed500
146+
)
147+
}
148+
},
149+
dismissButton = {
150+
TextButton(onClick = { showDeleteAccountDialog = false }) {
151+
Text(text = "취소", style = TukPretendardTypography.body14M)
152+
}
153+
}
154+
)
155+
}
156+
84157
}
85158

86159
@Composable
@@ -91,6 +164,7 @@ fun MyPageContent(
91164
onTermsClick: () -> Unit,
92165
onPrivacyPolicyClick: () -> Unit,
93166
onLogoutClick: () -> Unit,
167+
onDeleteAccountClick: () -> Unit,
94168
onBackClick: () -> Unit
95169
) {
96170

@@ -178,7 +252,7 @@ fun MyPageContent(
178252
modifier = Modifier
179253
.align(Alignment.BottomCenter)
180254
.padding(bottom = 16.dp)
181-
.clickable { }
255+
.clickable {onDeleteAccountClick()}
182256
)
183257
}
184258

@@ -227,6 +301,6 @@ fun MyPageItem(
227301
@Preview(showBackground = true)
228302
fun PreviewMyPage(
229303
) {
230-
MyPageContent({}, {}, {}, {}, {}, {}, {})
304+
MyPageContent({}, {}, {}, {}, {}, {}, {},{})
231305
}
232306

feature/mypage/src/main/java/com/plottwist/feature/mypage/MyPageViewModel.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.plottwist.feature.mypage
22

33
import androidx.lifecycle.ViewModel
4+
import com.plottwist.core.domain.auth.usecase.DeleteAccountUseCase
45
import com.plottwist.core.domain.auth.usecase.LogoutUseCase
56
import dagger.hilt.android.lifecycle.HiltViewModel
67
import org.orbitmvi.orbit.ContainerHost
@@ -9,7 +10,8 @@ import javax.inject.Inject
910

1011
@HiltViewModel
1112
class MyPageViewModel @Inject constructor(
12-
private val logoutUseCase: LogoutUseCase
13+
private val logoutUseCase: LogoutUseCase,
14+
private val deleteAccountUseCase: DeleteAccountUseCase
1315
) :ContainerHost<MyPageState, MyPageSideEffect>,ViewModel(){
1416

1517
override val container = container<MyPageState, MyPageSideEffect>(
@@ -27,6 +29,10 @@ class MyPageViewModel @Inject constructor(
2729
logoutUseCase.logoutWithGoogle()
2830
postSideEffect(MyPageSideEffect.NavigateToHome)
2931
}
32+
MyPageAction.ClickDeleteAccount -> {
33+
deleteAccountUseCase.deleteAccount()
34+
postSideEffect(MyPageSideEffect.NavigateToHome)
35+
}
3036
}
3137
}
3238
}

0 commit comments

Comments
 (0)