-
Notifications
You must be signed in to change notification settings - Fork 0
[Refactor] API 서비스 패키지 구조 개편 #123 #127
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
Changes from all commits
326f2fc
59c62f7
a259ce3
dde054d
74d8ccb
4777d19
c2172b7
69c0d13
fd082e4
0809f62
f11aef6
8203396
afbd7fc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| package com.konkuk.medicarecall.data.api.auth | ||
|
|
||
| import com.konkuk.medicarecall.data.dto.request.CertificationCodeRequestDto | ||
| import com.konkuk.medicarecall.data.dto.request.PhoneNumberConfirmRequestDto | ||
| import com.konkuk.medicarecall.data.dto.request.TokenRefreshRequestDto | ||
| import com.konkuk.medicarecall.data.dto.response.MemberTokenResponseDto | ||
| import com.konkuk.medicarecall.data.dto.response.VerificationResponseDto | ||
| import retrofit2.Response | ||
| import retrofit2.http.Body | ||
| import retrofit2.http.Header | ||
| import retrofit2.http.POST | ||
|
|
||
| /** 인증과 관련된 API 모음 (토큰 갱신, 본인인증, 로그아웃) */ | ||
|
|
||
| interface AuthService { | ||
| @POST("auth/refresh") | ||
| suspend fun refreshToken(@Body req: TokenRefreshRequestDto) | ||
| : Response<MemberTokenResponseDto> | ||
|
|
||
| @POST("verifications") | ||
| suspend fun requestCertificationCode(@Body req: CertificationCodeRequestDto) | ||
| : Response<Unit> | ||
|
|
||
| @POST("verifications/confirmation") | ||
| suspend fun confirmPhoneNumber(@Body req: PhoneNumberConfirmRequestDto) | ||
| : Response<VerificationResponseDto> | ||
|
|
||
| @POST("auth/logout") | ||
| suspend fun logout( | ||
| @Header("Authorization") authorization: String // "Bearer <refresh>" | ||
| ): Response<Unit> | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ package com.konkuk.medicarecall.data.di | |
|
|
||
| import android.util.Log | ||
| import com.konkuk.medicarecall.BuildConfig | ||
| import com.konkuk.medicarecall.data.api.TokenRefreshService | ||
| import com.konkuk.medicarecall.data.api.auth.AuthService | ||
| import com.konkuk.medicarecall.data.network.AuthAuthenticator | ||
| import com.konkuk.medicarecall.data.network.AuthInterceptor | ||
| import com.konkuk.medicarecall.data.repository.DataStoreRepository | ||
|
|
@@ -34,9 +34,9 @@ object NetworkModule { | |
| @Singleton | ||
| fun provideAuthAuthenticator( | ||
| dataStoreRepository: DataStoreRepository, | ||
| tokenRefreshService: dagger.Lazy<TokenRefreshService>, | ||
| authService: dagger.Lazy<AuthService> | ||
| ): AuthAuthenticator { | ||
| return AuthAuthenticator(dataStoreRepository, tokenRefreshService) | ||
| return AuthAuthenticator(dataStoreRepository, authService) | ||
|
Comment on lines
35
to
+39
Contributor
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. 여기 코드에서 순환 의존성 때문에 Lazy 로 선언하신 것 같습니다.
위와 같은 상황을 방지하게 위해 지연 생성을 하기 보단, tokenRepository를 사용해서 하면 좋을 것 같습니다! 현재 PR 에 대한 내용은 아니니 추후 참고용으로 달아놓을게요!
Collaborator
Author
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. 피드백 감사합니다! 말씀 주신 부분 추후 리팩토링 시 참고하면 좋을 것 같아요 |
||
| } | ||
|
|
||
| @Provides | ||
|
|
@@ -52,11 +52,13 @@ object NetworkModule { | |
| fun provideOkHttpClient( | ||
| authInterceptor: Interceptor, | ||
| loggingInterceptor: HttpLoggingInterceptor, | ||
| authAuthenticator: AuthAuthenticator | ||
| ): OkHttpClient { | ||
| return OkHttpClient.Builder() | ||
| .readTimeout(20, TimeUnit.SECONDS) | ||
| .addInterceptor(authInterceptor) | ||
| .addInterceptor(loggingInterceptor) | ||
| .authenticator(authAuthenticator) | ||
| .build() | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,9 @@ | ||
| package com.konkuk.medicarecall.data.network | ||
|
|
||
| import android.util.Log | ||
| import com.konkuk.medicarecall.data.api.TokenRefreshService | ||
| import com.konkuk.medicarecall.data.api.auth.AuthService | ||
| import com.konkuk.medicarecall.data.dto.request.TokenRefreshRequestDto | ||
| import com.konkuk.medicarecall.data.repository.DataStoreRepository | ||
| import dagger.Lazy | ||
| import kotlinx.coroutines.runBlocking | ||
| import okhttp3.Authenticator | ||
| import okhttp3.Request | ||
|
|
@@ -14,7 +13,7 @@ import javax.inject.Inject | |
|
|
||
| class AuthAuthenticator @Inject constructor( | ||
| private val dataStoreRepository: DataStoreRepository, | ||
| private val tokenRefreshService: Lazy<TokenRefreshService> // 순환 참조 방지를 위해 Lazy 주입 | ||
| private val authService: dagger.Lazy<AuthService> //순환 참조 방지 | ||
| ) : Authenticator { | ||
|
|
||
| override fun authenticate(route: Route?, response: Response): Request? { | ||
|
|
@@ -46,7 +45,7 @@ class AuthAuthenticator @Inject constructor( | |
|
|
||
| // 6. 토큰 갱신 API 호출 (runBlocking 사용) | ||
| val refreshResponse = runBlocking { | ||
| tokenRefreshService.get().refreshToken(TokenRefreshRequestDto(refreshToken)) | ||
| authService.get().refreshToken(TokenRefreshRequestDto(refreshToken)) | ||
| } | ||
|
Comment on lines
47
to
49
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. 🧩 Analysis chain리프레시 호출이 동일 OkHttp(인터셉터/Authentictor 포함)를 타는지 확인 필요
🏁 Script executed: #!/bin/bash
# AuthService 제공자/클라이언트 배선 확인
rg -nP --type=kt -C3 'provideAuthService|Retrofit\\s*\\.\\s*create\\(\\s*AuthService::class' app
# AuthInterceptor가 리프레시/인증 경로를 스킵하는지 확인
rg -nP --type=kt -C3 'class\\s+AuthInterceptor\\b|intercept\\(|encodedPath|auth/refresh|verification' app
# 별도 no-auth/refresh 클라이언트 존재 여부
rg -nP --type=kt -C2 '@Named\\(|@Qualifier|noAuth|unauth|refresh' appLength of output: 218 스크립트 패턴의 괄호 이스케이프가 빠져 에러가 발생한 것 같습니다. 아래 수정된 스크립트를 실행해 리프레시 전용 클라이언트 분리 여부와 인터셉터/Authenticator 스킵 로직을 확인해 주세요. 🏁 Script executed: #!/bin/bash
# AuthService 제공자/클라이언트 배선 확인
rg -nP --type=kt -C3 'provideAuthService' app
rg -nP --type=kt -C3 'Retrofit\s*\.create\(\s*AuthService::class\s*\)' app
# AuthInterceptor가 리프레시/인증 경로를 스킵하는지 확인
rg -nP --type=kt -C3 'class\s+AuthInterceptor' app
rg -nP --type=kt -C3 'fun\s+intercept' app
rg -nP --type=kt -C3 'encodedPath.*refresh' app
# 별도 no-auth/refresh 클라이언트 존재 여부
rg -nP --type=kt -C2 '@Named.*(noAuth|unauth|refresh)' appLength of output: 161 ripgrep에서 🏁 Script executed: #!/bin/bash
# AuthService 제공자/클라이언트 배선 확인
rg -g '*.kt' -n -C3 'provideAuthService' app
rg -g '*.kt' -n -C3 'Retrofit\s*\.create\(\s*AuthService::class\s*\)' app
# AuthInterceptor가 리프레시/인증 경로를 스킵하는지 확인
rg -g '*.kt' -n -C3 'class\s+AuthInterceptor\b' app
rg -g '*.kt' -n -C3 'fun\s+intercept\b' app
rg -g '*.kt' -n -C3 'encodedPath.*refresh' app
# 별도 no-auth/refresh 클라이언트 존재 여부
rg -g '*.kt' -n -C2 '@Named.*(noAuth|unauth|refresh)' appLength of output: 2204 리프레시 전용 Retrofit 클라이언트 분리 필요 🤖 Prompt for AI Agents |
||
|
|
||
| return if (refreshResponse.isSuccessful && refreshResponse.body() != null) { | ||
|
|
@@ -74,4 +73,4 @@ class AuthAuthenticator @Inject constructor( | |
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
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.
이건 무슨 코드인가요..?
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.
Detekt 실행 시 빌드 실패가 발생해서 추가한 코드입니다!