Skip to content

Commit

Permalink
[Feat] 마이 페이지 조회 API 구현 (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
arinming committed May 3, 2024
1 parent bc186b0 commit 72ce0d5
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class AuthInterceptor : Interceptor {
val originalRequest = chain.request()

val newRequest = originalRequest.newBuilder()
.addHeader("memberId", "495")
.addHeader("memberId", "514")
.build()

return chain.proceed(newRequest)
Expand Down
19 changes: 13 additions & 6 deletions app/src/main/java/com/sopt/now/compose/ui/myPage/MyPageScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,26 @@ import androidx.compose.foundation.gestures.scrollable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableFloatStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel
import com.sopt.now.compose.R

@Composable
fun MyPageScreen() {
fun MyPageScreen(
myPageViewModel: MyPageViewModel = viewModel(),
) {
val infoState by myPageViewModel.infoState.collectAsState()
var offset by remember { mutableFloatStateOf(0f) }

Column(modifier = Modifier
Expand All @@ -36,11 +44,10 @@ fun MyPageScreen() {
contentDescription = null,
modifier = Modifier.aspectRatio(3f / 4f)
)
Column {
// Text(text = id)
// Text(text = pw)
// Text(text = nickname)
// Text(text = mbti)
Column(modifier = Modifier.padding(16.dp)) {
Text(text = infoState.data.authenticationId)
Text(text = infoState.data.nickname)
Text(text = infoState.data.phone)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.sopt.now.compose.ui.myPage

import android.util.Log
import androidx.lifecycle.ViewModel
import com.sopt.now.compose.data.model.ResponseInfoDto
import com.sopt.now.compose.data.model.UserInfo
import com.sopt.now.compose.data.module.ServicePool
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.update
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response

class MyPageViewModel : ViewModel() {
private val authService by lazy { ServicePool.authService }

private val _infoState =
MutableStateFlow(
ResponseInfoDto(
code = 0,
message = "",
data = UserInfo(authenticationId = "", nickname = "", phone = "")
)
)
val infoState = _infoState.asStateFlow()

init {
fetchInfo()
}

private fun fetchInfo() {
authService.memberInfo().enqueue(object : Callback<ResponseInfoDto> {
override fun onResponse(
call: Call<ResponseInfoDto>,
response: Response<ResponseInfoDto>,
) {
if (response.isSuccessful) {
val data = response.body()
if (data != null) {
_infoState.update {
data
}
}
}
}

override fun onFailure(call: Call<ResponseInfoDto>, t: Throwable) {
Log.e("MyPageError", "${t.message}")
}
})
}
}

0 comments on commit 72ce0d5

Please sign in to comment.