Skip to content

Commit

Permalink
refactor: (#286) AuthCode Aggregate 구성
Browse files Browse the repository at this point in the history
  • Loading branch information
softpeanut committed Jan 9, 2023
1 parent 3db34f2 commit c370696
Showing 1 changed file with 40 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,63 @@ import net.bytebuddy.utility.RandomString
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

/**
*
* AuthCodeAggregate Root를 담당하는 AuthCode
* AuthCode Aggregate Root를 담당하는 AuthCode
*
* @author Chokyunghyeon
* @author kimbeomjin
* @date 2022/09/24
* @version 1.0.0
* @version 1.2.5
**/
@Aggregate
data class AuthCode @Default constructor(
data class AuthCode(
val key: String,

val code: String,
val code: Code,

val expirationTime: Int
) {

constructor(email: String) : this(
key = email,
code = RandomString(6).nextString(),
expirationTime = EXPIRED
)

companion object {
@JvmField
val EXPIRED = getProperty(DomainPropertiesPrefix.AUTHCODE_EXP).toInt()

fun of(key: String, code: Code, expirationTime: Int) = AuthCode(
key = key,
code = code,
expirationTime = expirationTime
)

fun issue(email: String) = AuthCode(
key = email,
code = Code.defaultValue(),
expirationTime = EXPIRED
)
}
}

/**
*
* AuthCode Aggregate 중 인증코드를 담당하는 Code
*
* @author kimbeomjin
* @date 2023/01/09
* @version 1.2.5
**/
@JvmInline
value class Code private constructor(
val value: String
) {

fun match(code: String): Boolean {
return this.value == code
}

companion object {
fun of(value: String) = Code(value)

fun defaultValue() = Code(RandomString(6).nextString())
}
}

0 comments on commit c370696

Please sign in to comment.