Skip to content

Commit

Permalink
[MERGE] #226 -> develop
Browse files Browse the repository at this point in the history
[Fix/#226] ν”„λ‘œν•„ μˆ˜μ • λ·° / μ„œλ²„ν†΅μ‹  μˆ˜μ •
  • Loading branch information
leeeyubin authored Sep 9, 2024
2 parents 61fa69b + c967ca5 commit 5e95261
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 11 deletions.
2 changes: 1 addition & 1 deletion core/src/main/java/com/terning/core/type/ProfileImage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ enum class ProfileImage(
"glass" -> GLASS
"calendar" -> CALENDAR
"passion" -> PASSION
else -> BASIC
else -> DEFAULT
}

fun toIndex(profileImage: ProfileImage): Int =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ class MyPageDataSourceImpl @Inject constructor(

override suspend fun editProfile(
request: MyPageProfileEditRequestDto
): NonDataBaseResponse = myPageService.editProfile()
): NonDataBaseResponse = myPageService.editProfile(request)
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ class TokenReissueDataSourceImpl @Inject constructor(
override suspend fun postReissueToken(
authorization: String
): BaseResponse<TokenReissueResponseDto> =
tokenReissueService.postReissueToken(authorization)
tokenReissueService.postReissueToken("Bearer $authorization")
}
6 changes: 5 additions & 1 deletion data/src/main/java/com/terning/data/service/MyPageService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package com.terning.data.service

import com.terning.data.dto.BaseResponse
import com.terning.data.dto.NonDataBaseResponse
import com.terning.data.dto.request.MyPageProfileEditRequestDto
import com.terning.data.dto.response.MyPageResponseDto
import retrofit2.http.Body
import retrofit2.http.DELETE
import retrofit2.http.GET
import retrofit2.http.PATCH
Expand All @@ -19,5 +21,7 @@ interface MyPageService {
suspend fun getProfile(): BaseResponse<MyPageResponseDto>

@PATCH("api/v1/mypage/profile")
suspend fun editProfile(): NonDataBaseResponse
suspend fun editProfile(
@Body body: MyPageProfileEditRequestDto
): NonDataBaseResponse
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ fun MyPageRoute(
}
}

LaunchedEffect(true) {
viewModel.getProfile()
}

LaunchedEffect(viewModel.sideEffects, lifecycleOwner) {
viewModel.sideEffects.flowWithLifecycle(lifecycle = lifecycleOwner.lifecycle)
.collect { sideEffect ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ class MyPageViewModel @Inject constructor(
private val tokenRepository: TokenRepository
) : ViewModel() {

init {
getProfile()
}

private val _state: MutableStateFlow<MyPageState> = MutableStateFlow(MyPageState())
val state: StateFlow<MyPageState> get() = _state.asStateFlow()

Expand Down Expand Up @@ -98,7 +94,7 @@ class MyPageViewModel @Inject constructor(
}
}

private fun getProfile() {
fun getProfile() {
viewModelScope.launch {
myPageRepository.getProfile()
.onSuccess { response ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ data class ProfileEditState(
val name: String = "",
val initialName: String = "",
val profile: String = "",
val initialProfile: String = "",
val initialView: Boolean = true,
val isModified: Boolean = false,
val isButtonValid: Boolean = false,
val authType: String = "",
val showBottomSheet: Boolean = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,26 @@ class ProfileEditViewModel @Inject constructor(
name = initialName,
initialName = initialName,
profile = initialProfile,
initialProfile = initialProfile
)
}

fun updateName(name: String) {
_state.value = _state.value.copy(
name = name,
initialView = false
initialView = false,
isModified = true
)
}

fun updateProfile(profile: String) {
val isSameAsInitial = profile == _state.value.initialProfile
val isSameAsPrevious = profile == _state.value.profile

_state.value = _state.value.copy(
profile = profile,
initialView = false
initialView = !_state.value.isModified && isSameAsInitial,
isModified = if (isSameAsPrevious) _state.value.isModified else !isSameAsInitial
)
}

Expand Down

0 comments on commit 5e95261

Please sign in to comment.