Skip to content

Commit

Permalink
Merge pull request #74 from TeamBridge-Project/feature/#72-유효성_검사_의존성_주입
Browse files Browse the repository at this point in the history
Feature/#72 유효성 검사 의존성 주입
  • Loading branch information
EvergreenTree97 authored May 20, 2022
2 parents 6d979fa + 1097bdb commit 5e7c08b
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 17 deletions.
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ buildscript {
compose_version = '1.2.0-alpha04'
accompanist_version = '0.24.4-alpha'
nav_version = "2.4.1"
dagger_version = "2.41"
hilt_version = "2.41"
coroutines_version = "1.6.0"
retrofit_version = "2.9.0"
Expand Down
3 changes: 3 additions & 0 deletions domain/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
plugins {
id 'com.android.library'
id 'org.jetbrains.kotlin.android'
id 'kotlin-kapt'
id 'dagger.hilt.android.plugin'
}

android {
Expand Down Expand Up @@ -30,6 +32,7 @@ android {
}

dependencies {
kapt "com.google.dagger:hilt-android-compiler:$hilt_version"
implementation "com.google.dagger:hilt-android:$hilt_version"
implementation 'androidx.core:core-ktx:1.7.0'
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.example.domain.common

interface SignUpValidation {
interface SignUpValidator {
fun isEmailValidity(email: String) : Boolean

fun isPasswordValidity(password: String) : Boolean
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package com.example.domain.common.impl

import com.example.domain.common.SignUpValidation
import com.example.domain.common.SignUpValidator
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
internal class SignUpValidationImpl @Inject constructor() : SignUpValidation{
internal class SignUpValidatorImpl @Inject constructor() : SignUpValidator{
override fun isEmailValidity(email: String): Boolean {
return email.matches("""^[0-9a-zA-Z]([-_.]?[0-9a-zA-Z])*@[0-9a-zA-Z]([-_.]?[0-9a-zA-Z])*.[.][a-zA-Z]{2,3}$""".toRegex())
}
Expand Down
21 changes: 21 additions & 0 deletions domain/src/main/java/com/example/domain/di/DomainModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.example.domain.di

import com.example.domain.common.SignUpValidator
import com.example.domain.common.impl.SignUpValidatorImpl
import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
internal interface DomainModule {

@Binds
@Singleton
fun bindSignUpValidator(
validator: SignUpValidatorImpl
): SignUpValidator

}
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,10 @@ fun SignUpScreen(
SignUpState.PasswordFailed -> {
Toast.makeText(activity, "패스워드 형식이 틀렸습니다.", Toast.LENGTH_SHORT).show()
}
SignUpState.NickName -> {
SignUpState.NickNameFailed -> {
Toast.makeText(activity, "닉네임 형식이 틀렸습니다.", Toast.LENGTH_SHORT).show()
}
SignUpState.Date -> {
SignUpState.DateFailed -> {
Toast.makeText(activity, "생일 형식이 틀렸습니다.", Toast.LENGTH_SHORT).show()
}
else -> {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ sealed class SignUpState{
object Loading : SignUpState()
object EmailFailed : SignUpState()
object PasswordFailed : SignUpState()
object NickName : SignUpState()
object Date : SignUpState()
object NickNameFailed : SignUpState()
object DateFailed : SignUpState()
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.app.Activity
import android.content.Intent
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.example.domain.common.SignUpValidator
import com.example.domain.model.SignUpModel
import com.example.domain.usecase.SignUpUseCase
import com.example.local.datastore.DataStoreManager
Expand All @@ -20,7 +21,8 @@ import javax.inject.Inject
@HiltViewModel
class SignUpViewModel @Inject constructor(
private val signUpUseCase: SignUpUseCase,
private val dataStore: DataStoreManager
private val dataStore: DataStoreManager,
private val signUpValidator: SignUpValidator
) : ViewModel() {

private val _uiState = MutableStateFlow<SignUpState>(SignUpState.SignUpNeeded)
Expand All @@ -37,14 +39,14 @@ class SignUpViewModel @Inject constructor(
) {
_uiState.value = SignUpState.Loading

if (!email.matches("""^[0-9a-zA-Z]([-_.]?[0-9a-zA-Z])*@[0-9a-zA-Z]([-_.]?[0-9a-zA-Z])*.[.][a-zA-Z]{2,3}$""".toRegex())) {
if (!signUpValidator.isEmailValidity(email)) {
_uiState.value = SignUpState.EmailFailed
} else if(!password.matches("^(?=.*[A-Za-z])(?=.*[0-9])(?=.*[$@$!%*#?&.])[A-Za-z[0-9]$@$!%*#?&.]{8,20}$".toRegex())) {
} else if(!signUpValidator.isPasswordValidity(password)) {
_uiState.value = SignUpState.PasswordFailed
} else if(!nickname.matches("^[가-힣a-zA-Z0-9]{2,6}$".toRegex())) {
_uiState.value = SignUpState.NickName
} else if(!date.matches("^(19[0-9][0-9]|20\\d{2})-(0[0-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$".toRegex())) {
_uiState.value = SignUpState.Date
} else if(!signUpValidator.isNickNameValidity(nickname)) {
_uiState.value = SignUpState.NickNameFailed
} else if(!signUpValidator.isDateValidity(date)) {
_uiState.value = SignUpState.DateFailed
} else {
val charGender = when (gender) {
"" -> "m"
Expand Down

0 comments on commit 5e7c08b

Please sign in to comment.