Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix/#226] 프로필 수정 뷰 / 서버통신 수정 #228

Merged
merged 7 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
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
Loading