Skip to content

Commit 34e537f

Browse files
authored
[PC-1642] Profile 수정, 로그아웃, 탈퇴, 토큰 만료 시 로컬 MyProfile 데이터 clear 로직 추가 (#205)
* [PC-1642] MyProfile 수정, 로그아웃, 탈퇴, 토큰 만료 시 로컬 MyProfile 데이터 제거 * [PC-1642] ci 빌드 실패 수정 * [PC-1642] ci 빌드 실패 수정 * [PC-1644] fcm 알림 채널 변경 및 중요도 변경 (#206) * [PC-1642] 불필요한 join 처리 제거 * [PC-1642] MyProfile 수정, 로그아웃, 탈퇴, 토큰 만료 시 로컬 MyProfile 데이터 제거 * [PC-1642] ci 빌드 실패 수정 * [PC-1642] ci 빌드 실패 수정 * [PC-1642] 불필요한 join 처리 제거 * [PC-1642] 토큰 만료 처리 및 세션 만료 로직 일원화
1 parent 2f85f23 commit 34e537f

File tree

6 files changed

+36
-26
lines changed

6 files changed

+36
-26
lines changed

core/data/src/main/java/com/puzzle/data/repository/AuthRepositoryImpl.kt

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.puzzle.data.repository
22

3+
import com.puzzle.datastore.datasource.profile.LocalProfileDataSource
34
import com.puzzle.datastore.datasource.token.LocalTokenDataSource
45
import com.puzzle.datastore.datasource.user.LocalUserDataSource
56
import com.puzzle.domain.model.auth.OAuthProvider
@@ -17,6 +18,7 @@ class AuthRepositoryImpl @Inject constructor(
1718
private val notificationDataSource: NotificationDataSource,
1819
private val localTokenDataSource: LocalTokenDataSource,
1920
private val localUserDataSource: LocalUserDataSource,
21+
private val localProfileDataSource: LocalProfileDataSource,
2022
) : AuthRepository {
2123
override suspend fun loginOauth(
2224
oAuthProvider: OAuthProvider,
@@ -46,27 +48,21 @@ class AuthRepositoryImpl @Inject constructor(
4648

4749
override suspend fun logout() {
4850
coroutineScope {
49-
val clearUserRoleJob = launch { localUserDataSource.clearUserRole() }
50-
val clearLastMatchingPoolEmptyDialogShownDateJob = launch { localUserDataSource.clearLastMatchingPoolEmptyDialogShownDate() }
51-
val clearTokenJob = launch { localTokenDataSource.clearToken() }
52-
53-
clearTokenJob.join()
54-
clearLastMatchingPoolEmptyDialogShownDateJob.join()
55-
clearUserRoleJob.join()
51+
launch { localUserDataSource.clearUserRole() }
52+
launch { localUserDataSource.clearLastMatchingPoolEmptyDialogShownDate() }
53+
launch { localTokenDataSource.clearToken() }
54+
launch { localProfileDataSource.clearMyProfile() }
5655
}
5756
}
5857

5958
override suspend fun withdraw(reason: String) {
6059
authDataSource.withdraw(reason)
6160

6261
coroutineScope {
63-
val clearUserRoleJob = launch { localUserDataSource.clearUserRole() }
64-
val clearLastMatchingPoolEmptyDialogShownDateJob = launch { localUserDataSource.clearLastMatchingPoolEmptyDialogShownDate() }
65-
val clearTokenJob = launch { localTokenDataSource.clearToken() }
66-
67-
clearTokenJob.join()
68-
clearLastMatchingPoolEmptyDialogShownDateJob.join()
69-
clearUserRoleJob.join()
62+
launch { localUserDataSource.clearUserRole() }
63+
launch { localUserDataSource.clearLastMatchingPoolEmptyDialogShownDate() }
64+
launch { localTokenDataSource.clearToken() }
65+
launch { localProfileDataSource.clearMyProfile() }
7066
}
7167
}
7268

core/data/src/main/java/com/puzzle/data/repository/ProfileRepositoryImpl.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,10 @@ class ProfileRepositoryImpl @Inject constructor(
252252
)
253253
}
254254

255+
override suspend fun clearMyProfile() {
256+
localProfileDataSource.clearMyProfile()
257+
}
258+
255259
override suspend fun connectSSE() = sseClient.connect()
256260
override suspend fun disconnectSSE() {
257261
profileDataSource.disconnectSSE()

core/data/src/test/java/com/puzzle/data/repository/AuthRepositoryImplTest.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.puzzle.data.repository
22

33
import com.puzzle.data.source.auth.FakeAuthDataSource
44
import com.puzzle.data.source.notification.SpyNotificationDataSource
5+
import com.puzzle.data.source.profile.FakeLocalProfileDataSource
56
import com.puzzle.data.source.token.FakeLocalTokenDataSource
67
import com.puzzle.data.source.user.FakeLocalUserDataSource
78
import com.puzzle.domain.model.auth.OAuthProvider
@@ -17,6 +18,8 @@ class AuthRepositoryImplTest {
1718
private lateinit var notificationDataSource: SpyNotificationDataSource
1819
private lateinit var localTokenDataSource: FakeLocalTokenDataSource
1920
private lateinit var localUserDataSource: FakeLocalUserDataSource
21+
private lateinit var localProfileDataSource: FakeLocalProfileDataSource
22+
2023
private lateinit var authRepository: AuthRepositoryImpl
2124

2225
@BeforeEach
@@ -25,11 +28,13 @@ class AuthRepositoryImplTest {
2528
notificationDataSource = SpyNotificationDataSource()
2629
localTokenDataSource = FakeLocalTokenDataSource()
2730
localUserDataSource = FakeLocalUserDataSource()
31+
localProfileDataSource = FakeLocalProfileDataSource()
2832
authRepository = AuthRepositoryImpl(
2933
authDataSource = authDataSource,
3034
notificationDataSource = notificationDataSource,
3135
localTokenDataSource = localTokenDataSource,
3236
localUserDataSource = localUserDataSource,
37+
localProfileDataSource = localProfileDataSource
3338
)
3439
}
3540

@@ -68,6 +73,7 @@ class AuthRepositoryImplTest {
6873
assertTrue(localTokenDataSource.refreshToken.first().isEmpty())
6974
assertTrue(localUserDataSource.userRole.first().isEmpty())
7075
assertTrue(localUserDataSource.lastMatchingPoolEmptyDialogShownDate.first().isEmpty())
76+
assertTrue(localProfileDataSource.myValueTalks.first().isNullOrEmpty())
7177
}
7278

7379
@Test
@@ -83,5 +89,6 @@ class AuthRepositoryImplTest {
8389
assertTrue(localTokenDataSource.refreshToken.first().isEmpty())
8490
assertTrue(localUserDataSource.userRole.first().isEmpty())
8591
assertTrue(localUserDataSource.lastMatchingPoolEmptyDialogShownDate.first().isEmpty())
92+
assertTrue(localProfileDataSource.myValueTalks.first().isNullOrEmpty())
8693
}
8794
}

core/domain/src/main/java/com/puzzle/domain/repository/ProfileRepository.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ interface ProfileRepository {
7272
valueTalks: List<ValueTalkAnswer>
7373
)
7474

75+
suspend fun clearMyProfile()
76+
7577
suspend fun connectSSE()
7678
suspend fun disconnectSSE()
7779
}

feature/profile/src/main/java/com/puzzle/profile/graph/register/RegisterProfileViewModel.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ class RegisterProfileViewModel @Inject constructor(
292292
},
293293
)
294294
}.onSuccess {
295+
profileRepository.clearMyProfile()
295296
loadMyProfile()
296297
setState { copy(currentPage = RegisterProfileState.Page.COMPLETE) }
297298
}.onFailure { exception ->
@@ -336,6 +337,7 @@ class RegisterProfileViewModel @Inject constructor(
336337
},
337338
)
338339
}.onSuccess {
340+
profileRepository.clearMyProfile()
339341
loadMyProfile()
340342
setState { copy(currentPage = RegisterProfileState.Page.COMPLETE) }
341343
}.onFailure { exception ->

presentation/src/main/java/com/puzzle/presentation/MainViewModel.kt

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import com.puzzle.navigation.AuthGraphBaseRoute
2525
import com.puzzle.navigation.MatchingGraph
2626
import com.puzzle.navigation.NavigationEvent.TopLevelTo
2727
import com.puzzle.navigation.NavigationHelper
28-
import com.puzzle.navigation.OnboardingRoute
2928
import dagger.hilt.android.lifecycle.HiltViewModel
3029
import kotlinx.coroutines.coroutineScope
3130
import kotlinx.coroutines.flow.MutableStateFlow
@@ -79,15 +78,7 @@ class MainViewModel @Inject constructor(
7978

8079
private fun handleHttpError(exception: HttpResponseException) {
8180
when (exception.errorCode) {
82-
PieceErrorCode.EXPIRED_REFRESH_TOKEN -> {
83-
viewModelScope.launch {
84-
userRepository.clearLastMatchingPoolEmptyDialogShownDate()
85-
86-
navigationHelper.navigate(
87-
TopLevelTo(AuthGraphBaseRoute)
88-
)
89-
}
90-
}
81+
PieceErrorCode.EXPIRED_REFRESH_TOKEN -> clearAndNavigateToAuth()
9182

9283
PieceErrorCode.PERMANENTLY_BANNED -> eventHelper.sendEvent(PieceEvent.ShowBannedDialog)
9384

@@ -144,8 +135,7 @@ class MainViewModel @Inject constructor(
144135
(exception is IllegalArgumentException ||
145136
(exception is HttpResponseException && exception.status == HttpResponseStatus.Unauthorized)
146137
) -> {
147-
userRepository.clearLastMatchingPoolEmptyDialogShownDate()
148-
navigationHelper.navigate(TopLevelTo(route = OnboardingRoute))
138+
clearAndNavigateToAuth()
149139
return
150140
}
151141

@@ -172,4 +162,13 @@ class MainViewModel @Inject constructor(
172162
notificationRepository.readNotification(notificationId)
173163
}.onFailure { errorHelper.sendError(it) }
174164
}
165+
166+
private fun clearAndNavigateToAuth() = viewModelScope.launch {
167+
suspendRunCatching {
168+
userRepository.clearLastMatchingPoolEmptyDialogShownDate()
169+
profileRepository.clearMyProfile()
170+
}.onFailure { errorHelper.recordError(it) }
171+
172+
navigationHelper.navigate(TopLevelTo(AuthGraphBaseRoute))
173+
}
175174
}

0 commit comments

Comments
 (0)