Skip to content

Commit 46ea194

Browse files
committed
Refactor: UserDataSource를 UserRemoteDataSource와 UserLocalDataSource로 분리
1 parent 55c8f13 commit 46ea194

5 files changed

Lines changed: 48 additions & 10 deletions

File tree

app/src/main/java/com/threegap/bitnagil/di/data/DataSourceModule.kt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ import com.threegap.bitnagil.data.report.datasource.ReportDataSource
2020
import com.threegap.bitnagil.data.report.datasourceImpl.ReportDataSourceImpl
2121
import com.threegap.bitnagil.data.routine.datasource.RoutineRemoteDataSource
2222
import com.threegap.bitnagil.data.routine.datasourceImpl.RoutineRemoteDataSourceImpl
23-
import com.threegap.bitnagil.data.user.datasource.UserDataSource
24-
import com.threegap.bitnagil.data.user.datasourceImpl.UserDataSourceImpl
23+
import com.threegap.bitnagil.data.user.datasource.UserLocalDataSource
24+
import com.threegap.bitnagil.data.user.datasource.UserRemoteDataSource
25+
import com.threegap.bitnagil.data.user.datasourceImpl.UserLocalDataSourceImpl
26+
import com.threegap.bitnagil.data.user.datasourceImpl.UserRemoteDataSourceImpl
2527
import com.threegap.bitnagil.data.version.datasource.VersionDataSource
2628
import com.threegap.bitnagil.data.version.datasourceImpl.VersionDataSourceImpl
2729
import dagger.Binds
@@ -56,7 +58,11 @@ abstract class DataSourceModule {
5658

5759
@Binds
5860
@Singleton
59-
abstract fun bindUserDataSource(userDataSourceImpl: UserDataSourceImpl): UserDataSource
61+
abstract fun bindUserLocalDataSource(userLocalDataSourceImpl: UserLocalDataSourceImpl): UserLocalDataSource
62+
63+
@Binds
64+
@Singleton
65+
abstract fun bindUserRemoteDataSource(userRemoteDataSourceImpl: UserRemoteDataSourceImpl): UserRemoteDataSource
6066

6167
@Binds
6268
@Singleton
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.threegap.bitnagil.data.user.datasource
2+
3+
import com.threegap.bitnagil.domain.user.model.UserProfile
4+
import kotlinx.coroutines.flow.StateFlow
5+
6+
interface UserLocalDataSource {
7+
val userProfile: StateFlow<UserProfile?>
8+
suspend fun saveUserProfile(userProfile: UserProfile)
9+
fun clearCache()
10+
}

data/src/main/java/com/threegap/bitnagil/data/user/datasource/UserDataSource.kt renamed to data/src/main/java/com/threegap/bitnagil/data/user/datasource/UserRemoteDataSource.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ package com.threegap.bitnagil.data.user.datasource
22

33
import com.threegap.bitnagil.data.user.model.response.UserProfileResponse
44

5-
interface UserDataSource {
5+
interface UserRemoteDataSource {
66
suspend fun fetchUserProfile(): Result<UserProfileResponse>
77
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.threegap.bitnagil.data.user.datasourceImpl
2+
3+
import com.threegap.bitnagil.data.user.datasource.UserLocalDataSource
4+
import com.threegap.bitnagil.domain.user.model.UserProfile
5+
import kotlinx.coroutines.flow.MutableStateFlow
6+
import kotlinx.coroutines.flow.StateFlow
7+
import kotlinx.coroutines.flow.asStateFlow
8+
import kotlinx.coroutines.flow.update
9+
import javax.inject.Inject
10+
import javax.inject.Singleton
11+
12+
@Singleton
13+
class UserLocalDataSourceImpl @Inject constructor() : UserLocalDataSource {
14+
private val _userProfile = MutableStateFlow<UserProfile?>(null)
15+
override val userProfile: StateFlow<UserProfile?> = _userProfile.asStateFlow()
16+
17+
override suspend fun saveUserProfile(userProfile: UserProfile) {
18+
_userProfile.update { userProfile }
19+
}
20+
21+
override fun clearCache() {
22+
_userProfile.update { null }
23+
}
24+
}

data/src/main/java/com/threegap/bitnagil/data/user/datasourceImpl/UserDataSourceImpl.kt renamed to data/src/main/java/com/threegap/bitnagil/data/user/datasourceImpl/UserRemoteDataSourceImpl.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
package com.threegap.bitnagil.data.user.datasourceImpl
22

33
import com.threegap.bitnagil.data.common.safeApiCall
4-
import com.threegap.bitnagil.data.user.datasource.UserDataSource
4+
import com.threegap.bitnagil.data.user.datasource.UserRemoteDataSource
55
import com.threegap.bitnagil.data.user.model.response.UserProfileResponse
66
import com.threegap.bitnagil.data.user.service.UserService
77
import javax.inject.Inject
88

9-
class UserDataSourceImpl @Inject constructor(
9+
class UserRemoteDataSourceImpl @Inject constructor(
1010
private val userService: UserService,
11-
) : UserDataSource {
11+
) : UserRemoteDataSource {
1212
override suspend fun fetchUserProfile(): Result<UserProfileResponse> =
13-
safeApiCall {
14-
userService.fetchUserProfile()
15-
}
13+
safeApiCall { userService.fetchUserProfile() }
1614
}

0 commit comments

Comments
 (0)