Skip to content

Commit e4cb427

Browse files
authored
fix: prevent departments lookup with invalid collegeId (#480)
Treat sentinel -1 college/department as unselected to avoid calling /users/lookup/departments with collegeId=-1 (server VALIDATION_ERROR).
1 parent 09559fd commit e4cb427

2 files changed

Lines changed: 19 additions & 9 deletions

File tree

app/src/main/java/com/eatssu/android/presentation/mypage/userinfo/UserInfoActivity.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ class UserInfoActivity :
177177
val data = state.data
178178

179179
// 단과대를 먼저 선택하도록 유도
180-
if (data.selectedCollege == null) {
180+
if (data.selectedCollege == null || data.selectedCollege.collegeId == -1) {
181181
showToast(R.string.toast_college_required, ToastType.ERROR)
182182
return
183183
}
@@ -278,4 +278,4 @@ class UserInfoActivity :
278278
}
279279
}
280280

281-
}
281+
}

app/src/main/java/com/eatssu/android/presentation/mypage/userinfo/UserInfoViewModel.kt

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)