-
Notifications
You must be signed in to change notification settings - Fork 0
[feature/#7] 4주차 과제 구현 #8
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
Open
kangyein9892
wants to merge
24
commits into
develop
Choose a base branch
from
feature/#7-week4
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
1efe18e
feature/#7: okhttp, retrofit 세팅
kangyein9892 22f1246
feature/#7: baseReponseDto 설정
kangyein9892 acbaefb
feature/#7: signUp response,request dto 및 entity 추가
kangyein9892 864129f
feature/#7: AuthService 및 모듈 구현
kangyein9892 2196e39
feature/#7: AuthDataSoruce 구현
kangyein9892 0d5c56f
feature/#7: AuthRepository 구현 및 모듈 구현
kangyein9892 1d9ec2e
feature/#7: 닉네임 화면 구현 및 회원가입 api 연결
kangyein9892 e8e0731
feature/#7: signIn response, request dto 및 entity 추가
kangyein9892 7accf99
feature/#7: authService에 signIn 함수 추가
kangyein9892 399cc15
feature/#7: authDataSource에 signIn 추가
kangyein9892 d3a5c1f
feature/#7: authRepository에 signIn 추가
kangyein9892 0f0427e
refactor/#7: userLocalDataSource로 수정
kangyein9892 97f36de
feature/#7: signIn api 뷰에 연결
kangyein9892 eb7fd68
delete/#7: home에서 안쓰는 userRepository 관련 코드 삭제
kangyein9892 4c6280a
chore/#7: userId Long 타입으로 수정
kangyein9892 296b952
feature/#7: AuthInterceptor okhttp intercept 헤더 추가
kangyein9892 7daaeb6
chore/#7: jsonToErrorMessage 패키지 위치 변경
kangyein9892 36ad7f3
feature/#7: mynickname response dto, entity 추가
kangyein9892 076171e
chore/#7: authService에 헤더 필요 없으므로 @Tag 추가
kangyein9892 2d8039c
feature/#7: userService 구현
kangyein9892 ae63048
feature/#7: userRemoteDataSource 구현
kangyein9892 3fbe91e
feature/#7: UserRepository 구현
kangyein9892 35cd3ab
feature/#7: my 화면에 닉네임 반영
kangyein9892 b0d38e3
chore/#7: delay 시간 추가
kangyein9892 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
data/src/main/java/org/sopt/at/data/datasource/AuthDataSource.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package org.sopt.at.data.datasource | ||
|
|
||
| import org.sopt.at.data.dto.request.SignInRequestDto | ||
| import org.sopt.at.data.dto.request.SignUpRequestDto | ||
| import org.sopt.at.data.service.AuthService | ||
| import javax.inject.Inject | ||
|
|
||
| internal class AuthDataSource @Inject constructor( | ||
| private val authService: AuthService | ||
| ) { | ||
| suspend fun signUp(signUpRequest: SignUpRequestDto) = authService.signUp(signUpRequest) | ||
|
|
||
| suspend fun signIn(signInRequest: SignInRequestDto) = authService.signIn(signInRequest) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
data/src/main/java/org/sopt/at/data/datasource/UserRemoteDataSource.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package org.sopt.at.data.datasource | ||
|
|
||
| import org.sopt.at.data.service.UserService | ||
| import javax.inject.Inject | ||
|
|
||
| internal class UserRemoteDataSource @Inject constructor( | ||
| private val userService: UserService | ||
| ) { | ||
| suspend fun getMyNickName() = userService.getMyNickName() | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| package org.sopt.at.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.at.data.BuildConfig | ||
| import org.sopt.at.data.datasource.UserLocalDataSource | ||
| import org.sopt.at.data.service.AuthInterceptor | ||
| import retrofit2.Converter | ||
| import retrofit2.Retrofit | ||
| import java.util.concurrent.TimeUnit | ||
| import javax.inject.Singleton | ||
|
|
||
| @Module | ||
| @InstallIn(SingletonComponent::class) | ||
| internal object NetworkModule { | ||
|
|
||
| @Provides | ||
| @Singleton | ||
| fun providesLoggingInterceptor() = HttpLoggingInterceptor().apply { | ||
| level = if (BuildConfig.DEBUG) { | ||
| HttpLoggingInterceptor.Level.BODY | ||
| } else { | ||
| HttpLoggingInterceptor.Level.NONE | ||
| } | ||
|
|
||
| } | ||
|
|
||
| @Provides | ||
| @Singleton | ||
| fun providesOkHttpClient( | ||
| loggingInterceptor: HttpLoggingInterceptor, | ||
| authInterceptor: AuthInterceptor | ||
| ): OkHttpClient = OkHttpClient.Builder() | ||
| .connectTimeout(10, TimeUnit.SECONDS) | ||
| .readTimeout(10, TimeUnit.SECONDS) | ||
| .addInterceptor(authInterceptor) | ||
| .addInterceptor(loggingInterceptor) | ||
| .build() | ||
|
|
||
| @Provides | ||
| @Singleton | ||
| fun provideAuthInterceptor(userLocalDataSource: UserLocalDataSource): AuthInterceptor = | ||
| AuthInterceptor(userLocalDataSource) | ||
|
|
||
| @Provides | ||
| @Singleton | ||
| fun providesConverterFactory(): Converter.Factory = Json.asConverterFactory("application/json".toMediaType()) | ||
|
|
||
| @Provides | ||
| @Singleton | ||
| fun providesRetrofit( | ||
| client: OkHttpClient, | ||
| converterFactory: Converter.Factory | ||
| ): Retrofit = Retrofit.Builder() | ||
| .baseUrl(BuildConfig.BASE_URL) | ||
| .addConverterFactory(converterFactory) | ||
| .client(client) | ||
| .build() | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package org.sopt.at.data.di | ||
|
|
||
| import dagger.Module | ||
| import dagger.Provides | ||
| import dagger.hilt.InstallIn | ||
| import dagger.hilt.components.SingletonComponent | ||
| import org.sopt.at.data.service.AuthService | ||
| import org.sopt.at.data.service.UserService | ||
| import retrofit2.Retrofit | ||
| import javax.inject.Singleton | ||
|
|
||
| @Module | ||
| @InstallIn(SingletonComponent::class) | ||
| internal object ServiceModule { | ||
| @Provides | ||
| @Singleton | ||
| fun provideAuthService(retrofit: Retrofit): AuthService = | ||
| retrofit.create(AuthService::class.java) | ||
|
|
||
| @Provides | ||
| @Singleton | ||
| fun provideUserService(retrofit: Retrofit): UserService = | ||
| retrofit.create(UserService::class.java) | ||
| } |
15 changes: 15 additions & 0 deletions
15
data/src/main/java/org/sopt/at/data/dto/request/SignInRequestDto.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package org.sopt.at.data.dto.request | ||
|
|
||
| import kotlinx.serialization.Serializable | ||
| import org.sopt.at.entity.SignInEntity | ||
|
|
||
| @Serializable | ||
| internal data class SignInRequestDto( | ||
| val loginId: String, | ||
| val password: String | ||
| ) | ||
|
|
||
| internal fun SignInEntity.toDto() = SignInRequestDto( | ||
| loginId = id, | ||
| password = password | ||
| ) |
17 changes: 17 additions & 0 deletions
17
data/src/main/java/org/sopt/at/data/dto/request/SignUpRequestDto.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package org.sopt.at.data.dto.request | ||
|
|
||
| import kotlinx.serialization.Serializable | ||
| import org.sopt.at.entity.SignUpEntity | ||
|
|
||
| @Serializable | ||
| internal data class SignUpRequestDto( | ||
| val loginId: String, | ||
| val nickname: String, | ||
| val password: String | ||
| ) | ||
|
|
||
| internal fun SignUpEntity.toDto() = SignUpRequestDto( | ||
| loginId = loginId, | ||
| nickname = nickname, | ||
| password = password | ||
| ) |
11 changes: 11 additions & 0 deletions
11
data/src/main/java/org/sopt/at/data/dto/response/BaseResponseDto.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package org.sopt.at.data.dto.response | ||
|
|
||
| import kotlinx.serialization.Serializable | ||
|
|
||
| @Serializable | ||
| data class BaseResponseDto<T>( | ||
| val success: Boolean, | ||
| val code: String, | ||
| val message: String, | ||
| val data: T? | ||
| ) |
13 changes: 13 additions & 0 deletions
13
data/src/main/java/org/sopt/at/data/dto/response/MyNicknameResponseDto.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package org.sopt.at.data.dto.response | ||
|
|
||
| import kotlinx.serialization.Serializable | ||
| import org.sopt.at.entity.MyNicknameEntity | ||
|
|
||
| @Serializable | ||
| data class MyNicknameResponseDto( | ||
| val nickname: String | ||
| ) { | ||
| fun toEntity() = MyNicknameEntity( | ||
| nickname = nickname | ||
| ) | ||
| } |
13 changes: 13 additions & 0 deletions
13
data/src/main/java/org/sopt/at/data/dto/response/SignInResponseDto.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package org.sopt.at.data.dto.response | ||
|
|
||
| import kotlinx.serialization.Serializable | ||
| import org.sopt.at.entity.SignInUserEntity | ||
|
|
||
| @Serializable | ||
| data class SignInResponseDto( | ||
| val userId: Long | ||
| ) { | ||
| fun toEntity() = SignInUserEntity( | ||
| userId = userId | ||
| ) | ||
| } |
15 changes: 15 additions & 0 deletions
15
data/src/main/java/org/sopt/at/data/dto/response/SignUpResponseDto.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package org.sopt.at.data.dto.response | ||
|
|
||
| import kotlinx.serialization.Serializable | ||
| import org.sopt.at.entity.SignUpUserEntity | ||
|
|
||
| @Serializable | ||
| data class SignUpResponseDto( | ||
| val userId: Long, | ||
| val nickname: String | ||
| ) { | ||
| fun toEntity() = SignUpUserEntity( | ||
| userId = userId, | ||
| nickname = nickname | ||
| ) | ||
| } |
66 changes: 66 additions & 0 deletions
66
data/src/main/java/org/sopt/at/data/repository/AuthRepositoryImpl.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| package org.sopt.at.data.repository | ||
|
|
||
| import org.sopt.at.data.datasource.AuthDataSource | ||
| import org.sopt.at.data.dto.request.toDto | ||
| import org.sopt.at.data.service.jsonToErrorMessage | ||
| import org.sopt.at.entity.ApiException | ||
| import org.sopt.at.entity.SignInEntity | ||
| import org.sopt.at.entity.SignInUserEntity | ||
| import org.sopt.at.entity.SignUpEntity | ||
| import org.sopt.at.entity.SignUpUserEntity | ||
| import org.sopt.at.repository.AuthRepository | ||
| import retrofit2.HttpException | ||
| import javax.inject.Inject | ||
|
|
||
| internal class AuthRepositoryImpl @Inject constructor( | ||
| private val authDataSource: AuthDataSource | ||
| ) : AuthRepository { | ||
|
|
||
| override suspend fun signUp(signUpData: SignUpEntity): Result<SignUpUserEntity> = | ||
| runCatching { | ||
| val response = authDataSource.signUp(signUpData.toDto()) | ||
|
|
||
| if (!response.success || response.data == null) { | ||
| throw ApiException(response.message) | ||
| } | ||
|
|
||
| response.data.toEntity() | ||
| }.recoverCatching { throwable -> | ||
| when (throwable) { | ||
| is HttpException -> { | ||
| val errorBodyStr = throwable.response()?.errorBody()?.string() | ||
|
|
||
| val message = jsonToErrorMessage(errorBodyStr) | ||
| ?: "Unknown error" | ||
|
|
||
| throw ApiException(message) | ||
| } | ||
|
|
||
| else -> throw throwable | ||
| } | ||
| } | ||
|
|
||
| override suspend fun signIn(signInEntity: SignInEntity): Result<SignInUserEntity?> = | ||
| runCatching { | ||
| val response = authDataSource.signIn(signInEntity.toDto()) | ||
|
|
||
| if (!response.success || response.data == null) { | ||
| throw ApiException(response.message) | ||
| } | ||
|
|
||
| response.data.toEntity() | ||
| }.recoverCatching { throwable -> | ||
| when (throwable) { | ||
| is HttpException -> { | ||
| val errorBodyStr = throwable.response()?.errorBody()?.string() | ||
|
|
||
| val message = jsonToErrorMessage(errorBodyStr) | ||
| ?: "Unknown error" | ||
|
|
||
| throw ApiException(message) | ||
| } | ||
|
|
||
| else -> throw throwable | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Try catch 문으로 사용했었는데 runCatching으로 체이닝이 깔끔하게 이뤄지네요 하나 배워갑니다!
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.
저도 현재 화면에서 try-catch 방식으로 예외 처리를 하고 있는데요, 예인님처럼 runCatching을 쓰면 비동기 체이닝이 더 깔끔해 보이네용 .ᐟ
혹시 팀에서 선호하는 방식이 따로 있나요, 아니면 상황에 따라 자유롭게 쓰면 될까요?