Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ class UserInfoActivity :
val data = state.data

// 단과대를 먼저 선택하도록 유도
if (data.selectedCollege == null) {
if (data.selectedCollege == null || data.selectedCollege.collegeId == -1) {
showToast(R.string.toast_college_required, ToastType.ERROR)
return
}
Expand Down Expand Up @@ -278,4 +278,4 @@ class UserInfoActivity :
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,14 @@ class UserInfoViewModel @Inject constructor(

val userInfo = getUserCollegeDepartmentUseCase()

val initialCollege = userInfo.userCollege.takeUnless { it.collegeId == -1 }
val initialDepartment = userInfo.userDepartment.takeUnless { it.departmentId == -1 }
Comment on lines +60 to +61
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

-1이라는 매직 넘버가 코드 여러 곳에서 '선택되지 않음'을 나타내는 값으로 사용되고 있습니다. 코드의 가독성과 유지보수성을 높이기 위해, 이 값을 UserInfoViewModelcompanion objectconst val UNSELECTED_ID = -1와 같이 상수로 정의하고, -1 대신 이 상수를 사용하는 것을 고려해 보세요. 이 변경은 이 파일의 loadDepartmentList 함수와 UserInfoActivity에도 적용될 수 있습니다.


// 단과대 목록과 학과 목록을 먼저 모두 가져옴
val colleges = userRepository.getTotalColleges()
val departments =
if (userInfo.userCollege.collegeId != -1)
userRepository.getTotalDepartments(userInfo.userCollege.collegeId)
if (initialCollege != null)
userRepository.getTotalDepartments(initialCollege.collegeId)
else
emptyList()

Expand All @@ -71,10 +74,10 @@ class UserInfoViewModel @Inject constructor(
UserInfoData(
nickname = userInfo.nickname,
originalNickname = userInfo.nickname,
selectedCollege = userInfo.userCollege,
originalCollege = userInfo.userCollege,
selectedDepartment = userInfo.userDepartment,
originalDepartment = userInfo.userDepartment,
selectedCollege = initialCollege,
originalCollege = initialCollege,
selectedDepartment = initialDepartment,
originalDepartment = initialDepartment,
collegeList = colleges,
departmentList = departments
)
Expand Down Expand Up @@ -187,6 +190,14 @@ class UserInfoViewModel @Inject constructor(
viewModelScope.launch {
val currentState = _uiState.value as? UiState.Success ?: return@launch

if (collegeId == -1) {
Timber.w("학과 목록 로드 스킵: invalid collegeId=-1")
_uiState.update {
UiState.Success(currentState.data.copy(departmentList = emptyList()))
}
return@launch
}

val departments = userRepository.getTotalDepartments(collegeId)
_uiState.update {
UiState.Success(currentState.data.copy(departmentList = departments))
Expand Down Expand Up @@ -305,4 +316,3 @@ data class UserInfoData(
}
}
}