File tree Expand file tree Collapse file tree
app/src/main/java/com/threegap/bitnagil/di/data
data/src/main/java/com/threegap/bitnagil/data/user Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -20,8 +20,10 @@ import com.threegap.bitnagil.data.report.datasource.ReportDataSource
2020import com.threegap.bitnagil.data.report.datasourceImpl.ReportDataSourceImpl
2121import com.threegap.bitnagil.data.routine.datasource.RoutineRemoteDataSource
2222import 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
2527import com.threegap.bitnagil.data.version.datasource.VersionDataSource
2628import com.threegap.bitnagil.data.version.datasourceImpl.VersionDataSourceImpl
2729import 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
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change @@ -2,6 +2,6 @@ package com.threegap.bitnagil.data.user.datasource
22
33import com.threegap.bitnagil.data.user.model.response.UserProfileResponse
44
5- interface UserDataSource {
5+ interface UserRemoteDataSource {
66 suspend fun fetchUserProfile (): Result <UserProfileResponse >
77}
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 11package com.threegap.bitnagil.data.user.datasourceImpl
22
33import com.threegap.bitnagil.data.common.safeApiCall
4- import com.threegap.bitnagil.data.user.datasource.UserDataSource
4+ import com.threegap.bitnagil.data.user.datasource.UserRemoteDataSource
55import com.threegap.bitnagil.data.user.model.response.UserProfileResponse
66import com.threegap.bitnagil.data.user.service.UserService
77import 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}
You can’t perform that action at this time.
0 commit comments