-
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/#9] 4주차 필수 과제 구현 #11
base: develop
Are you sure you want to change the base?
Changes from all commits
66897d8
422b74b
bc0e6db
6193ea0
1f2743f
ff8151f
0c8c32f
9557f67
570178f
0e4daa7
958b879
a6c1250
9df14b4
3dfdfc5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,25 +11,20 @@ class PreferenceUtil( | |
PREF_NAME, Context.MODE_PRIVATE | ||
) | ||
|
||
var id: String | ||
get() = preference.getString(ID, DEFAULT_STRING).toString() | ||
set(value) = preference.edit().putString(ID, value).apply() | ||
var token: String | ||
get() = preference.getString(TOKEN, DEFAULT_STRING).toString() | ||
set(value) = preference.edit().putString(TOKEN, value).apply() | ||
|
||
var password: String | ||
get() = preference.getString(PASSWORD, DEFAULT_STRING).toString() | ||
set(value) = preference.edit().putString(PASSWORD, value).apply() | ||
|
||
fun clearIdPassword() { | ||
id = "" | ||
password = "" | ||
fun clearToken() { | ||
token = "" | ||
} | ||
|
||
companion object { | ||
private const val PREF_NAME = "wavve_prefs" | ||
private const val ID = "ID" | ||
private const val PASSWORD = "PASSWORD" | ||
private const val TOKEN = "TOKEN" | ||
private const val DEFAULT_STRING = "" | ||
|
||
|
||
Comment on lines
26
to
+27
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. 2줄 공백이다 ㅋㅋ 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. 들켰다ㅎ |
||
val LocalPreference = staticCompositionLocalOf<PreferenceUtil> { | ||
error("PreferenceUtil is not initialized") | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.sopt.and.data.datasource | ||
|
||
import org.sopt.and.data.dto.BaseResponse | ||
import org.sopt.and.data.dto.request.SignInRequestDto | ||
import org.sopt.and.data.dto.request.SignUpRequestDto | ||
import org.sopt.and.data.dto.response.SignInResponseDto | ||
import org.sopt.and.data.dto.response.SignUpResponseDto | ||
import retrofit2.Call | ||
|
||
interface AuthDataSource { | ||
fun postSignUp( | ||
request: SignUpRequestDto | ||
): Call<BaseResponse<SignUpResponseDto>> | ||
Comment on lines
+11
to
+13
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. To reviewer에 원래는 call을 안쓰셨다고 했던 것 같은데 원래 하셨던 방법이 뭐였나요?! 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. 저도 궁금합니다~!! 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. suspend 다음주에 알려줄 거야 ㅜㅜ 앞서나가지마잉 ㅋㅋ 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. 앞서나기 싫어서 Call 사용했습니다ㅎㅎ (근데 진짜에요) |
||
|
||
fun postSignIn( | ||
request: SignInRequestDto | ||
): Call<BaseResponse<SignInResponseDto>> | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package org.sopt.and.data.datasource | ||
|
||
import org.sopt.and.data.dto.BaseResponse | ||
import org.sopt.and.data.dto.response.MyHobbyResponseDto | ||
import retrofit2.Call | ||
|
||
interface UserDataSource { | ||
fun getMyHobby(token: String): Call<BaseResponse<MyHobbyResponseDto>> | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.sopt.and.data.datasourceImpl | ||
|
||
import org.sopt.and.data.datasource.AuthDataSource | ||
import org.sopt.and.data.dto.BaseResponse | ||
import org.sopt.and.data.dto.request.SignInRequestDto | ||
import org.sopt.and.data.dto.request.SignUpRequestDto | ||
import org.sopt.and.data.dto.response.SignInResponseDto | ||
import org.sopt.and.data.dto.response.SignUpResponseDto | ||
import org.sopt.and.data.remote.AuthService | ||
import retrofit2.Call | ||
import javax.inject.Inject | ||
|
||
class AuthDataSourceImpl @Inject constructor( | ||
private val userService: AuthService | ||
): AuthDataSource { | ||
override fun postSignUp(request: SignUpRequestDto): Call<BaseResponse<SignUpResponseDto>> = userService.signUp(request) | ||
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. 요기도 뭔가 줄 분리하면 좋을 것 같아요! |
||
override fun postSignIn(request: SignInRequestDto): Call<BaseResponse<SignInResponseDto>> = userService.signIn(request) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.sopt.and.data.datasourceImpl | ||
|
||
import org.sopt.and.data.datasource.UserDataSource | ||
import org.sopt.and.data.dto.BaseResponse | ||
import org.sopt.and.data.dto.response.MyHobbyResponseDto | ||
import org.sopt.and.data.remote.UserService | ||
import retrofit2.Call | ||
import javax.inject.Inject | ||
|
||
class UserDataSourceImpl @Inject constructor( | ||
private val userService: UserService | ||
) : UserDataSource { | ||
override fun getMyHobby(token: String): Call<BaseResponse<MyHobbyResponseDto>> = | ||
userService.getMyHobby(token) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
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.AuthDataSource | ||
import org.sopt.and.data.datasource.UserDataSource | ||
import org.sopt.and.data.datasourceImpl.AuthDataSourceImpl | ||
import org.sopt.and.data.datasourceImpl.UserDataSourceImpl | ||
import javax.inject.Singleton | ||
|
||
@InstallIn(SingletonComponent::class) | ||
@Module | ||
abstract class DataSourceModule { | ||
|
||
@Binds | ||
@Singleton | ||
abstract fun bindsAuthDataSource( | ||
authDataSourceImpl: AuthDataSourceImpl | ||
): AuthDataSource | ||
|
||
@Binds | ||
@Singleton | ||
abstract fun bindsUserDataSource( | ||
userDataSourceImpl: UserDataSourceImpl | ||
): UserDataSource | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
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.repositoryimpl.DummyPopularProgramRepositoryImpl | ||
import org.sopt.and.data.repositoryimpl.DummyRecommendationRepositoryImpl | ||
import org.sopt.and.data.repositoryimpl.MyHobbyRepositoryImpl | ||
import org.sopt.and.data.repositoryimpl.SignInRepositoryImpl | ||
import org.sopt.and.data.repositoryimpl.SignUpRepositoryImpl | ||
import org.sopt.and.data.repositoryimpl.StarredProgramRepositoryImpl | ||
import org.sopt.and.domain.repository.MyHobbyRepository | ||
import org.sopt.and.domain.repository.PopularProgramRepository | ||
import org.sopt.and.domain.repository.RecommendationRepository | ||
import org.sopt.and.domain.repository.SignInRepository | ||
import org.sopt.and.domain.repository.SignUpRepository | ||
import org.sopt.and.domain.repository.StarredProgramRepository | ||
import javax.inject.Singleton | ||
|
||
@InstallIn(SingletonComponent::class) | ||
@Module | ||
abstract class RepositoryModule() { | ||
|
||
@Binds | ||
@Singleton | ||
abstract fun bindsDummyRecommendationRepository( | ||
recommendationRepositoryImpl: DummyRecommendationRepositoryImpl | ||
): RecommendationRepository | ||
|
||
@Binds | ||
@Singleton | ||
abstract fun bindsDummyPopularProgramRepository( | ||
popularProgramRepositoryImpl: DummyPopularProgramRepositoryImpl | ||
): PopularProgramRepository | ||
|
||
@Binds | ||
@Singleton | ||
abstract fun bindsStarredProgramRepository( | ||
starredProgramRepositoryImpl: StarredProgramRepositoryImpl | ||
): StarredProgramRepository | ||
|
||
@Binds | ||
@Singleton | ||
abstract fun bindsSignUpRepository( | ||
signUpRepositoryImpl: SignUpRepositoryImpl | ||
): SignUpRepository | ||
|
||
|
||
@Binds | ||
@Singleton | ||
abstract fun bindsSignInRepository( | ||
signInRepositoryImpl: SignInRepositoryImpl | ||
): SignInRepository | ||
|
||
@Binds | ||
@Singleton | ||
abstract fun bindsMyHobbyRepository( | ||
myHobbyRepositoryImpl: MyHobbyRepositoryImpl | ||
): MyHobbyRepository | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
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.logging.HttpLoggingInterceptor | ||
import org.sopt.and.BuildConfig.BASE_URL | ||
import retrofit2.Converter | ||
import retrofit2.Retrofit | ||
import javax.inject.Singleton | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
object RetrofitModule { | ||
|
||
@Provides | ||
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. 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 | ||
fun providesLoggingInterceptor() = HttpLoggingInterceptor().apply { | ||
level = HttpLoggingInterceptor.Level.BODY | ||
} | ||
|
||
@Provides | ||
@Singleton | ||
fun providesOkHttpClient( | ||
loggingInterceptor: HttpLoggingInterceptor | ||
): OkHttpClient = OkHttpClient.Builder() | ||
.addInterceptor(loggingInterceptor) | ||
.build() | ||
|
||
@Provides | ||
@Singleton | ||
fun providesConverterFactory(): Converter.Factory = Json.asConverterFactory("application/json".toMediaType()) | ||
|
||
@Provides | ||
@Singleton | ||
fun providesRetrofit( | ||
client: OkHttpClient, | ||
converterFactory: Converter.Factory | ||
): Retrofit = Retrofit.Builder() | ||
.baseUrl(BASE_URL) | ||
.client(client) | ||
.addConverterFactory(converterFactory) | ||
.build() | ||
} |
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.
sharedPreferences를 clear 시켜주는 것 대신 토큰만 clear 해준 이유가 있는지 궁금해요!
또, sharedPreference에서 remove 함수를 사용해 줄 수도 있습니다!
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.
그냥 필요한 부분만 지우는게 좋지 않을까 싶어서 저렇게 했습니다!
remove에 대해선 자세히 알아보고 적용할게요~