From c370696fc5530c694e6524241418b97e37764205 Mon Sep 17 00:00:00 2001 From: KimBeomJin Date: Mon, 9 Jan 2023 11:20:56 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20(#286)=20AuthCode=20Aggregate=20?= =?UTF-8?q?=EA=B5=AC=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../simtong/domain/auth/model/AuthCode.kt | 51 +++++++++++++++---- 1 file changed, 40 insertions(+), 11 deletions(-) diff --git a/simtong-domain/src/main/kotlin/team/comit/simtong/domain/auth/model/AuthCode.kt b/simtong-domain/src/main/kotlin/team/comit/simtong/domain/auth/model/AuthCode.kt index 35d17e28..9dd5a10d 100644 --- a/simtong-domain/src/main/kotlin/team/comit/simtong/domain/auth/model/AuthCode.kt +++ b/simtong-domain/src/main/kotlin/team/comit/simtong/domain/auth/model/AuthCode.kt @@ -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()) + } } \ No newline at end of file