Skip to content

Commit

Permalink
refactor: (#78) 생성자 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
khcho0125 committed Sep 29, 2022
1 parent 9eaf4b0 commit e6d2d46
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package team.comit.simtong.domain.auth.usecase

import net.bytebuddy.utility.RandomString
import team.comit.simtong.domain.auth.exception.CertifiedEmailException
import team.comit.simtong.domain.auth.model.AuthCode
import team.comit.simtong.domain.auth.model.AuthCodeLimit
Expand Down Expand Up @@ -28,26 +27,15 @@ class SendAuthCodeUseCase(

fun execute(email: String) {
val authCodeLimit = queryAuthCodeLimitPort.queryAuthCodeLimitByEmail(email)
?: AuthCodeLimit(
key = email,
expirationTime = AuthCodeLimit.EXPIRED,
attemptCount = 0,
isVerified = false
)
?: AuthCodeLimit(email)

if(authCodeLimit.isVerified) {
throw CertifiedEmailException.EXCEPTION
}

commandAuthCodeLimitPort.save(authCodeLimit.increaseCount())

val authCode = commandAuthCodePort.save(
AuthCode(
key = email,
code = RandomString(6).nextString(),
expirationTime = AuthCode.EXPIRED
)
)
val authCode = commandAuthCodePort.save(AuthCode(email))

sendEmailPort.sendAuthCode(authCode.code, email)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package team.comit.simtong.domain.auth.model

import net.bytebuddy.utility.RandomString
import team.comit.simtong.global.annotation.Aggregate

/**
Expand All @@ -23,4 +24,10 @@ class AuthCode(
const val EXPIRED = 180
}

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ class AuthCodeLimit(
const val VERIFIED_EXPIRED = 2700
}

constructor(email: String) : this(
key = email,
expirationTime = EXPIRED,
attemptCount = MAX_ATTEMPT_COUNT,
isVerified = false
)

fun increaseCount(): AuthCodeLimit {
if (attemptCount >= MAX_ATTEMPT_COUNT) {
throw ExceededSendAuthCodeRequestException.EXCEPTION
Expand Down

0 comments on commit e6d2d46

Please sign in to comment.