Skip to content

Commit

Permalink
#86 feat : BaseResponse 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
yy0ung committed Nov 22, 2023
1 parent b54b95e commit 874b3f7
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 43 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.avengers.nibobnebob.data.model.response

data class BaseResponse<T>(
val data: 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 BaseEdit(
val data: MyDefaultInfoResponse,
val message: String,
val statusCode: Int
)

data class MyDefaultInfoResponse(
val userInfo: UserEditInfo
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.avengers.nibobnebob.data.remote

import com.avengers.nibobnebob.data.model.request.EditMyInfoRequest
import com.avengers.nibobnebob.data.model.response.Base
import com.avengers.nibobnebob.data.model.response.BaseEdit
import com.avengers.nibobnebob.data.model.response.BaseResponse
import com.avengers.nibobnebob.data.model.response.MyDefaultInfoResponse
import com.avengers.nibobnebob.data.model.response.MyInfoResponse
import retrofit2.Response
Expand All @@ -14,18 +13,18 @@ import retrofit2.http.PUT
interface MyPageApi {
@GET("api/user/details")
suspend fun getMyInfo(
@Header("Authorization") token : String,
) : Response<Base>
@Header("Authorization") token: String,
): Response<BaseResponse<MyInfoResponse>>

@GET("api/user")
suspend fun getMyDefaultInfo(
@Header("Authorization") token : String,
) : Response<BaseEdit>
@Header("Authorization") token: String,
): Response<BaseResponse<MyDefaultInfoResponse>>

@PUT("api/user")
suspend fun editMyInfo(
@Header("Authorization") token : String,
@Body data : EditMyInfoRequest
) : Response<Unit>
@Header("Authorization") token: String,
@Body data: EditMyInfoRequest
): Response<Unit>

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ package com.avengers.nibobnebob.data.repository

import com.avengers.nibobnebob.data.model.BaseState
import com.avengers.nibobnebob.data.model.request.EditMyInfoRequest
import com.avengers.nibobnebob.data.model.response.Base
import com.avengers.nibobnebob.data.model.response.BaseEdit
import com.avengers.nibobnebob.data.model.response.BaseResponse
import com.avengers.nibobnebob.data.model.response.MyDefaultInfoResponse
import com.avengers.nibobnebob.data.model.response.MyInfoResponse
import kotlinx.coroutines.flow.Flow

interface MyPageRepository {
fun getMyInfo(): Flow<BaseState<Base>>
fun getMyInfo(): Flow<BaseState<BaseResponse<MyInfoResponse>>>

fun getMyDefaultInfo(): Flow<BaseState<BaseEdit>>
fun getMyDefaultInfo(): Flow<BaseState<BaseResponse<MyDefaultInfoResponse>>>

fun editMyInfo(data: EditMyInfoRequest): Flow<BaseState<Unit>>

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

import android.util.Log
import com.avengers.nibobnebob.data.model.BaseState
import com.avengers.nibobnebob.data.model.request.EditMyInfoRequest
import com.avengers.nibobnebob.data.model.response.Base
import com.avengers.nibobnebob.data.model.response.BaseEdit
import com.avengers.nibobnebob.data.model.response.BaseResponse
import com.avengers.nibobnebob.data.model.response.MyDefaultInfoResponse
import com.avengers.nibobnebob.data.model.response.MyInfoResponse
import com.avengers.nibobnebob.data.model.runRemote
import com.avengers.nibobnebob.data.remote.MyPageApi
import com.avengers.nibobnebob.data.repository.MyPageRepository
Expand All @@ -14,15 +13,16 @@ import kotlinx.coroutines.flow.flow
import javax.inject.Inject

class MyPageRepositoryImpl @Inject constructor(private val api: MyPageApi) : MyPageRepository {
private val token = "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwiaWQiOjIsImlhdCI6MjAxNjIzOTAyMn0.VMvtPcawKVzNyOV08lrArxUvM-XxowWIknsPFkjRTws"
override fun getMyInfo(): Flow<BaseState<Base>> = flow {
api.getMyInfo(token).apply { Log.d("TEST", "///${body()}") }
private val token =
"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwiaWQiOjIsImlhdCI6MjAxNjIzOTAyMn0.VMvtPcawKVzNyOV08lrArxUvM-XxowWIknsPFkjRTws"

override fun getMyInfo(): Flow<BaseState<BaseResponse<MyInfoResponse>>> = flow {
val result = runRemote { api.getMyInfo(token) }
emit(result)

}

override fun getMyDefaultInfo(): Flow<BaseState<BaseEdit>> = flow {
override fun getMyDefaultInfo(): Flow<BaseState<BaseResponse<MyDefaultInfoResponse>>> = flow {
val result = runRemote { api.getMyDefaultInfo(token) }
emit(result)
}
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.toUiMyPageInfoData().apply {
it.data.data.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.toUiMyPageEditInfoData().apply {
it.data.data.toUiMyPageEditInfoData().apply {
nickState.emit(nickName)
locationState.emit(location.indexOf(location))
locationTextState.emit(location)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package com.avengers.nibobnebob.presentation.ui.main.mypage.mapper

import com.avengers.nibobnebob.data.model.response.Base
import com.avengers.nibobnebob.data.model.response.MyInfoResponse
import com.avengers.nibobnebob.presentation.ui.main.mypage.model.UiMyPageInfoData

internal fun Base.toUiMyPageInfoData() = UiMyPageInfoData(
nickName = data.userInfo.nickName,
age = data.userInfo.birthdate,
location = data.userInfo.region,
gender = if(data.userInfo.isMale) "" else ""
internal fun MyInfoResponse.toUiMyPageInfoData() = UiMyPageInfoData(
nickName = userInfo.nickName,
age = userInfo.birthdate,
location = userInfo.region,
gender = if(userInfo.isMale) "" else ""
)
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package com.avengers.nibobnebob.presentation.ui.main.mypage.mapper

import com.avengers.nibobnebob.data.model.response.BaseEdit
import com.avengers.nibobnebob.data.model.response.MyDefaultInfoResponse
import com.avengers.nibobnebob.data.model.response.MyInfoResponse
import com.avengers.nibobnebob.presentation.ui.main.mypage.model.UiMyPageEditInfoData

fun BaseEdit.toUiMyPageEditInfoData() = UiMyPageEditInfoData(
nickName = data.userInfo.nickName,
email = data.userInfo.email,
provider = data.userInfo.provider,
birth = data.userInfo.birthdate,
location = data.userInfo.region,
gender = data.userInfo.isMale
fun MyDefaultInfoResponse.toUiMyPageEditInfoData() = UiMyPageEditInfoData(
nickName = userInfo.nickName,
email = userInfo.email,
provider = userInfo.provider,
birth = userInfo.birthdate,
location = userInfo.region,
gender = userInfo.isMale
)

0 comments on commit 874b3f7

Please sign in to comment.