File tree Expand file tree Collapse file tree 15 files changed +131
-1
lines changed
app/src/main/java/com/threegap/bitnagil/di/data
data/src/main/java/com/threegap/bitnagil/data/user
domain/src/main/java/com/threegap/bitnagil/domain/user
presentation/src/main/java/com/threegap/bitnagil/presentation/home Expand file tree Collapse file tree 15 files changed +131
-1
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,8 @@ import com.threegap.bitnagil.data.onboarding.datasource.OnBoardingDataSource
1010import com.threegap.bitnagil.data.onboarding.datasourceImpl.OnBoardingDataSourceImpl
1111import com.threegap.bitnagil.data.routine.datasource.RoutineRemoteDataSource
1212import com.threegap.bitnagil.data.routine.datasourceImpl.RoutineRemoteDataSourceImpl
13+ import com.threegap.bitnagil.data.user.datasource.UserDataSource
14+ import com.threegap.bitnagil.data.user.datasourceImpl.UserDataSourceImpl
1315import com.threegap.bitnagil.data.writeroutine.datasource.WriteRoutineDataSource
1416import com.threegap.bitnagil.data.writeroutine.datasourceImpl.WriteRoutineDataSourceImpl
1517import dagger.Binds
@@ -45,4 +47,8 @@ abstract class DataSourceModule {
4547 @Binds
4648 @Singleton
4749 abstract fun bindWriteRoutineDataSource (writeRoutineDataSourceImpl : WriteRoutineDataSourceImpl ): WriteRoutineDataSource
50+
51+ @Binds
52+ @Singleton
53+ abstract fun bindUserDataSource (userDataSourceImpl : UserDataSourceImpl ): UserDataSource
4854}
Original file line number Diff line number Diff line change @@ -4,11 +4,13 @@ import com.threegap.bitnagil.data.auth.repositoryimpl.AuthRepositoryImpl
44import com.threegap.bitnagil.data.emotion.repositoryImpl.EmotionRepositoryImpl
55import com.threegap.bitnagil.data.onboarding.repositoryImpl.OnBoardingRepositoryImpl
66import com.threegap.bitnagil.data.routine.repositoryImpl.RoutineRepositoryImpl
7+ import com.threegap.bitnagil.data.user.repositoryImpl.UserRepositoryImpl
78import com.threegap.bitnagil.data.writeroutine.repositoryImpl.WriteRoutineRepositoryImpl
89import com.threegap.bitnagil.domain.auth.repository.AuthRepository
910import com.threegap.bitnagil.domain.emotion.repository.EmotionRepository
1011import com.threegap.bitnagil.domain.onboarding.repository.OnBoardingRepository
1112import com.threegap.bitnagil.domain.routine.repository.RoutineRepository
13+ import com.threegap.bitnagil.domain.user.repository.UserRepository
1214import com.threegap.bitnagil.domain.writeroutine.repository.WriteRoutineRepository
1315import dagger.Binds
1416import dagger.Module
@@ -39,4 +41,8 @@ abstract class RepositoryModule {
3941 @Binds
4042 @Singleton
4143 abstract fun bindWriteRoutineRepository (writeRoutineRepositoryImpl : WriteRoutineRepositoryImpl ): WriteRoutineRepository
44+
45+ @Binds
46+ @Singleton
47+ abstract fun bindUserRepository (userRepositoryImpl : UserRepositoryImpl ): UserRepository
4248}
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import com.threegap.bitnagil.data.auth.service.AuthService
44import com.threegap.bitnagil.data.emotion.service.EmotionService
55import com.threegap.bitnagil.data.onboarding.service.OnBoardingService
66import com.threegap.bitnagil.data.routine.service.RoutineService
7+ import com.threegap.bitnagil.data.user.service.UserService
78import com.threegap.bitnagil.data.writeroutine.service.WriteRoutineService
89import com.threegap.bitnagil.di.core.Auth
910import com.threegap.bitnagil.di.core.NoneAuth
@@ -48,4 +49,9 @@ object ServiceModule {
4849 @Singleton
4950 fun provideReissueService (@NoneAuth retrofit : Retrofit ): ReissueService =
5051 retrofit.create(ReissueService ::class .java)
52+
53+ @Provides
54+ @Singleton
55+ fun provideUserService (@Auth retrofit : Retrofit ): UserService =
56+ retrofit.create(UserService ::class .java)
5157}
Original file line number Diff line number Diff line change 1+ package com.threegap.bitnagil.data.user.datasource
2+
3+ import com.threegap.bitnagil.data.user.model.response.UserProfileResponseDto
4+
5+ interface UserDataSource {
6+ suspend fun fetchUserProfile (): Result <UserProfileResponseDto >
7+ }
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.common.safeApiCall
4+ import com.threegap.bitnagil.data.user.datasource.UserDataSource
5+ import com.threegap.bitnagil.data.user.model.response.UserProfileResponseDto
6+ import com.threegap.bitnagil.data.user.service.UserService
7+ import javax.inject.Inject
8+
9+ class UserDataSourceImpl @Inject constructor(
10+ private val userService : UserService ,
11+ ) : UserDataSource {
12+ override suspend fun fetchUserProfile (): Result <UserProfileResponseDto > =
13+ safeApiCall {
14+ userService.fetchUserProfile()
15+ }
16+ }
Original file line number Diff line number Diff line change 1+ package com.threegap.bitnagil.data.user.model.response
2+
3+ import com.threegap.bitnagil.domain.user.model.UserProfile
4+ import kotlinx.serialization.SerialName
5+ import kotlinx.serialization.Serializable
6+
7+ @Serializable
8+ data class UserProfileResponseDto (
9+ @SerialName(" nickname" )
10+ val nickname : String ,
11+ )
12+
13+ fun UserProfileResponseDto.toDomain () =
14+ UserProfile (
15+ nickname = this .nickname,
16+ )
Original file line number Diff line number Diff line change 1+ package com.threegap.bitnagil.data.user.repositoryImpl
2+
3+ import com.threegap.bitnagil.data.user.datasource.UserDataSource
4+ import com.threegap.bitnagil.data.user.model.response.toDomain
5+ import com.threegap.bitnagil.domain.user.model.UserProfile
6+ import com.threegap.bitnagil.domain.user.repository.UserRepository
7+ import javax.inject.Inject
8+
9+ class UserRepositoryImpl @Inject constructor(
10+ private val userDataSource : UserDataSource ,
11+ ) : UserRepository {
12+ override suspend fun fetchUserProfile (): Result <UserProfile > =
13+ userDataSource.fetchUserProfile().map { it.toDomain() }
14+ }
Original file line number Diff line number Diff line change 1+ package com.threegap.bitnagil.data.user.service
2+
3+ import com.threegap.bitnagil.data.user.model.response.UserProfileResponseDto
4+ import com.threegap.bitnagil.network.model.BaseResponse
5+ import retrofit2.http.GET
6+
7+ interface UserService {
8+ @GET(" /api/v1/users/nickname" )
9+ suspend fun fetchUserProfile (): BaseResponse <UserProfileResponseDto >
10+ }
Original file line number Diff line number Diff line change 1+ package com.threegap.bitnagil.domain.user.model
2+
3+ data class UserProfile (
4+ val nickname : String ,
5+ )
Original file line number Diff line number Diff line change 1+ package com.threegap.bitnagil.domain.user.repository
2+
3+ import com.threegap.bitnagil.domain.user.model.UserProfile
4+
5+ interface UserRepository {
6+ suspend fun fetchUserProfile (): Result <UserProfile >
7+ }
You can’t perform that action at this time.
0 commit comments