Skip to content

Commit

Permalink
MOD/#19: 사용자저장소 관련 코드 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
boiledEgg-s committed Jun 7, 2024
1 parent fb985fd commit 812a7db
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,7 @@ class SoptAppContainer(context: Context): AppContainer {
}

private val okHttpClientWithInterceptor: OkHttpClient.Builder by lazy {
val memberId = context
.getSharedPreferences(PREFERENCE_ID, Context.MODE_PRIVATE)
.getString(USER_ID_KEY, "")
.orEmpty()
val memberId = userRepository.getUserId()

OkHttpClient.Builder().apply {
addInterceptor(Interceptor { chain ->
Expand All @@ -78,7 +75,5 @@ class SoptAppContainer(context: Context): AppContainer {
companion object{
const val BASE_URL = BuildConfig.AUTH_BASE_URL
const val PREFERENCE_ID = "SOPT"

private const val TAG = "SoptAppContainer"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import com.sopt.now.compose.models.User
class UserRepositoryImpl(
private val sharedPreferences: SharedPreferences
) : UserRepository {
override suspend fun getUserProfile(): User {
override fun getUserProfile(): User {
sharedPreferences.run {
val id = getString(ID_KEY, "") ?: ""
val pw = getString(PW_KEY, "") ?: ""
Expand All @@ -17,7 +17,7 @@ class UserRepositoryImpl(
}
}

override suspend fun setUserProfile(user: User) {
override fun setUserProfile(user: User) {
val edit = sharedPreferences.edit()
edit.run {
putString(ID_KEY, user.id)
Expand All @@ -28,11 +28,11 @@ class UserRepositoryImpl(
}
}

override suspend fun getUserId(): String {
override fun getUserId(): String {
return sharedPreferences.getString(USER_ID_KEY, "").orEmpty()
}

override suspend fun setUserId(userId: String) {
override fun setUserId(userId: String) {
val edit = sharedPreferences.edit()
edit.putString(USER_ID_KEY, userId).apply()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import android.util.Log
import com.sopt.now.compose.models.User

interface UserRepository {
suspend fun getUserProfile(): User?
suspend fun setUserProfile(user: User)

suspend fun getUserId(): String
suspend fun setUserId(userId: String)
fun getUserProfile(): User?
fun setUserProfile(user: User)
fun getUserId(): String
fun setUserId(userId: String)
}

Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class LoginViewModel(
password = _uiState.value.pw
)

private fun setUserIdInPreference(userId: String) = viewModelScope.launch {
private fun setUserIdInPreference(userId: String) {
userRepository.setUserId(userId)
}

Expand Down

0 comments on commit 812a7db

Please sign in to comment.