Skip to content

Commit

Permalink
Merge pull request #63 from AdultOfNineteen/feat/issue-60
Browse files Browse the repository at this point in the history
[FEAT] 유저 닉네임 반영
  • Loading branch information
DongChyeon authored Mar 9, 2024
2 parents fbe2f50 + 750a269 commit 2a307e8
Show file tree
Hide file tree
Showing 13 changed files with 112 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import com.teamwiney.data.network.model.response.GoogleAccessToken
import com.teamwiney.data.network.model.response.SetPreferences
import com.teamwiney.data.network.model.response.SocialLogin
import com.teamwiney.data.network.model.response.UserInfo
import com.teamwiney.data.network.model.response.UserNickname
import com.teamwiney.data.network.model.response.VerifyAuthenticationMessage
import kotlinx.coroutines.flow.Flow

Expand Down Expand Up @@ -50,6 +51,12 @@ interface AuthDataSource {

fun getUserInfo(): Flow<ApiResult<CommonResponse<UserInfo>>>

fun getUserNickname(): Flow<ApiResult<CommonResponse<UserNickname>>>

fun modifyUserNickname(
nickname: String
): Flow<ApiResult<CommonResponse<String>>>

fun getConnections(): Flow<ApiResult<BaseResponse>>

fun registerFcmToken(fcmTokenRequest: FcmTokenRequest): Flow<ApiResult<BaseResponse>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ class AuthDataSourceImpl @Inject constructor(
emit(authService.getUserInfo())
}.flowOn(ioDispatcher)

override fun getUserNickname() = flow {
emit(authService.getUserNickname())
}.flowOn(ioDispatcher)

override fun modifyUserNickname(nickname: String) = flow {
emit(authService.modifyUserNickname(nickname))
}.flowOn(ioDispatcher)

override fun getConnections() = flow {
emit(authService.getConnections())
}.flowOn(ioDispatcher)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.teamwiney.data.network.model.response

import com.google.gson.annotations.SerializedName

data class UserNickname(
@SerializedName("nickname") val nickname: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import com.teamwiney.data.network.model.response.GoogleAccessToken
import com.teamwiney.data.network.model.response.SetPreferences
import com.teamwiney.data.network.model.response.SocialLogin
import com.teamwiney.data.network.model.response.UserInfo
import com.teamwiney.data.network.model.response.UserNickname
import com.teamwiney.data.network.model.response.VerifyAuthenticationMessage
import retrofit2.Response
import retrofit2.http.Body
Expand Down Expand Up @@ -74,6 +75,16 @@ interface AuthService {
@GET("/info")
suspend fun getUserInfo(): ApiResult<CommonResponse<UserInfo>>

/** 유저 닉네임 조회 API */
@GET("/nickname")
suspend fun getUserNickname(): ApiResult<CommonResponse<UserNickname>>

/** 유저 닉네임 변경 API */
@PATCH("/nickname")
suspend fun modifyUserNickname(
@Query("nickname") nickname: String
): ApiResult<CommonResponse<String>>

/** 토큰 리프레쉬 API */
@POST("/refresh")
suspend fun refreshToken(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.teamwiney.data.network.model.response.GoogleAccessToken
import com.teamwiney.data.network.model.response.SetPreferences
import com.teamwiney.data.network.model.response.SocialLogin
import com.teamwiney.data.network.model.response.UserInfo
import com.teamwiney.data.network.model.response.UserNickname
import com.teamwiney.data.network.model.response.VerifyAuthenticationMessage
import kotlinx.coroutines.flow.Flow

Expand Down Expand Up @@ -52,6 +53,12 @@ interface AuthRepository {

fun getUserInfo(): Flow<ApiResult<CommonResponse<UserInfo>>>

fun getUserNickname(): Flow<ApiResult<CommonResponse<UserNickname>>>

fun modifyUserNickname(
nickname: String
): Flow<ApiResult<CommonResponse<String>>>

fun getConnections(): Flow<ApiResult<BaseResponse>>

fun registerFcmToken(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ class AuthRepositoryImpl @Inject constructor(

override fun getUserInfo() = authDataSource.getUserInfo()

override fun getUserNickname() = authDataSource.getUserNickname()

override fun modifyUserNickname(
nickname: String
) = authDataSource.modifyUserNickname(nickname)

override fun getConnections() = authDataSource.getConnections()

override fun registerFcmToken(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class AnalysisContract {

data class State(
val isLoading: Boolean = false,
val nickname: String = "",
val tasteAnalysis: TasteAnalysis = TasteAnalysis()
) : UiState

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.ContentScale
Expand All @@ -28,6 +29,7 @@ import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.withStyle
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.navigation.navOptions
import com.teamwiney.analysis.component.AnalysisBottomContent
import com.teamwiney.analysis.component.AnalysisStartButton
Expand All @@ -48,11 +50,14 @@ fun AnalysisScreen(
bottomSheetState: WineyBottomSheetState,
viewModel: AnalysisViewModel
) {
val uiState by viewModel.uiState.collectAsStateWithLifecycle()
val effectFlow = viewModel.effect

val pagerState = rememberPagerState(pageCount = { 2 })

LaunchedEffect(true) {
viewModel.getUserNickname()

effectFlow.collectLatest { effect ->
when (effect) {
is AnalysisContract.Effect.NavigateTo -> {
Expand Down Expand Up @@ -112,7 +117,9 @@ fun AnalysisScreen(
viewModel::checkTastingNotes
)

1 -> AnalysisProgressContent {
1 -> AnalysisProgressContent(
nickname = uiState.nickname
) {
appState.navigate(
HomeDestinations.Analysis.RESULT,
navOptions {
Expand All @@ -129,6 +136,7 @@ fun AnalysisScreen(

@Composable
private fun AnalysisProgressContent(
nickname: String = "",
getAnalytics: () -> Unit = {}
) {
LaunchedEffect(true) {
Expand All @@ -148,9 +156,9 @@ private fun AnalysisProgressContent(
color = WineyTheme.colors.main_3
)
) {
append("나의 ")
append("${nickname} ")
}
append("테이스팅 노트를\n 분석 중이에요!")
append("테이스팅 노트를\n분석중이예요!")
},
style = WineyTheme.typography.title1.copy(
color = WineyTheme.colors.gray_50
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.lifecycle.viewModelScope
import com.teamwiney.core.common.base.BaseViewModel
import com.teamwiney.data.network.adapter.ApiResult
import com.teamwiney.data.network.model.response.toDomain
import com.teamwiney.data.repository.auth.AuthRepository
import com.teamwiney.data.repository.tastingnote.TastingNoteRepository
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.collectLatest
Expand All @@ -13,6 +14,7 @@ import javax.inject.Inject

@HiltViewModel
class AnalysisViewModel @Inject constructor(
private val authRepository: AuthRepository,
private val tastingNoteRepository: TastingNoteRepository
) : BaseViewModel<AnalysisContract.State, AnalysisContract.Event, AnalysisContract.Effect>(
initialState = AnalysisContract.State()
Expand Down Expand Up @@ -57,6 +59,29 @@ class AnalysisViewModel @Inject constructor(
}
}

fun getUserNickname() = viewModelScope.launch {
authRepository.getUserNickname().onStart {
updateState(currentState.copy(isLoading = true))
}.collect {
updateState(currentState.copy(isLoading = false))
when (it) {
is ApiResult.Success -> {
val result = it.data.result

updateState(currentState.copy(nickname = result.nickname))
}

is ApiResult.ApiError -> {
postEffect(AnalysisContract.Effect.ShowSnackBar(it.message))
}

else -> {
postEffect(AnalysisContract.Effect.ShowSnackBar("네트워크 오류가 발생했습니다."))
}
}
}
}

private fun getTasteAnalysis() = viewModelScope.launch {
tastingNoteRepository.getTasteAnalysis().onStart {
updateState(currentState.copy(isLoading = true))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class MyPageContract {

data class State(
val isLoading: Boolean = false,
val nickname: String = "",
val currentGrade: WineGrade = WineGrade.GLASS,
val expectedMonthGrade: WineGrade = WineGrade.GLASS,
val noteCount: Int = 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ fun MyPageScreen(
val context = LocalContext.current

LaunchedEffect(true) {
viewModel.getUserNickname()
viewModel.getUserWineGrade()
viewModel.getWineGradeStandard()

Expand Down Expand Up @@ -97,7 +98,7 @@ fun MyPageScreen(
modifier = Modifier.verticalScroll(rememberScrollState())
) {
MyPageProfile(
name = "김희연",
name = uiState.nickname,
onProfileClick = {
appState.navigate(MyPageDestinations.ACCOUNT)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,29 @@ class MyPageViewModel @Inject constructor(
}
}

fun getUserNickname() = viewModelScope.launch {
authRepository.getUserNickname().onStart {
updateState(currentState.copy(isLoading = true))
}.collect {
updateState(currentState.copy(isLoading = false))
when (it) {
is ApiResult.Success -> {
val result = it.data.result

updateState(currentState.copy(nickname = result.nickname))
}

is ApiResult.ApiError -> {
postEffect(MyPageContract.Effect.ShowSnackBar(it.message))
}

else -> {
postEffect(MyPageContract.Effect.ShowSnackBar("네트워크 오류가 발생했습니다."))
}
}
}
}

fun getUserWineGrade() = viewModelScope.launch {
val userId = runBlocking { dataStoreRepository.getIntValue(USER_ID).first() }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.core.text.isDigitsOnly
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.teamwiney.core.common.WineyAppState
import com.teamwiney.core.common.WineyBottomSheetState
Expand Down Expand Up @@ -103,7 +104,7 @@ fun NoteWineInfoVintageAndPriceScreen(

WineInfoTextField(
value = uiState.wineNote.vintage,
onValueChanged = { viewModel.updateVintage(it) },
onValueChanged = { if (it.isDigitsOnly()) viewModel.updateVintage(it) },
placeholderText = "ex) 1990",
trailingIcon = {
Text(
Expand Down Expand Up @@ -137,7 +138,7 @@ fun NoteWineInfoVintageAndPriceScreen(

WineInfoTextField(
value = uiState.wineNote.price,
onValueChanged = { viewModel.updatePrice(it) },
onValueChanged = { if (it.isDigitsOnly()) viewModel.updatePrice(it) },
placeholderText = "ex) 30000",
trailingIcon = {
Text(
Expand Down

0 comments on commit 2a307e8

Please sign in to comment.