-
Notifications
You must be signed in to change notification settings - Fork 0
refactor: 회원가입 로직 수정 #691
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
Merged
refactor: 회원가입 로직 수정 #691
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
42 changes: 3 additions & 39 deletions
42
app/src/main/java/com/into/websoso/data/repository/AuthRepository.kt
This file contains hidden or 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,75 +1,39 @@ | ||
| package com.into.websoso.data.repository | ||
|
|
||
| import android.content.SharedPreferences | ||
| import com.into.websoso.data.remote.api.AuthApi | ||
| import com.into.websoso.data.remote.request.FCMTokenRequestDto | ||
| import com.into.websoso.data.remote.request.UserProfileRequestDto | ||
| import javax.inject.Inject | ||
| import javax.inject.Singleton | ||
|
|
||
| @Singleton | ||
| class AuthRepository | ||
| @Inject | ||
| constructor( | ||
| private val authApi: AuthApi, | ||
| private val authStorage: SharedPreferences, | ||
| ) { | ||
| var accessToken: String | ||
| get() = authStorage.getString(ACCESS_TOKEN_KEY, "").orEmpty() | ||
| private set(value) = authStorage.edit().putString(ACCESS_TOKEN_KEY, value).apply() | ||
|
|
||
| var refreshToken: String | ||
| get() = authStorage.getString(REFRESH_TOKEN_KEY, "").orEmpty() | ||
| private set(value) = authStorage.edit().putString(REFRESH_TOKEN_KEY, value).apply() | ||
|
|
||
| var isAutoLogin: Boolean | ||
| get() = authStorage.getBoolean(AUTO_LOGIN_KEY, false) | ||
| private set(value) = authStorage.edit().putBoolean(AUTO_LOGIN_KEY, value).apply() | ||
|
|
||
| suspend fun fetchNicknameValidity( | ||
| authorization: String, | ||
| nickname: String, | ||
| ): Boolean = authApi.getNicknameValidity("Bearer $authorization", nickname).isValid | ||
| suspend fun fetchNicknameValidity(nickname: String): Boolean = authApi.getNicknameValidity(nickname).isValid | ||
|
|
||
| suspend fun signUp( | ||
| authorization: String, | ||
| nickname: String, | ||
| gender: String, | ||
| birth: Int, | ||
| genrePreferences: List<String>, | ||
| ) { | ||
| authApi.postUserProfile( | ||
| "Bearer $authorization", | ||
| UserProfileRequestDto(nickname, gender, birth, genrePreferences), | ||
| ) | ||
| } | ||
|
|
||
| fun updateAccessToken(accessToken: String) { | ||
| this.accessToken = accessToken | ||
| } | ||
|
|
||
| fun updateRefreshToken(refreshToken: String) { | ||
| this.refreshToken = refreshToken | ||
| } | ||
|
|
||
| fun updateIsAutoLogin(isAutoLogin: Boolean) { | ||
| this.isAutoLogin = isAutoLogin | ||
| } | ||
|
|
||
| suspend fun saveFCMToken( | ||
| fcmToken: String, | ||
| deviceIdentifier: String, | ||
| ) { | ||
| authApi.postFCMToken( | ||
| authorization = "Bearer $accessToken", | ||
| FCMTokenRequestDto( | ||
| fcmToken = fcmToken, | ||
| deviceIdentifier = deviceIdentifier, | ||
| ), | ||
| ) | ||
| } | ||
|
|
||
| companion object { | ||
| private const val ACCESS_TOKEN_KEY = "ACCESS_TOKEN" | ||
| private const val REFRESH_TOKEN_KEY = "REFRESH_TOKEN" | ||
| private const val AUTO_LOGIN_KEY = "AUTO_LOGIN" | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
7 changes: 4 additions & 3 deletions
7
core/common/src/main/java/com/into/websoso/core/common/navigator/NavigatorProvider.kt
This file contains hidden or 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 hidden or 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
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.
🛠️ Refactor suggestion
네트워크 호출은 IO 디스패처에서 수행하도록 분리하세요
viewModelScope.launch의 기본 디스패처는Dispatchers.Main이기 때문에 현재 코드에서는 메인 스레드에서 API 호출이 실행될 수 있습니다. 레트로핏이 자체적으로 스레드 전환을 하도록 설정돼 있지 않다면 ANR 및 UI 지연이 발생할 여지가 있습니다.아래와 같이
withContext(Dispatchers.IO)로 IO 스레드에서 실행되게 하시는 것을 권장드립니다.viewModelScope.launch { - runCatching { - authRepository.fetchNicknameValidity(nickname) - }.onSuccess { isNicknameValid -> + runCatching { + withContext(Dispatchers.IO) { + authRepository.fetchNicknameValidity(nickname) + } + }.onSuccess { isNicknameValid ->추가로,
withContext사용 시 다음 import 가 필요합니다.🤖 Prompt for AI Agents