Skip to content

Commit

Permalink
Fix to cache member id.
Browse files Browse the repository at this point in the history
  • Loading branch information
bywindow committed Aug 17, 2024
1 parent f677727 commit 9ec5399
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ interface DefaultDataSource {
fun clearUserData() : Flow<Unit>
fun setUserProfile(data: UserProfile) : Flow<Unit>
fun getUserProfile() : Flow<UserProfile?>
fun setMemberId(data: Long) : Flow<Unit>
fun getMemberId() : Flow<Long?>
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class DefaultDataSourceImpl @Inject constructor(
object PreferencesKey {
val USER_NICKNAME = stringPreferencesKey("USER_NICKNAME")
val USER_CHARACTER = stringPreferencesKey("USER_CHARACTER")
val MEMBER_ID = stringPreferencesKey("MEMBER_ID")
}

override fun clearUserData(): Flow<Unit> = flow {
Expand All @@ -44,4 +45,15 @@ class DefaultDataSourceImpl @Inject constructor(
null
}
}

override fun setMemberId(data: Long): Flow<Unit> = flow {
dataStore.edit { preferences ->
preferences[PreferencesKey.MEMBER_ID] = data.toString()
}
emit(Unit)
}

override fun getMemberId(): Flow<Long?> = dataStore.data.map { preferences ->
preferences[PreferencesKey.MEMBER_ID]?.toLong()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class LoginUseCase @Inject constructor(
response.data.also {
authDataSource.setAccessToken(it.accessToken).first()
authDataSource.setRefreshToken(it.refreshToken).first()
defaultDataSource.setMemberId(it.memberId).first()
(it.nickname to it.characterType).let { (nickname, character) ->
if (nickname != null && character != null) {
defaultDataSource.setUserProfile(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ data class GoogleLogin(
val refreshToken: String,
val nickname: String?,
val characterType: CharacterType?,
val isProfileSet: Boolean
val isProfileSet: Boolean,
val memberId: Long
)
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ class ProfileViewModel @AssistedInject constructor(

when(val response = profileUseCase.saveProfile(nickname, selectedItem.type)) {
is NetworkResult.Success -> {
profileUseCase.saveProfile(nickname, selectedItem.type)
_isSaveSuccess.emit(true)
}
is NetworkResult.Exception -> {}
Expand Down

0 comments on commit 9ec5399

Please sign in to comment.