Skip to content

Commit

Permalink
refactor: (#286) AuthCodeLimit Aggregate 리팩토링
Browse files Browse the repository at this point in the history
  • Loading branch information
softpeanut committed Jan 9, 2023
1 parent 22fe8f4 commit 86047c0
Showing 1 changed file with 22 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import team.comit.simtong.domain.auth.exception.AuthExceptions
import team.comit.simtong.global.DomainProperties.getProperty
import team.comit.simtong.global.DomainPropertiesPrefix
import team.comit.simtong.global.annotation.Aggregate
import team.comit.simtong.global.annotation.Default

/**
*
Expand All @@ -13,10 +12,10 @@ import team.comit.simtong.global.annotation.Default
* @author Chokyunghyeon
* @author kimbeomjin
* @date 2022/09/11
* @version 1.0.0
* @version 1.2.5
**/
@Aggregate
data class AuthCodeLimit @Default constructor(
data class AuthCodeLimit(
val key: String,

val expirationTime: Int,
Expand All @@ -25,14 +24,6 @@ data class AuthCodeLimit @Default constructor(

val verified: Boolean
) {

constructor(email: String) : this(
key = email,
expirationTime = EXPIRED,
attemptCount = 0,
verified = false
)

companion object {
@JvmField
val MAX_ATTEMPT_COUNT: Short = getProperty(DomainPropertiesPrefix.AUTHCODELIMIT_MAX_ATTEMPT_COUNT).toShort()
Expand All @@ -43,6 +34,13 @@ data class AuthCodeLimit @Default constructor(
@JvmField
val VERIFIED_EXPIRED: Int = getProperty(DomainPropertiesPrefix.AUTHCODELIMIT_VERIFIED_EXP).toInt()

fun issue(email: String) = AuthCodeLimit(
key = email,
expirationTime = EXPIRED,
attemptCount = 0,
verified = false
)

fun certified(email: String) = AuthCodeLimit(
key = email,
expirationTime = VERIFIED_EXPIRED,
Expand All @@ -52,9 +50,8 @@ data class AuthCodeLimit @Default constructor(
}

fun increaseCount(): AuthCodeLimit {
if (attemptCount >= MAX_ATTEMPT_COUNT) {
throw AuthExceptions.ExceededSendAuthCodeRequest()
}
checkNotYetVerified()
checkNotExceededAttemptCount()

return AuthCodeLimit(
key = key,
Expand All @@ -64,4 +61,15 @@ data class AuthCodeLimit @Default constructor(
)
}

private fun checkNotYetVerified() {
if (verified) {
throw AuthExceptions.AlreadyCertifiedEmail()
}
}

private fun checkNotExceededAttemptCount() {
if (attemptCount >= MAX_ATTEMPT_COUNT) {
throw AuthExceptions.ExceededSendAuthCodeRequest()
}
}
}

0 comments on commit 86047c0

Please sign in to comment.