Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge: (#78) 이메일 인증 정책 설계 #82

Merged
merged 41 commits into from
Sep 30, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
cf644b0
docs: (#78) javadoc 수정
khcho0125 Sep 24, 2022
bc611a0
add: (#78) 이메일 인증 정책 로직
khcho0125 Sep 25, 2022
20c1e5a
add: (#78) 이메일 인증 정책 Port
khcho0125 Sep 25, 2022
8596c78
add: (#78) 이메일 인증 정책 예외
khcho0125 Sep 25, 2022
fb695e5
add: (#78) 도메인 인증 모델
khcho0125 Sep 25, 2022
c78e988
add: (#78) NullPointerException 핸들링
khcho0125 Sep 25, 2022
bad95f6
add: (#78) 이메일 인증 표현 영역 설계
khcho0125 Sep 25, 2022
5418d5d
add: #(78) 이메일 인증 외부 영역 설계
khcho0125 Sep 25, 2022
7e82c83
refactor: (#78) 비교 부호 수정
khcho0125 Sep 25, 2022
a29140e
refactor: (#78) mockito kotlin 추가
khcho0125 Sep 25, 2022
3f43c45
refactor: (#78) MAX_ATTEMPT_COUNT short 타입 변환
khcho0125 Sep 25, 2022
9a87638
test: (#78) 이메일 인증 정책 Test Case
khcho0125 Sep 25, 2022
05d37ee
refactor: (#78) 대입 삭제
khcho0125 Sep 25, 2022
5e441f3
add: (#78) Response 제거
khcho0125 Sep 25, 2022
64401b6
Merge branch 'main' into feature/78-email-policy
khcho0125 Sep 25, 2022
e35ef7c
test: (#78) Response 제거 테스트 코드 반영
khcho0125 Sep 25, 2022
0519781
Merge remote-tracking branch 'origin/feature/78-email-policy' into fe…
khcho0125 Sep 25, 2022
948999f
refactor: (#78) AuthCode 확인 쿼리 exists → query
khcho0125 Sep 26, 2022
8338db1
docs: (#78) javadoc 수정
khcho0125 Sep 26, 2022
43b5d72
refactor: (#78) Policy 수정
khcho0125 Sep 27, 2022
325a9cc
refactor: (#78) 환경 변수 사용
khcho0125 Sep 27, 2022
6e0c501
style: (#78) 공백 줄 맞춤
khcho0125 Sep 27, 2022
1bbf69c
Merge branch 'main' into feature/78-email-policy
khcho0125 Sep 27, 2022
7a6fc38
refactor: (#78) const value 세팅
khcho0125 Sep 27, 2022
2f8f806
test: (#78) willDoNothing 제거
khcho0125 Sep 27, 2022
b42bfe4
refactor: (#78) UseCase 설계 구성 변경
khcho0125 Sep 27, 2022
144109f
fix: (#78) value 설정 실수
khcho0125 Sep 27, 2022
a0796e9
test: (#78) 사용하지 않는 Stub 제거
khcho0125 Sep 27, 2022
6aaf8a6
style: (#78) 코드 관련 X 수정
khcho0125 Sep 27, 2022
9eaf4b0
test: (#78) 누락된 부분 추가
khcho0125 Sep 27, 2022
e6d2d46
refactor: (#78) 생성자 추가
khcho0125 Sep 29, 2022
6207b66
fix: (#78) 발송 횟수 수정
khcho0125 Sep 29, 2022
8f35587
build: (#78) DomainService 의존성 주입
khcho0125 Sep 29, 2022
d116bf2
refactor: (#78) DomainService로 분리
khcho0125 Sep 29, 2022
a07848b
refactor: (#78) 생성자 이동
khcho0125 Sep 29, 2022
d7dac8f
refactor: (#78) 생성자 이슈 해결
khcho0125 Sep 30, 2022
4312a84
revert: (#78) allOpen DomainService
khcho0125 Sep 30, 2022
52e6c48
style: (#78) verified → certified
khcho0125 Sep 30, 2022
3aec087
docs: (#78) Default 어노테이션 주석 추가
khcho0125 Sep 30, 2022
ab2c3de
refactor: (#78) HeadMapping
khcho0125 Sep 30, 2022
244f028
revert: (#78) Get Method 사용
khcho0125 Sep 30, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
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.policy.SendAuthCodePolicy
import team.comit.simtong.domain.auth.model.AuthCodeLimit
import team.comit.simtong.domain.auth.spi.CommandAuthCodeLimitPort
import team.comit.simtong.domain.auth.spi.CommandAuthCodePort
import team.comit.simtong.domain.auth.spi.QueryAuthCodeLimitPort
import team.comit.simtong.domain.auth.spi.SendEmailPort
import team.comit.simtong.global.annotation.UseCase

Expand All @@ -18,16 +20,26 @@ import team.comit.simtong.global.annotation.UseCase
**/
@UseCase
class SendAuthCodeUseCase(
private val sendAuthCodePolicy: SendAuthCodePolicy,
private val commandAuthCodeLimitPort: CommandAuthCodeLimitPort,
private val commandAuthCodePort: CommandAuthCodePort,
private val queryAuthCodeLimitPort: QueryAuthCodeLimitPort,
private val sendEmailPort: SendEmailPort
) {

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

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

commandAuthCodeLimitPort.save(authCodeLimit.increaseCount())
khcho0125 marked this conversation as resolved.
Show resolved Hide resolved

val authCode = commandAuthCodePort.save(
AuthCode(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
import org.junit.jupiter.api.extension.ExtendWith
import org.mockito.BDDMockito.given
import org.mockito.BDDMockito.willDoNothing
import org.mockito.kotlin.any
import org.springframework.boot.test.mock.mockito.MockBean
import org.springframework.test.context.junit.jupiter.SpringExtension
import team.comit.simtong.domain.auth.exception.CertifiedEmailException
import team.comit.simtong.domain.auth.exception.ExceededSendAuthCodeRequestException
import team.comit.simtong.domain.auth.model.AuthCode
import team.comit.simtong.domain.auth.model.AuthCodeLimit
import team.comit.simtong.domain.auth.policy.SendAuthCodePolicy
import team.comit.simtong.domain.auth.spi.CommandAuthCodeLimitPort
import team.comit.simtong.domain.auth.spi.CommandAuthCodePort
import team.comit.simtong.domain.auth.spi.QueryAuthCodeLimitPort
Expand All @@ -33,8 +33,6 @@ class SendAuthCodeUseCaseTests {
@MockBean
private lateinit var sendEmailPort: SendEmailPort

private lateinit var sendAuthCodePolicy: SendAuthCodePolicy

private lateinit var sendAuthCodeUseCase: SendAuthCodeUseCase

private val email = "[email protected]"
Expand Down Expand Up @@ -69,11 +67,10 @@ class SendAuthCodeUseCaseTests {

@BeforeEach
fun setUp() {
sendAuthCodePolicy = SendAuthCodePolicy(queryAuthCodeLimitPort)
sendAuthCodeUseCase = SendAuthCodeUseCase(
sendAuthCodePolicy,
commandAuthCodeLimitPort,
commandAuthCodePort,
queryAuthCodeLimitPort,
sendEmailPort
)
}
Expand All @@ -87,6 +84,8 @@ class SendAuthCodeUseCaseTests {
given(commandAuthCodePort.save(any()))
.willReturn(authCodeStub)

willDoNothing().given(sendEmailPort).sendAuthCode(code, email)

// when
sendAuthCodeUseCase.execute(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 team.comit.simtong.domain.auth.exception.ExceededSendAuthCodeRequestException
import team.comit.simtong.global.annotation.Aggregate

/**
Expand Down Expand Up @@ -30,7 +31,11 @@ class AuthCodeLimit(
const val VERIFIED_EXPIRED = 2700
}

fun sendAuthCode(): AuthCodeLimit {
fun increaseCount(): AuthCodeLimit {
if (attemptCount >= VERIFIED_EXPIRED) {
throw ExceededSendAuthCodeRequestException.EXCEPTION
}

return AuthCodeLimit(
key = key,
expirationTime = expirationTime,
Expand Down

This file was deleted.