Skip to content

Commit 03f3d74

Browse files
committed
Change UpdateStudentUserInfUseCase to receive major from parameter
1 parent 318c983 commit 03f3d74

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

domain/src/main/java/in/koreatech/koin/domain/usecase/user/UpdateStudentUserInfoUseCase.kt

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@ import `in`.koreatech.koin.domain.error.user.UserErrorHandler
77
import `in`.koreatech.koin.domain.model.error.ErrorHandler
88
import `in`.koreatech.koin.domain.model.user.Gender
99
import `in`.koreatech.koin.domain.model.user.User
10-
import `in`.koreatech.koin.domain.repository.DeptRepository
1110
import `in`.koreatech.koin.domain.repository.UserRepository
1211
import `in`.koreatech.koin.domain.util.ext.isValidStudentId
1312
import javax.inject.Inject
1413

1514
class UpdateStudentUserInfoUseCase @Inject constructor(
16-
private val deptRepository: DeptRepository,
1715
private val userRepository: UserRepository,
1816
private val userErrorHandler: UserErrorHandler
1917
) {
@@ -24,6 +22,7 @@ class UpdateStudentUserInfoUseCase @Inject constructor(
2422
separatedPhoneNumber: List<String>?,
2523
gender: Gender?,
2624
studentId: String,
25+
major: String,
2726
checkedEmailValidation: Boolean
2827
): ErrorHandler? {
2928
return try {
@@ -35,15 +34,13 @@ class UpdateStudentUserInfoUseCase @Inject constructor(
3534
throw IllegalStateException(ERROR_USERINFO_GENDER_NOT_SET)
3635
}
3736

38-
if(!studentId.isValidStudentId) {
37+
if (!studentId.isValidStudentId) {
3938
throw IllegalStateException(ERROR_INVALID_STUDENT_ID)
4039
}
4140

42-
val newUser: User = when(beforeUser) {
41+
val newUser: User = when (beforeUser) {
4342
User.Anonymous -> throw IllegalAccessException()
4443
is User.Student -> {
45-
val deptString = deptRepository.getDeptNameFromDeptCode(studentId.substring(5..6))
46-
4744
beforeUser.copy(
4845
name = name.trim(),
4946
nickname = nickname.trim(),
@@ -55,7 +52,7 @@ class UpdateStudentUserInfoUseCase @Inject constructor(
5552
},
5653
gender = gender,
5754
studentNumber = studentId.trim().ifBlank { null },
58-
major = deptString
55+
major = major
5956
)
6057
}
6158
}

koin/src/main/java/in/koreatech/koin/ui/userinfo/UserInfoEditActivity.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ class UserInfoEditActivity : KoinNavigationDrawerActivity() {
6161
binding.userinfoeditedRadiobuttonGenderWoman.isChecked -> Gender.Woman
6262
else -> null
6363
},
64-
studentId = binding.userinfoeditedEdittextStudentId.textString
64+
studentId = binding.userinfoeditedEdittextStudentId.textString,
65+
major = userinfoeditedSpinnerMajor.selected.text.toString()
6566
)
6667
}
6768
)

koin/src/main/java/in/koreatech/koin/ui/userinfo/viewmodel/UserInfoEditViewModel.kt

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import `in`.koreatech.koin.domain.util.onSuccess
1818
import `in`.koreatech.koin.ui.userinfo.state.NicknameCheckState
1919
import `in`.koreatech.koin.ui.userinfo.state.NicknameState
2020
import kotlinx.coroutines.flow.SharingStarted
21+
import kotlinx.coroutines.flow.StateFlow
2122
import kotlinx.coroutines.flow.combine
2223
import kotlinx.coroutines.flow.filter
2324
import kotlinx.coroutines.flow.flow
@@ -36,12 +37,6 @@ class UserInfoEditViewModel @Inject constructor(
3637
private val _user = MutableLiveData<User>()
3738
val user: LiveData<User> get() = _user
3839

39-
val depts = flow { emit(getDeptNamesUseCase()) }
40-
.combine(user.asFlow()) { depts, user -> depts to user }
41-
.filter{ it.second.isStudent }
42-
.map { it.first to (it.second as User.Student).major }
43-
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000), listOf<String>() to null)
44-
4540
private val _getDeptErrorMessage = MutableLiveData<String>()
4641
val getDeptErrorMessage: LiveData<String> get() = _getDeptErrorMessage
4742

@@ -57,6 +52,12 @@ class UserInfoEditViewModel @Inject constructor(
5752
private val _userInfoEditedEvent = SingleLiveEvent<Unit>()
5853
val userInfoEditedEvent: LiveData<Unit> get() = _userInfoEditedEvent
5954

55+
val depts: StateFlow<Pair<List<String>, String?>> = flow { emit(getDeptNamesUseCase()) }
56+
.combine(user.asFlow()) { depts, user -> depts to user }
57+
.filter { it.second.isStudent }
58+
.map { it.first to (it.second as User.Student).major }
59+
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000), listOf<String>() to null)
60+
6061
fun getUserInfo() = viewModelScope.launchWithLoading {
6162
getUserInfoUseCase()
6263
.onSuccess { user ->
@@ -101,7 +102,8 @@ class UserInfoEditViewModel @Inject constructor(
101102
nickname: String,
102103
separatedPhoneNumber: List<String>?,
103104
gender: Gender?,
104-
studentId: String
105+
studentId: String,
106+
major: String
105107
) {
106108
if (isLoading.value == false) {
107109
viewModelScope.launchWithLoading {
@@ -113,6 +115,7 @@ class UserInfoEditViewModel @Inject constructor(
113115
separatedPhoneNumber = separatedPhoneNumber,
114116
gender = gender,
115117
studentId = studentId,
118+
major = major,
116119
checkedEmailValidation = nicknameState.value?.let {
117120
it.nickname == nickname && it.isNicknameDuplicated == false
118121
} ?: false

0 commit comments

Comments
 (0)