generated from pricelees/issue-pr-template
30 lines
1.2 KiB
Kotlin
30 lines
1.2 KiB
Kotlin
package roomescape.user.business
|
|
|
|
import io.github.oshai.kotlinlogging.KLogger
|
|
import io.github.oshai.kotlinlogging.KotlinLogging
|
|
import org.springframework.stereotype.Component
|
|
import roomescape.user.exception.UserErrorCode
|
|
import roomescape.user.exception.UserException
|
|
import roomescape.user.infrastructure.persistence.UserRepository
|
|
|
|
private val log: KLogger = KotlinLogging.logger {}
|
|
|
|
@Component
|
|
class UserValidator(
|
|
private val userRepository: UserRepository,
|
|
) {
|
|
|
|
fun validateCanSignup(email: String, phone: String) {
|
|
log.info { "[UserValidator.validateCanSignup] 회원가입 가능 여부 검증 시작: email:$email / phone:$phone" }
|
|
|
|
if (userRepository.existsByEmail(email)) {
|
|
log.info { "[UserValidator.validateCanSignup] 중복된 이메일 입력으로 인한 실패: email:$email" }
|
|
throw UserException(UserErrorCode.EMAIL_ALREADY_EXISTS)
|
|
}
|
|
if (userRepository.existsByPhone(phone)) {
|
|
log.info { "[UserValidator.validateCanSignup] 중복된 휴대폰 번호 입력으로 인한 실패: phone:$phone" }
|
|
throw UserException(UserErrorCode.PHONE_ALREADY_EXISTS)
|
|
}
|
|
}
|
|
}
|