-
Notifications
You must be signed in to change notification settings - Fork 0
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
[Feat/#8] 4주차 과제 #9
base: develop
Are you sure you want to change the base?
Changes from all commits
9edf84e
1d4dadd
caf0714
f555ec2
f8164cc
0e1b912
ba1f683
15bd300
22c0c49
ae62069
51b5bac
0965335
5022e87
755d7a4
eca791d
2d71803
38c5dc7
3e8cc29
68012cf
4988b03
490077a
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,7 @@ | ||
package org.sopt.and.data.datasource.local | ||
|
||
|
||
interface LocalDataSource { | ||
var accessToken: String | ||
fun clearInfo() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.sopt.and.data.datasource.remote | ||
|
||
import org.sopt.and.data.service.model.BaseResponse | ||
import org.sopt.and.data.service.model.request.SignInRequest | ||
import org.sopt.and.data.service.model.request.SignUpRequest | ||
import org.sopt.and.data.service.model.response.SignInResponse | ||
import org.sopt.and.data.service.model.response.SignUpResponse | ||
|
||
|
||
interface AuthRemoteDataSource { | ||
suspend fun signIn(signInRequest: SignInRequest): BaseResponse<SignInResponse> | ||
|
||
suspend fun signUp(signUpRequest: SignUpRequest): BaseResponse<SignUpResponse> | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package org.sopt.and.data.datasource.remote | ||
|
||
import org.sopt.and.data.service.model.BaseResponse | ||
import org.sopt.and.data.service.model.request.HobbyModifyRequest | ||
import org.sopt.and.data.service.model.response.HobbyResponse | ||
import retrofit2.Response | ||
|
||
|
||
interface MyPageRemoteDataSource { | ||
|
||
suspend fun getMyHobby(): BaseResponse<HobbyResponse> | ||
|
||
suspend fun getOtherHobby( | ||
no: String | ||
): BaseResponse<HobbyResponse> | ||
|
||
suspend fun modifyMyHobby( | ||
hobbyModifyRequest: HobbyModifyRequest | ||
): Response<BaseResponse<String?>?> | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package org.sopt.and.data.datasourceImpl.local | ||
|
||
import android.content.SharedPreferences | ||
import org.sopt.and.data.datasource.local.LocalDataSource | ||
import javax.inject.Inject | ||
|
||
|
||
class LocalDataSourceImpl @Inject constructor( | ||
private val sharedPreferences: SharedPreferences | ||
) : LocalDataSource { | ||
|
||
override var accessToken: String | ||
get() = sharedPreferences.getString(ACCESS_TOKEN, DEFAULT).orEmpty() | ||
set(value) = sharedPreferences.edit().putString(ACCESS_TOKEN, value).apply() | ||
|
||
override fun clearInfo() = sharedPreferences.edit().clear().apply() | ||
|
||
companion object { | ||
private const val ACCESS_TOKEN = "access_token" | ||
private const val DEFAULT = "" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package org.sopt.and.data.datasourceImpl.remote | ||
|
||
import org.sopt.and.data.datasource.remote.AuthRemoteDataSource | ||
import org.sopt.and.data.service.AuthService | ||
import org.sopt.and.data.service.model.BaseResponse | ||
import org.sopt.and.data.service.model.request.SignInRequest | ||
import org.sopt.and.data.service.model.request.SignUpRequest | ||
import org.sopt.and.data.service.model.response.SignInResponse | ||
import org.sopt.and.data.service.model.response.SignUpResponse | ||
import javax.inject.Inject | ||
|
||
|
||
class AuthRemoteDataSourceImpl @Inject constructor( | ||
private val authService: AuthService | ||
) : AuthRemoteDataSource { | ||
|
||
override suspend fun signIn( | ||
signInRequest: SignInRequest | ||
): BaseResponse<SignInResponse> = authService.signIn(signInRequest) | ||
|
||
override suspend fun signUp( | ||
signUpRequest: SignUpRequest | ||
): BaseResponse<SignUpResponse> = authService.signUp(signUpRequest) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.sopt.and.data.datasourceImpl.remote | ||
|
||
import org.sopt.and.data.datasource.remote.MyPageRemoteDataSource | ||
import org.sopt.and.data.service.MyPageService | ||
import org.sopt.and.data.service.model.BaseResponse | ||
import org.sopt.and.data.service.model.request.HobbyModifyRequest | ||
import org.sopt.and.data.service.model.response.HobbyResponse | ||
import retrofit2.Response | ||
import javax.inject.Inject | ||
|
||
|
||
class MyPageRemoteDataSourceImpl @Inject constructor( | ||
private val myPageService: MyPageService | ||
) : MyPageRemoteDataSource { | ||
|
||
override suspend fun getMyHobby(): BaseResponse<HobbyResponse> = myPageService.getMyHobby() | ||
|
||
override suspend fun getOtherHobby( | ||
no: String | ||
): BaseResponse<HobbyResponse> = myPageService.getOthersHobby(no) | ||
|
||
override suspend fun modifyMyHobby( | ||
hobbyModifyRequest: HobbyModifyRequest | ||
): Response<BaseResponse<String?>?> = myPageService.modifyMyHobby(hobbyModifyRequest) | ||
} |
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. 힐트 사용 너무 잘하시네요~ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package org.sopt.and.data.di | ||
|
||
import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
import kotlinx.serialization.json.Json | ||
import okhttp3.MediaType.Companion.toMediaType | ||
import okhttp3.OkHttpClient | ||
import okhttp3.ResponseBody | ||
import okhttp3.logging.HttpLoggingInterceptor | ||
import org.sopt.and.BuildConfig.BASE_URL | ||
import org.sopt.and.data.interceptor.TokenInterceptor | ||
import retrofit2.Converter | ||
import retrofit2.Retrofit | ||
import java.lang.reflect.Type | ||
import javax.inject.Singleton | ||
|
||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
object ApiModule { | ||
|
||
@Provides | ||
@Singleton | ||
fun provideLoggingInterceptor(): HttpLoggingInterceptor = HttpLoggingInterceptor().apply { | ||
level = HttpLoggingInterceptor.Level.BODY | ||
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. HttpLoggingInterceptor 사용하는거 너무 좋은 것 같아요~!! |
||
} | ||
|
||
@Provides | ||
@Singleton | ||
fun provideOkHttpClient( | ||
loggingInterceptor: HttpLoggingInterceptor, | ||
tokenInterceptor: TokenInterceptor | ||
): OkHttpClient = OkHttpClient.Builder() | ||
.addInterceptor(loggingInterceptor) | ||
.addInterceptor(tokenInterceptor) | ||
.build() | ||
|
||
@Provides | ||
@Singleton | ||
fun provideRetrofit( | ||
client: OkHttpClient | ||
): Retrofit { | ||
val nullOnEmptyConverterFactory = object : Converter.Factory() { | ||
fun converterFactory() = this | ||
override fun responseBodyConverter(type: Type, annotations: Array<out Annotation>, retrofit: Retrofit) = object : Converter<ResponseBody, Any?> { | ||
val nextResponseBodyConverter = retrofit.nextResponseBodyConverter<Any?>(converterFactory(), type, annotations) | ||
override fun convert(value: ResponseBody) = if (value.contentLength() == 0L) null else nextResponseBodyConverter.convert(value) | ||
} | ||
} | ||
|
||
return Retrofit.Builder() | ||
.baseUrl(BASE_URL) | ||
.client(client) | ||
.addConverterFactory(nullOnEmptyConverterFactory) | ||
.addConverterFactory(Json.asConverterFactory("application/json".toMediaType())) | ||
.build() | ||
} | ||
} |
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. 이건 네이밍을 왜 앱 모듈로 하셨나요? |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package org.sopt.and.data.di | ||
|
||
import dagger.Binds | ||
import dagger.Module | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
import org.sopt.and.data.datasource.local.LocalDataSource | ||
import org.sopt.and.data.datasource.remote.AuthRemoteDataSource | ||
import org.sopt.and.data.datasource.remote.MyPageRemoteDataSource | ||
import org.sopt.and.data.datasourceImpl.local.LocalDataSourceImpl | ||
import org.sopt.and.data.datasourceImpl.remote.AuthRemoteDataSourceImpl | ||
import org.sopt.and.data.datasourceImpl.remote.MyPageRemoteDataSourceImpl | ||
import javax.inject.Singleton | ||
|
||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
abstract class DataSourceModule { | ||
|
||
@Binds | ||
@Singleton | ||
abstract fun bindAuthRemoteDataSource( | ||
authRemoteDataSourceImpl: AuthRemoteDataSourceImpl | ||
): AuthRemoteDataSource | ||
|
||
@Binds | ||
@Singleton | ||
abstract fun bindMyPageRemoteDataSource( | ||
myPageRemoteDataSourceImpl: MyPageRemoteDataSourceImpl | ||
): MyPageRemoteDataSource | ||
|
||
@Binds | ||
@Singleton | ||
abstract fun bindLocalDataSource( | ||
localDataSourceImpl: LocalDataSourceImpl | ||
): LocalDataSource | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package org.sopt.and.data.di | ||
|
||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
import org.sopt.and.data.service.AuthService | ||
import org.sopt.and.data.service.MyPageService | ||
import retrofit2.Retrofit | ||
import javax.inject.Singleton | ||
|
||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
object ServiceModule { | ||
|
||
@Provides | ||
@Singleton | ||
fun provideAuthService( | ||
retrofit: Retrofit | ||
): AuthService = retrofit.create(AuthService::class.java) | ||
|
||
@Provides | ||
@Singleton | ||
fun provideMyPageService( | ||
retrofit: Retrofit | ||
): MyPageService = retrofit.create(MyPageService::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.
Localdl라는 이름으론 이 클래스가 어떤 저장소에 접근하는지 알기 어렵다고 생각해요.
로컬 데이터베이스의 경우 preference, datastore, room 등이 있으니까 이름에서 잘 구분해주면 좋을 것 같습니다!