Skip to content

Commit

Permalink
#86 feat : 변경된 BaseResponse 적용
Browse files Browse the repository at this point in the history
Co-authored-by: BENDENG1 <[email protected]>
Co-authored-by: yy0ung <[email protected]>
  • Loading branch information
3 people committed Nov 22, 2023
1 parent 46a89f2 commit 48c0bc7
Show file tree
Hide file tree
Showing 16 changed files with 30 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ object NetworkModule {
.readTimeout(3000, TimeUnit.MILLISECONDS)
.connectTimeout(3000, TimeUnit.MILLISECONDS)
.addInterceptor(httpLoggingInterceptor)
//.addNetworkInterceptor(accessTokenInterceptor)
//.addInterceptor(bearerInterceptor)
.addNetworkInterceptor(accessTokenInterceptor)
.addInterceptor(bearerInterceptor)
.build()
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.avengers.nibobnebob.data.model

import android.util.Log
import com.google.gson.Gson
import retrofit2.Response

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.avengers.nibobnebob.data.model.response

import com.google.gson.annotations.SerializedName

data class BaseResponse<T>(
val data: T,
@SerializedName("data")
val body: T,
val message: String,
val statusCode: Int,
)
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
package com.avengers.nibobnebob.data.model.response

data class Base(
val data: MyInfoResponse,
val message: String,
val statusCode: Int
)


data class MyInfoResponse(
val userInfo: UserInfo
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.avengers.nibobnebob.data.remote

import com.avengers.nibobnebob.data.model.request.DetailSignupRequest
import com.avengers.nibobnebob.data.model.response.BaseResponse
import com.avengers.nibobnebob.data.model.response.NaverLoginResponse
import retrofit2.Response
import retrofit2.http.Body
Expand All @@ -14,5 +15,5 @@ interface IntroApi {
): Response<Unit>

@POST("api/auth/social-login")
suspend fun loginNaver(): Response<NaverLoginResponse>
suspend fun loginNaver(): Response<BaseResponse<NaverLoginResponse>>
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.avengers.nibobnebob.data.remote

import com.avengers.nibobnebob.data.model.response.BaseResponse
import com.avengers.nibobnebob.data.model.response.NaverLoginResponse
import retrofit2.Response
import retrofit2.http.POST

interface RefreshApi {

@POST("토큰 갱신 url")
suspend fun refreshToken(refreshToken : String) : Response<NaverLoginResponse>
suspend fun refreshToken(refreshToken : String) : Response<BaseResponse<NaverLoginResponse>>
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.avengers.nibobnebob.data.remote

import com.avengers.nibobnebob.data.model.response.BaseResponse
import com.avengers.nibobnebob.data.model.response.ValidateResponse
import retrofit2.Response
import retrofit2.http.GET
Expand All @@ -10,10 +11,10 @@ interface ValidationApi {
@GET("/api/user/nickname/{nickname}/exists")
suspend fun nickValidation(
@Path("nickname") nickname: String
): Response<ValidateResponse>
): Response<BaseResponse<ValidateResponse>>

@GET("/api/user/email/{email}/exists")
suspend fun emailValidation(
@Path("email") email: String
): Response<ValidateResponse>
): Response<BaseResponse<ValidateResponse>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.avengers.nibobnebob.data.repository

import com.avengers.nibobnebob.data.model.BaseState
import com.avengers.nibobnebob.data.model.request.DetailSignupRequest
import com.avengers.nibobnebob.data.model.response.BaseResponse
import com.avengers.nibobnebob.data.model.response.NaverLoginResponse
import kotlinx.coroutines.flow.Flow

Expand All @@ -11,5 +12,5 @@ interface IntroRepository {
body: DetailSignupRequest
): Flow<BaseState<Unit>>

fun loginNaver(): Flow<BaseState<NaverLoginResponse>>
fun loginNaver(): Flow<BaseState<BaseResponse<NaverLoginResponse>>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.avengers.nibobnebob.data.repository

import com.avengers.nibobnebob.data.model.BaseState
import com.avengers.nibobnebob.data.model.request.DetailSignupRequest
import com.avengers.nibobnebob.data.model.response.BaseResponse
import com.avengers.nibobnebob.data.model.response.NaverLoginResponse
import com.avengers.nibobnebob.data.model.runRemote
import com.avengers.nibobnebob.data.remote.IntroApi
Expand All @@ -18,7 +19,7 @@ class IntroRepositoryImpl @Inject constructor(
emit(result)
}

override fun loginNaver(): Flow<BaseState<NaverLoginResponse>> = flow {
override fun loginNaver(): Flow<BaseState<BaseResponse<NaverLoginResponse>>> = flow {
val result = runRemote { api.loginNaver() }
emit(result)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package com.avengers.nibobnebob.data.repository

import com.avengers.nibobnebob.data.model.BaseState
import com.avengers.nibobnebob.data.model.response.BaseResponse
import com.avengers.nibobnebob.data.model.response.ValidateResponse
import kotlinx.coroutines.flow.Flow

interface ValidationRepository {

fun nickValidation(
nickName: String
): Flow<BaseState<ValidateResponse>>
): Flow<BaseState<BaseResponse<ValidateResponse>>>

fun emailValidation(
email: String
): Flow<BaseState<ValidateResponse>>
): Flow<BaseState<BaseResponse<ValidateResponse>>>
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.avengers.nibobnebob.data.repository

import com.avengers.nibobnebob.data.model.BaseState
import com.avengers.nibobnebob.data.model.response.BaseResponse
import com.avengers.nibobnebob.data.model.response.ValidateResponse
import com.avengers.nibobnebob.data.model.runRemote
import com.avengers.nibobnebob.data.remote.ValidationApi
Expand All @@ -12,12 +13,12 @@ class ValidationRepositoryImpl @Inject constructor(
private val api: ValidationApi
) : ValidationRepository {

override fun nickValidation(nickName: String): Flow<BaseState<ValidateResponse>> = flow {
override fun nickValidation(nickName: String): Flow<BaseState<BaseResponse<ValidateResponse>>> = flow {
val result = runRemote { api.nickValidation(nickName) }
emit(result)
}

override fun emailValidation(email: String): Flow<BaseState<ValidateResponse>> = flow {
override fun emailValidation(email: String): Flow<BaseState<BaseResponse<ValidateResponse>>> = flow {
val result = runRemote { api.nickValidation(email) }
emit(result)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ class LoginViewModel @Inject constructor(
when(it){
is BaseState.Success -> {
dataStoreManager.putAutoLogin(true)
dataStoreManager.putAccessToken(it.data.accessToken.toString())
dataStoreManager.putRefreshToken(it.data.refreshToken.toString())
dataStoreManager.putAccessToken(it.data.body.accessToken.toString())
dataStoreManager.putRefreshToken(it.data.body.refreshToken.toString())

_events.emit(LoginEvent.NavigateToMain)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class DetailSignupViewModel @Inject constructor(

when (it) {
is BaseState.Success -> {
if (it.data.isExist) {
if (it.data.body.isExist) {
nickValidation.value = false
_uiState.update { state ->
state.copy(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class MyPageViewModel @Inject constructor(
myPageRepository.getMyInfo().onEach {
when (it) {
is BaseState.Success -> {
it.data.data.toUiMyPageInfoData().apply {
it.data.body.toUiMyPageInfoData().apply {
_uiState.update { state ->
state.copy(
nickName = nickName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class EditProfileViewModel @Inject constructor(
when (it) {
is BaseState.Success -> {

it.data.data.toUiMyPageEditInfoData().apply {
it.data.body.toUiMyPageEditInfoData().apply {
nickState.emit(nickName)
locationState.emit(location.indexOf(location))
locationTextState.emit(location)
Expand Down Expand Up @@ -127,7 +127,7 @@ class EditProfileViewModel @Inject constructor(
validationRepository.nickValidation(nickState.value).onEach {
when (it) {
is BaseState.Success -> {
if (it.data.isExist) {
if (it.data.body.isExist) {

_uiState.value = uiState.value.copy(
nickName = InputState(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class SplashViewModel @Inject constructor(
if (autoLogin == true && accessToken != "") {
_events.emit(NavigationEvent.NavigateToMain)
} else {
_events.emit(NavigationEvent.NavigateToMain)
_events.emit(NavigationEvent.NavigateToIntro)
}
}
}
Expand Down

0 comments on commit 48c0bc7

Please sign in to comment.