-
Notifications
You must be signed in to change notification settings - Fork 0
[7주차/필수] Repository 활용_xml #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop-xml
Are you sure you want to change the base?
Changes from all commits
41d34f6
958da20
b47f59f
c9c68dc
930f543
4fc0500
ddd17f1
0be81c3
f63b7b8
6539bb0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package com.sopt.now | ||
|
|
||
| import android.app.Application | ||
| import android.content.Context | ||
| import androidx.appcompat.app.AppCompatDelegate | ||
| import dagger.hilt.android.HiltAndroidApp | ||
|
|
||
| @HiltAndroidApp | ||
| class NowSopt : Application() { | ||
| override fun onCreate() { | ||
| super.onCreate() | ||
| appContext = applicationContext | ||
|
|
||
| AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO) | ||
| } | ||
|
|
||
| companion object { | ||
| lateinit var appContext: Context | ||
| private set | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package com.sopt.now.data.datasource | ||
|
|
||
| import com.sopt.now.data.dto.request.RequestLoginDto | ||
| import com.sopt.now.data.dto.request.RequestSignUpDto | ||
| import com.sopt.now.data.dto.response.ResponseLoginDto | ||
| import com.sopt.now.data.dto.response.ResponseSignUpDto | ||
| import retrofit2.Response | ||
| import javax.inject.Singleton | ||
|
|
||
| @Singleton | ||
| interface AuthDataSource { | ||
| suspend fun signUp(request: RequestSignUpDto): Response<ResponseSignUpDto> | ||
| suspend fun login(request: RequestLoginDto): Response<ResponseLoginDto> | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package com.sopt.now.data.datasource | ||
|
|
||
| import com.sopt.now.data.dto.response.ResponseFriendsDto | ||
| import retrofit2.Response | ||
| import javax.inject.Singleton | ||
|
|
||
| @Singleton | ||
| interface FriendDataSource { | ||
| suspend fun getFriends(page: Int): Response<ResponseFriendsDto> | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package com.sopt.now.data.datasource | ||
|
|
||
| import com.sopt.now.data.dto.request.RequestChangePwdDto | ||
| import com.sopt.now.data.dto.response.ResponseChangePwdDto | ||
| import com.sopt.now.data.dto.response.ResponseUserInfoDto | ||
| import retrofit2.Response | ||
| import javax.inject.Singleton | ||
|
|
||
| @Singleton | ||
| interface UserDataSource { | ||
| suspend fun getUserInfo(userId: Int): Response<ResponseUserInfoDto> | ||
| suspend fun changeUserPwd(userId: Int, pwd: RequestChangePwdDto): Response<ResponseChangePwdDto> | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,24 @@ | ||||||||||||
| package com.sopt.now.data.datasourceImpl | ||||||||||||
|
|
||||||||||||
| import com.sopt.now.data.datasource.AuthDataSource | ||||||||||||
| import com.sopt.now.data.dto.request.RequestLoginDto | ||||||||||||
| import com.sopt.now.data.dto.request.RequestSignUpDto | ||||||||||||
| import com.sopt.now.data.dto.response.ResponseLoginDto | ||||||||||||
| import com.sopt.now.data.dto.response.ResponseSignUpDto | ||||||||||||
| import com.sopt.now.data.service.AuthService | ||||||||||||
| import retrofit2.Response | ||||||||||||
| import javax.inject.Inject | ||||||||||||
| import javax.inject.Singleton | ||||||||||||
|
|
||||||||||||
| @Singleton | ||||||||||||
| class AuthDataSourceImpl @Inject constructor( | ||||||||||||
| private val authService: AuthService | ||||||||||||
| ) : AuthDataSource { | ||||||||||||
| override suspend fun signUp(request: RequestSignUpDto): Response<ResponseSignUpDto> { | ||||||||||||
| return authService.signUp(request) | ||||||||||||
| } | ||||||||||||
|
Comment on lines
+17
to
+19
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
이렇게 리팩토링 할 수 있겠네요! |
||||||||||||
|
|
||||||||||||
| override suspend fun login(request: RequestLoginDto): Response<ResponseLoginDto> { | ||||||||||||
| return authService.login(request) | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package com.sopt.now.data.datasourceImpl | ||
|
|
||
| import com.sopt.now.data.datasource.FriendDataSource | ||
| import com.sopt.now.data.dto.response.ResponseFriendsDto | ||
| import com.sopt.now.data.service.FriendService | ||
| import retrofit2.Response | ||
| import javax.inject.Inject | ||
| import javax.inject.Singleton | ||
|
|
||
| @Singleton | ||
| class FriendDataSourceImpl @Inject constructor( | ||
| private val friendService: FriendService | ||
| ) : FriendDataSource { | ||
| override suspend fun getFriends(page: Int): Response<ResponseFriendsDto> { | ||
| return friendService.getFriends(page) | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package com.sopt.now.data.datasourceImpl | ||
|
|
||
| import com.sopt.now.data.datasource.UserDataSource | ||
| import com.sopt.now.data.dto.request.RequestChangePwdDto | ||
| import com.sopt.now.data.dto.response.ResponseChangePwdDto | ||
| import com.sopt.now.data.dto.response.ResponseUserInfoDto | ||
| import com.sopt.now.data.service.UserService | ||
| import retrofit2.Response | ||
| import javax.inject.Inject | ||
| import javax.inject.Singleton | ||
|
|
||
| @Singleton | ||
| class UserDataSourceImpl @Inject constructor( | ||
| private val userService: UserService | ||
| ) : UserDataSource { | ||
| override suspend fun getUserInfo(userId: Int): Response<ResponseUserInfoDto> { | ||
| return userService.getUserInfo(userId) | ||
| } | ||
|
|
||
| override suspend fun changeUserPwd( | ||
| userId: Int, | ||
| pwd: RequestChangePwdDto | ||
| ): Response<ResponseChangePwdDto> { | ||
| return userService.changeUserPwd(userId, pwd) | ||
| } | ||
| } |
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. di 폴더는 밖으로 빼면 좋을 것 같아요! 또한 앱잼에서 따를 구조를 생각해서 data에서 remote와 local로 구분해보는 것도 좋을 것 같네욤 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| package com.sopt.now.data.di | ||
|
|
||
| import com.sopt.now.data.datasource.AuthDataSource | ||
| import com.sopt.now.data.datasource.FriendDataSource | ||
| import com.sopt.now.data.datasource.UserDataSource | ||
| import com.sopt.now.data.datasourceImpl.AuthDataSourceImpl | ||
| import com.sopt.now.data.datasourceImpl.FriendDataSourceImpl | ||
| import com.sopt.now.data.datasourceImpl.UserDataSourceImpl | ||
| import com.sopt.now.data.repositoryImpl.AuthRepositoryImpl | ||
| import com.sopt.now.data.repositoryImpl.FriendRepositoryImpl | ||
| import com.sopt.now.data.repositoryImpl.UserRepositoryImpl | ||
| import com.sopt.now.data.service.AuthService | ||
| import com.sopt.now.data.service.FriendService | ||
| import com.sopt.now.data.service.UserService | ||
| import com.sopt.now.domain.repository.AuthRepository | ||
| import com.sopt.now.domain.repository.FriendRepository | ||
| import com.sopt.now.domain.repository.UserRepository | ||
| import dagger.Module | ||
| import dagger.Provides | ||
| import dagger.hilt.InstallIn | ||
| import dagger.hilt.components.SingletonComponent | ||
| import javax.inject.Singleton | ||
|
|
||
| @Module | ||
| @InstallIn(SingletonComponent::class) | ||
| object DataModule { | ||
| @Singleton | ||
| @Provides | ||
| fun provideAuthDataSource( | ||
| authService: AuthService | ||
| ): AuthDataSource { | ||
| return AuthDataSourceImpl(authService) | ||
| } | ||
|
Comment on lines
+28
to
+33
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| @Singleton | ||
| @Provides | ||
| fun provideAuthRepository( | ||
| authDataSource: AuthDataSource | ||
| ): AuthRepository { | ||
| return AuthRepositoryImpl(authDataSource) | ||
| } | ||
| @Singleton | ||
| @Provides | ||
| fun provideUserDataSource( | ||
| userService: UserService | ||
| ): UserDataSource { | ||
| return UserDataSourceImpl(userService) | ||
| } | ||
|
|
||
| @Singleton | ||
| @Provides | ||
| fun provideUserRepository( | ||
| userDataSource: UserDataSource | ||
| ): UserRepository { | ||
| return UserRepositoryImpl(userDataSource) | ||
| } | ||
|
|
||
| @Singleton | ||
| @Provides | ||
| fun provideFriendDataSource( | ||
| friendService: FriendService | ||
| ): FriendDataSource { | ||
| return FriendDataSourceImpl(friendService) | ||
| } | ||
|
|
||
| @Singleton | ||
| @Provides | ||
| fun provideFriendRepository( | ||
| friendDataSource: FriendDataSource | ||
| ): FriendRepository { | ||
| return FriendRepositoryImpl(friendDataSource) | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| package com.sopt.now.data.di | ||
|
|
||
| import android.util.Log | ||
| import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory | ||
| import com.sopt.now.BuildConfig.AUTH_BASE_URL | ||
| import com.sopt.now.BuildConfig.FRIEND_BASE_URL | ||
| import com.sopt.now.data.service.AuthService | ||
| import com.sopt.now.data.service.FriendService | ||
| import com.sopt.now.data.service.UserService | ||
| import dagger.Module | ||
| import dagger.Provides | ||
| import dagger.hilt.InstallIn | ||
| import dagger.hilt.components.SingletonComponent | ||
| import kotlinx.serialization.json.Json | ||
| import okhttp3.Interceptor | ||
| import okhttp3.MediaType.Companion.toMediaType | ||
| import okhttp3.OkHttpClient | ||
| import okhttp3.logging.HttpLoggingInterceptor | ||
| import retrofit2.Retrofit | ||
| import javax.inject.Singleton | ||
|
|
||
| @Module | ||
| @InstallIn(SingletonComponent::class) | ||
| object NetworkModule { | ||
| private const val CONTENT_TYPE = "application/json" | ||
| private val json: Json = Json { | ||
| ignoreUnknownKeys = true | ||
| } | ||
|
|
||
| private fun getLogOkHttpClient(): Interceptor { | ||
| val loggingInterceptor = HttpLoggingInterceptor { message -> | ||
| Log.d("OkHttp", message) | ||
| } | ||
| loggingInterceptor.level = HttpLoggingInterceptor.Level.BODY | ||
| return loggingInterceptor | ||
| } | ||
|
|
||
| private val okHttpClient = OkHttpClient.Builder() | ||
| .addInterceptor(getLogOkHttpClient()) | ||
| .build() | ||
|
|
||
| @Singleton | ||
| @Provides | ||
| fun provideRetrofit(): Retrofit.Builder { | ||
| return Retrofit.Builder() | ||
| .addConverterFactory(json.asConverterFactory(CONTENT_TYPE.toMediaType())) | ||
| .client(okHttpClient) | ||
| } | ||
|
|
||
| @Singleton | ||
| @Provides | ||
| fun provideAuthService(retrofit: Retrofit.Builder): AuthService { | ||
| return retrofit.baseUrl(AUTH_BASE_URL).build().create(AuthService::class.java) | ||
| } | ||
|
|
||
| @Singleton | ||
| @Provides | ||
| fun provideUserService(retrofit: Retrofit.Builder): UserService { | ||
| return retrofit.baseUrl(AUTH_BASE_URL).build().create(UserService::class.java) | ||
| } | ||
|
|
||
| @Singleton | ||
| @Provides | ||
| fun provideFriendService(retrofit: Retrofit.Builder): FriendService { | ||
| return retrofit.baseUrl(FRIEND_BASE_URL).build().create(FriendService::class.java) | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
함수로 분리하면 더 깔끔할 것 같아요