Skip to content

Commit

Permalink
[FEATURE] #125 : 학번은 9글자만 입력할 수 있도록 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
tgyuuAn committed Feb 17, 2024
1 parent e4699a0 commit 39df3eb
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 248 deletions.
3 changes: 0 additions & 3 deletions .idea/.gitignore

This file was deleted.

117 changes: 0 additions & 117 deletions .idea/codeStyles/Project.xml

This file was deleted.

5 changes: 0 additions & 5 deletions .idea/codeStyles/codeStyleConfig.xml

This file was deleted.

3 changes: 0 additions & 3 deletions .idea/dictionaries/jaino.xml

This file was deleted.

4 changes: 1 addition & 3 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 0 additions & 41 deletions .idea/inspectionProfiles/Project_Default.xml

This file was deleted.

25 changes: 0 additions & 25 deletions .idea/jarRepositories.xml

This file was deleted.

5 changes: 5 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,32 @@ import java.net.UnknownHostException

fun Throwable.toSupportingText(): String {
return when (this) {
is UnknownHostException -> {
"네트워크 연결이 원활하지 않습니다."
}
is FirebaseAuthException -> {
this.toSupportingText()
}
is FirebaseFirestoreException -> {
this.toSupportingText()
}
else -> {
"알 수 없는 오류가 발생하였습니다."
}
is UnknownHostException -> "네트워크 연결이 원활하지 않습니다."

is FirebaseAuthException -> this.toSupportingText()

is FirebaseFirestoreException -> this.toSupportingText()

is IllegalStateException -> this.message.toString()

else -> "알 수 없는 오류가 발생하였습니다."
}
}

fun FirebaseAuthException.toSupportingText(): String {
return when (this.errorCode) {
"ERROR_WEB_CONTEXT_CANCELED", "ERROR_USER_CANCELLED" -> {
"다시 시도해 주세요."
}
else -> {
"알 수 없는 오류가 발생하였습니다."
}
"ERROR_WEB_CONTEXT_CANCELED", "ERROR_USER_CANCELLED" -> "다시 시도해 주세요."

else -> "알 수 없는 오류가 발생하였습니다."
}
}

fun FirebaseFirestoreException.toSupportingText(): String {
return when (this.code.value()) {
7 -> {
"접근 권한이 없습니다."
}
16 -> {
"회원이 만료되었습니다. 다시 로그인 해주세요."
}
else -> {
"알 수 없는 오류가 발생하였습니다."
}
7 -> "접근 권한이 없습니다."

16 -> "회원이 만료되었습니다. 다시 로그인 해주세요."

else -> "알 수 없는 오류가 발생하였습니다."
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,35 +31,34 @@ class SignUpViewModel @Inject constructor(
private val _signUpSemester: MutableStateFlow<String> = MutableStateFlow(FIRST_SEMESTER)
val signUpSemester: StateFlow<String> get() = _signUpSemester

fun postUserProfile() {
viewModelScope.launch {
postUserProfileUseCase(
userName = _signUpName.value,
studentId = _signUpStudentId.value,
registeredAt = "${_signUpYear.value} ${_signUpSemester.value}",
).onSuccess {
_signUpEventFlow.emit(SignUpEvent.Success)
}.onFailure { throwable ->
_signUpEventFlow.emit(SignUpEvent.Failure(throwable))
}
fun postUserProfile() = viewModelScope.launch {
if (!isValidStudentId()) {
_signUpEventFlow.emit(
SignUpEvent.Failure(IllegalStateException("학번은 9자리로만 입력하실 수 있어요!")),
)
return@launch
}
}

fun setName(name: String) {
_signUpName.value = name
postUserProfileUseCase(
userName = _signUpName.value,
studentId = _signUpStudentId.value,
registeredAt = "${_signUpYear.value} ${_signUpSemester.value}",
).onSuccess {
_signUpEventFlow.emit(SignUpEvent.Success)
}.onFailure { throwable ->
_signUpEventFlow.emit(SignUpEvent.Failure(throwable))
}
}

fun setStudentId(studentId: String) {
_signUpStudentId.value = studentId
}
fun isValidStudentId(): Boolean = (_signUpStudentId.value.length == STUDENT_ID_LENGTH)

fun setYear(year: String) {
_signUpYear.value = year
}
fun setName(name: String) { _signUpName.value = name }

fun setSemester(semester: String) {
_signUpSemester.value = semester
}
fun setStudentId(studentId: String) { _signUpStudentId.value = studentId }

fun setYear(year: String) { _signUpYear.value = year }

fun setSemester(semester: String) { _signUpSemester.value = semester }

sealed class SignUpEvent {
data object Success : SignUpEvent()
Expand All @@ -68,5 +67,6 @@ class SignUpViewModel @Inject constructor(

companion object {
const val FIRST_SEMESTER = "1학기"
const val STUDENT_ID_LENGTH = 9
}
}
9 changes: 8 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,11 @@ kotlin.code.style=official
# Enables namespacing of each library's R class so that its R class includes only the
# resources declared in the library itself and none from the library's dependencies,
# thereby reducing the size of the R class for that library
android.nonTransitiveRClass=true
android.nonTransitiveRClass=true
android.enableJetifier=false
org.gradle.caching=true
org.gradle.daemon=true
org.gradle.configureondemand=true
org.gradle.configuration-cache=true
org.gradle.parallel=true
kotlin.incremental=true

0 comments on commit 39df3eb

Please sign in to comment.