@@ -57,11 +57,14 @@ class UserInfoViewModel @Inject constructor(
5757
5858 val userInfo = getUserCollegeDepartmentUseCase()
5959
60+ val initialCollege = userInfo.userCollege.takeUnless { it.collegeId == - 1 }
61+ val initialDepartment = userInfo.userDepartment.takeUnless { it.departmentId == - 1 }
62+
6063 // 단과대 목록과 학과 목록을 먼저 모두 가져옴
6164 val colleges = userRepository.getTotalColleges()
6265 val departments =
63- if (userInfo.userCollege.collegeId != - 1 )
64- userRepository.getTotalDepartments(userInfo.userCollege .collegeId)
66+ if (initialCollege != null )
67+ userRepository.getTotalDepartments(initialCollege .collegeId)
6568 else
6669 emptyList()
6770
@@ -71,10 +74,10 @@ class UserInfoViewModel @Inject constructor(
7174 UserInfoData (
7275 nickname = userInfo.nickname,
7376 originalNickname = userInfo.nickname,
74- selectedCollege = userInfo.userCollege ,
75- originalCollege = userInfo.userCollege ,
76- selectedDepartment = userInfo.userDepartment ,
77- originalDepartment = userInfo.userDepartment ,
77+ selectedCollege = initialCollege ,
78+ originalCollege = initialCollege ,
79+ selectedDepartment = initialDepartment ,
80+ originalDepartment = initialDepartment ,
7881 collegeList = colleges,
7982 departmentList = departments
8083 )
@@ -187,6 +190,14 @@ class UserInfoViewModel @Inject constructor(
187190 viewModelScope.launch {
188191 val currentState = _uiState .value as ? UiState .Success ? : return @launch
189192
193+ if (collegeId == - 1 ) {
194+ Timber .w(" 학과 목록 로드 스킵: invalid collegeId=-1" )
195+ _uiState .update {
196+ UiState .Success (currentState.data.copy(departmentList = emptyList()))
197+ }
198+ return @launch
199+ }
200+
190201 val departments = userRepository.getTotalDepartments(collegeId)
191202 _uiState .update {
192203 UiState .Success (currentState.data.copy(departmentList = departments))
@@ -305,4 +316,3 @@ data class UserInfoData(
305316 }
306317 }
307318}
308-
0 commit comments