Skip to content

Commit

Permalink
merge: (#118) 이메일 중복 검사 설계 (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
khcho0125 authored Oct 15, 2022
2 parents 7229601 + fa573b3 commit e670edc
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package team.comit.simtong.domain.user.usecase

import team.comit.simtong.domain.auth.exception.UsedEmailException
import team.comit.simtong.domain.user.spi.QueryUserPort
import team.comit.simtong.global.annotation.ReadOnlyUseCase

/**
*
* 중복된 이메일인지 검사를 담당하는 CheckEmailDuplicationUseCase
*
* @author Chokyunghyeon
* @date 2022/10/14
* @version 1.0.0
**/
@ReadOnlyUseCase
class CheckEmailDuplicationUseCase(
private val queryUserPort: QueryUserPort
) {

fun execute(email: String) {
if (queryUserPort.existsUserByEmail(email)) {
throw UsedEmailException.EXCEPTION
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package team.comit.simtong.domain.user.usecase

import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertDoesNotThrow
import org.junit.jupiter.api.assertThrows
import org.junit.jupiter.api.extension.ExtendWith
import org.mockito.BDDMockito.given
import org.springframework.boot.test.mock.mockito.MockBean
import org.springframework.test.context.junit.jupiter.SpringExtension
import team.comit.simtong.domain.auth.exception.UsedEmailException
import team.comit.simtong.domain.user.spi.QueryUserPort

@ExtendWith(SpringExtension::class)
class CheckEmailDuplicationUseCaseTests {

@MockBean
private lateinit var queryUserPort: QueryUserPort

private lateinit var checkEmailDuplicationUseCase: CheckEmailDuplicationUseCase

private val email = "[email protected]"

@BeforeEach
fun setUp() {
checkEmailDuplicationUseCase = CheckEmailDuplicationUseCase(queryUserPort)
}

@Test
fun `중복 없음`() {
// given
given(queryUserPort.existsUserByEmail(email))
.willReturn(false)

// when & then
assertDoesNotThrow {
checkEmailDuplicationUseCase.execute(email)
}
}

@Test
fun `중복 있음`() {
// given
given(queryUserPort.existsUserByEmail(email))
.willReturn(true)

// when & then
assertThrows<UsedEmailException> {
checkEmailDuplicationUseCase.execute(email)
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class SecurityConfig(
.antMatchers(HttpMethod.PUT, "/users/email").hasRole(ROLE_COMMON.role)

// commons
.antMatchers(HttpMethod.PUT, "/commons/email/duplication").permitAll()
.antMatchers(HttpMethod.GET, "/commons/employee-number").permitAll()
.antMatchers(HttpMethod.PUT, "/commons/token/reissue").permitAll()
.antMatchers(HttpMethod.PUT, "/commons/password/initialization").permitAll()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ import team.comit.simtong.domain.user.dto.ChangePasswordRequest
import team.comit.simtong.domain.user.dto.FindEmployeeNumberRequest
import team.comit.simtong.domain.user.dto.ResetPasswordRequest
import team.comit.simtong.domain.user.usecase.ChangePasswordUseCase
import team.comit.simtong.domain.user.usecase.CheckEmailDuplicationUseCase
import team.comit.simtong.domain.user.usecase.FindEmployeeNumberUseCase
import team.comit.simtong.domain.user.usecase.ResetPasswordUseCase
import javax.validation.Valid
import javax.validation.constraints.Email
import javax.validation.constraints.NotBlank

/**
*
Expand All @@ -30,6 +33,7 @@ class WebCommonAdapter(
private val reissueTokenUseCase: ReissueTokenUseCase,
private val findEmployeeNumberUseCase: FindEmployeeNumberUseCase,
private val resetPasswordUseCase: ResetPasswordUseCase,
private val checkEmailDuplicationUseCase: CheckEmailDuplicationUseCase,
private val changePasswordUseCase: ChangePasswordUseCase
) {

Expand Down Expand Up @@ -61,6 +65,11 @@ class WebCommonAdapter(
)
}

@GetMapping("/email/duplication")
fun checkEmailDuplication(@Email @NotBlank @RequestParam email: String) {
checkEmailDuplicationUseCase.execute(email)
}

@PutMapping("/password")
@ResponseStatus(HttpStatus.NO_CONTENT)
fun changePassword(@Valid @RequestBody request: WebChangePasswordRequest) {
Expand Down

0 comments on commit e670edc

Please sign in to comment.