Skip to content

Commit

Permalink
Merge pull request #37 from Nexters/feature/fix-user-cache
Browse files Browse the repository at this point in the history
Fix to cache member id.
  • Loading branch information
eshc123 authored Aug 17, 2024
2 parents 52351c2 + 61c4fb0 commit e391475
Show file tree
Hide file tree
Showing 5 changed files with 18 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 @@ -3,6 +3,7 @@ package com.goalpanzi.mission_mate.core.datastore.datasource
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.core.edit
import androidx.datastore.preferences.core.longPreferencesKey
import androidx.datastore.preferences.core.stringPreferencesKey
import com.luckyoct.core.model.CharacterType
import com.luckyoct.core.model.UserProfile
Expand All @@ -18,6 +19,7 @@ class DefaultDataSourceImpl @Inject constructor(
object PreferencesKey {
val USER_NICKNAME = stringPreferencesKey("USER_NICKNAME")
val USER_CHARACTER = stringPreferencesKey("USER_CHARACTER")
val MEMBER_ID = longPreferencesKey("MEMBER_ID")
}

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

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

override fun getMemberId(): Flow<Long?> = dataStore.data.map { preferences ->
preferences[PreferencesKey.MEMBER_ID]
}
}
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 e391475

Please sign in to comment.