Skip to content

Commit

Permalink
refactor: (#281) Data 인자 사용
Browse files Browse the repository at this point in the history
  • Loading branch information
khcho0125 committed Jan 14, 2023
1 parent 23031cf commit f108367
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package team.comit.simtong.domain.auth.usecase

import team.comit.simtong.domain.auth.dto.request.CheckAuthCodeData
import team.comit.simtong.domain.auth.exception.AuthExceptions
import team.comit.simtong.domain.auth.model.AuthCodeLimit
import team.comit.simtong.domain.auth.spi.CommandAuthCodeLimitPort
Expand All @@ -21,16 +22,16 @@ class CheckAuthCodeUseCase(
private val queryAuthCodePort: QueryAuthCodePort
) {

fun execute(email: String, code: String) {
val authCode = queryAuthCodePort.queryAuthCodeByEmail(email)
fun execute(request: CheckAuthCodeData) {
val authCode = queryAuthCodePort.queryAuthCodeByEmail(request.email)
?: throw AuthExceptions.RequiredNewEmailAuthentication()

if (!authCode.code.match(code)) {
if (!authCode.code.match(request.code)) {
throw AuthExceptions.DifferentAuthCode()
}

commandAuthCodeLimitPort.save(
AuthCodeLimit.certified(email)
AuthCodeLimit.certified(request.email)
)
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package team.comit.simtong.domain.auth.usecase

import team.comit.simtong.domain.auth.dto.request.SendAuthCodeData
import team.comit.simtong.domain.auth.model.AuthCode
import team.comit.simtong.domain.auth.model.AuthCodeLimit
import team.comit.simtong.domain.auth.spi.CommandAuthCodeLimitPort
Expand All @@ -24,18 +25,18 @@ class SendAuthCodeUseCase(
private val sendEmailPort: SendEmailPort
) {

fun execute(email: String) {
val authCodeLimit = queryAuthCodeLimitPort.queryAuthCodeLimitByEmail(email)
?: AuthCodeLimit.issue(email)
fun execute(request: SendAuthCodeData) {
val authCodeLimit = queryAuthCodeLimitPort.queryAuthCodeLimitByEmail(request.email)
?: AuthCodeLimit.issue(request.email)

commandAuthCodeLimitPort.save(
authCodeLimit.increaseCount()
)

val authCode = commandAuthCodePort.save(
AuthCode.issue(email)
AuthCode.issue(request.email)
)

sendEmailPort.sendAuthCode(authCode.code.value, email)
sendEmailPort.sendAuthCode(authCode.code.value, request.email)
}
}

0 comments on commit f108367

Please sign in to comment.