-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: 카카오 로그인 관련 로직 DataSource 리팩터링 #931
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
922b1bb
chore: kakao login repository 패키지 분리
kimhm0728 cad27a6
refactor: token repository를 local data source로 이동
kimhm0728 504d229
refactor: RemoteAuthDataSource로 로직 이동
kimhm0728 fa0813e
refactor: LoginRepository를 data source 사용으로 변경
kimhm0728 3694192
style: ktLint 적용
kimhm0728 2eaab14
fix: repository 참조 오류 수정
kimhm0728 f51be6e
feat: data source 의존성 모듈 작성
kimhm0728 57395de
chore: LoginRepository -> AuthRepository 이름 변경
kimhm0728 a99f45a
chore: auth 패키지 구조 변경
kimhm0728 7dd1232
chore: checkIf로 시작하는 모호한 함수명 변경
kimhm0728 dbadd47
refactor: 사용하지 않는 repository 제거
kimhm0728 2205bef
chore: default data source -> kakao 로 네이밍 변경
kimhm0728 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
android/app/src/main/java/com/mulberry/ody/data/auth/repository/KakaoAuthRepository.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.mulberry.ody.data.auth.repository | ||
|
||
import android.content.Context | ||
import com.mulberry.ody.data.auth.source.local.LocalAuthDataSource | ||
import com.mulberry.ody.data.auth.source.remote.RemoteAuthDataSource | ||
import com.mulberry.ody.domain.apiresult.ApiResult | ||
import com.mulberry.ody.domain.apiresult.getOrNull | ||
import com.mulberry.ody.domain.apiresult.suspendOnSuccess | ||
import com.mulberry.ody.domain.model.AuthToken | ||
import com.mulberry.ody.domain.repository.ody.AuthRepository | ||
import javax.inject.Inject | ||
|
||
class KakaoAuthRepository | ||
@Inject | ||
constructor( | ||
private val localAuthDataSource: LocalAuthDataSource, | ||
private val remoteAuthDataSource: RemoteAuthDataSource, | ||
) : AuthRepository { | ||
override suspend fun isLoggedIn(): Boolean { | ||
if (!remoteAuthDataSource.isLoggedIn() || !localAuthDataSource.isLoggedIn()) { | ||
return false | ||
} | ||
val authToken = remoteAuthDataSource.postAuthToken().getOrNull() ?: return false | ||
localAuthDataSource.postAuthToken(authToken) | ||
return true | ||
} | ||
|
||
override suspend fun login(context: Context): ApiResult<AuthToken> { | ||
val fcmToken = localAuthDataSource.fetchFCMToken().getOrNull() ?: return ApiResult.Unexpected(Exception("FCM 토큰이 존재하지 않습니다.")) | ||
return remoteAuthDataSource.login(fcmToken, context).suspendOnSuccess { | ||
localAuthDataSource.postAuthToken(it) | ||
} | ||
} | ||
|
||
override suspend fun logout(): ApiResult<Unit> { | ||
localAuthDataSource.removeAuthToken() | ||
return remoteAuthDataSource.logout() | ||
} | ||
|
||
override suspend fun withdrawAccount(): ApiResult<Unit> { | ||
return remoteAuthDataSource.withdraw().suspendOnSuccess { | ||
localAuthDataSource.removeAuthToken() | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...oid/app/src/main/java/com/mulberry/ody/data/auth/source/local/KakaoLocalAuthDataSource.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,30 @@ | ||
package com.mulberry.ody.data.auth.source.local | ||
|
||
import com.mulberry.ody.data.local.db.OdyDatastore | ||
import com.mulberry.ody.domain.model.AuthToken | ||
import kotlinx.coroutines.flow.first | ||
import javax.inject.Inject | ||
|
||
class KakaoLocalAuthDataSource | ||
@Inject | ||
constructor( | ||
private val odyDatastore: OdyDatastore, | ||
) : LocalAuthDataSource { | ||
override suspend fun isLoggedIn(): Boolean { | ||
return odyDatastore.getAuthToken().first().isSuccess | ||
} | ||
|
||
override suspend fun removeAuthToken() { | ||
odyDatastore.removeAuthToken() | ||
} | ||
|
||
override suspend fun postAuthToken(authToken: AuthToken) { | ||
odyDatastore.setAuthToken(authToken) | ||
} | ||
|
||
override suspend fun fetchFCMToken(): Result<String> { | ||
return odyDatastore.getFCMToken().first() | ||
} | ||
|
||
override suspend fun postFCMToken(fcmToken: String) = odyDatastore.setFCMToken(fcmToken) | ||
} |
15 changes: 15 additions & 0 deletions
15
android/app/src/main/java/com/mulberry/ody/data/auth/source/local/LocalAuthDataSource.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,15 @@ | ||
package com.mulberry.ody.data.auth.source.local | ||
|
||
import com.mulberry.ody.domain.model.AuthToken | ||
|
||
interface LocalAuthDataSource { | ||
suspend fun isLoggedIn(): Boolean | ||
|
||
suspend fun removeAuthToken() | ||
|
||
suspend fun postAuthToken(authToken: AuthToken) | ||
|
||
suspend fun fetchFCMToken(): Result<String> | ||
|
||
suspend fun postFCMToken(fcmToken: String) | ||
} |
59 changes: 59 additions & 0 deletions
59
...d/app/src/main/java/com/mulberry/ody/data/auth/source/remote/KakaoRemoteAuthDataSource.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,59 @@ | ||
package com.mulberry.ody.data.auth.source.remote | ||
|
||
import android.content.Context | ||
import com.mulberry.ody.data.remote.core.entity.login.mapper.toAuthToken | ||
import com.mulberry.ody.data.remote.core.entity.login.request.LoginRequest | ||
import com.mulberry.ody.data.remote.core.service.AuthService | ||
import com.mulberry.ody.data.remote.core.service.RefreshTokenService | ||
import com.mulberry.ody.data.remote.thirdparty.login.kakao.KakaoOAuthLoginService | ||
import com.mulberry.ody.domain.apiresult.ApiResult | ||
import com.mulberry.ody.domain.apiresult.flatMap | ||
import com.mulberry.ody.domain.apiresult.map | ||
import com.mulberry.ody.domain.apiresult.toApiResult | ||
import com.mulberry.ody.domain.model.AuthToken | ||
import javax.inject.Inject | ||
|
||
class KakaoRemoteAuthDataSource | ||
@Inject | ||
constructor( | ||
private val authService: AuthService, | ||
private val refreshTokenService: RefreshTokenService, | ||
private val kakaoOAuthLoginService: KakaoOAuthLoginService, | ||
) : RemoteAuthDataSource { | ||
override suspend fun isLoggedIn(): Boolean { | ||
return kakaoOAuthLoginService.isLoggedIn() | ||
} | ||
|
||
override suspend fun postAuthToken(): ApiResult<AuthToken> { | ||
return refreshTokenService.postRefreshToken().map { it.toAuthToken() } | ||
} | ||
|
||
override suspend fun login( | ||
fcmToken: String, | ||
context: Context, | ||
): ApiResult<AuthToken> { | ||
val loginResult = | ||
kakaoOAuthLoginService.login(context).toApiResult() | ||
.map { LoginRequest(fcmToken, it.providerId, it.nickname, it.imageUrl) } | ||
|
||
return loginResult.flatMap { loginRequest -> | ||
authService.postLoginWithKakao(loginRequest).map { it.toAuthToken() } | ||
} | ||
} | ||
|
||
override suspend fun logout(): ApiResult<Unit> { | ||
val kakaoLogoutResult = kakaoOAuthLoginService.logout() | ||
val odyLogoutResult = authService.postLogout() | ||
|
||
val exception = kakaoLogoutResult.exceptionOrNull() | ||
if (exception != null) { | ||
return ApiResult.Unexpected(exception) | ||
} | ||
|
||
return odyLogoutResult | ||
} | ||
|
||
override suspend fun withdraw(): ApiResult<Unit> { | ||
return authService.deleteMember() | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
android/app/src/main/java/com/mulberry/ody/data/auth/source/remote/RemoteAuthDataSource.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,20 @@ | ||
package com.mulberry.ody.data.auth.source.remote | ||
|
||
import android.content.Context | ||
import com.mulberry.ody.domain.apiresult.ApiResult | ||
import com.mulberry.ody.domain.model.AuthToken | ||
|
||
interface RemoteAuthDataSource { | ||
suspend fun isLoggedIn(): Boolean | ||
|
||
suspend fun postAuthToken(): ApiResult<AuthToken> | ||
|
||
suspend fun login( | ||
fcmToken: String, | ||
context: Context, | ||
): ApiResult<AuthToken> | ||
|
||
suspend fun logout(): ApiResult<Unit> | ||
|
||
suspend fun withdraw(): ApiResult<Unit> | ||
} |
25 changes: 0 additions & 25 deletions
25
...id/app/src/main/java/com/mulberry/ody/data/local/repository/DefaultAuthTokenRepository.kt
This file was deleted.
Oops, something went wrong.
18 changes: 0 additions & 18 deletions
18
...p/src/main/java/com/mulberry/ody/data/remote/core/repository/DefaultFCMTokenRepository.kt
This file was deleted.
Oops, something went wrong.
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
9 changes: 0 additions & 9 deletions
9
android/app/src/main/java/com/mulberry/ody/data/remote/core/service/LogoutService.kt
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
android/app/src/main/java/com/mulberry/ody/data/remote/core/service/MemberService.kt
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -2,8 +2,8 @@ package com.mulberry.ody.data.remote.thirdparty.fcm.service | |
|
||
import com.google.firebase.messaging.FirebaseMessagingService | ||
import com.google.firebase.messaging.RemoteMessage | ||
import com.mulberry.ody.data.local.db.OdyDatastore | ||
import com.mulberry.ody.domain.model.NotificationType | ||
import com.mulberry.ody.domain.repository.ody.FCMTokenRepository | ||
import com.mulberry.ody.presentation.notification.FCMNotification | ||
import dagger.hilt.android.AndroidEntryPoint | ||
import kotlinx.coroutines.runBlocking | ||
|
@@ -12,7 +12,7 @@ import javax.inject.Inject | |
@AndroidEntryPoint | ||
class FCMService : FirebaseMessagingService() { | ||
@Inject | ||
lateinit var fcmTokenRepository: FCMTokenRepository | ||
lateinit var odyDatastore: OdyDatastore | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 자연스러워졌네요! |
||
|
||
@Inject | ||
lateinit var fcmNotification: FCMNotification | ||
|
@@ -28,7 +28,7 @@ class FCMService : FirebaseMessagingService() { | |
|
||
override fun onNewToken(token: String) { | ||
runBlocking { | ||
fcmTokenRepository.postFCMToken(token) | ||
odyDatastore.setFCMToken(token) | ||
} | ||
} | ||
} |
100 changes: 0 additions & 100 deletions
100
...src/main/java/com/mulberry/ody/data/remote/thirdparty/login/kakao/KakaoLoginRepository.kt
This file was deleted.
Oops, something went wrong.
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
너무 좋다고 생각합니다.