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: (#194) 회원가입 사원 정보 확인 #195

Merged
merged 6 commits into from
Dec 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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,5 +1,7 @@
package team.comit.simtong.domain.file.spi

import team.comit.simtong.domain.user.spi.UserQueryEmployeeCertificatePort

/**
*
* 직원 명부 Domain에 관한 요청을 하는 EmployeeCertificatePort
Expand All @@ -8,4 +10,4 @@ package team.comit.simtong.domain.file.spi
* @date 2022/12/06
* @version 1.0.0
**/
interface EmployeeCertificatePort : CommandEmployeeCertificatePort, QueryEmployeeCertificatePort
interface EmployeeCertificatePort : CommandEmployeeCertificatePort, QueryEmployeeCertificatePort, UserQueryEmployeeCertificatePort
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import team.comit.simtong.domain.auth.dto.TokenResponse
import team.comit.simtong.domain.auth.exception.RequiredNewEmailAuthenticationException
import team.comit.simtong.domain.auth.exception.UncertifiedEmailException
import team.comit.simtong.domain.auth.exception.UsedEmailException
import team.comit.simtong.domain.file.exception.InvalidEmployeeException
import team.comit.simtong.domain.spot.exception.SpotNotFoundException
import team.comit.simtong.domain.team.exception.TeamNotFoundException
import team.comit.simtong.domain.user.dto.SignUpRequest
Expand All @@ -14,6 +15,7 @@ import team.comit.simtong.domain.user.spi.QueryUserPort
import team.comit.simtong.domain.user.spi.UserCommandAuthCodeLimitPort
import team.comit.simtong.domain.user.spi.UserJwtPort
import team.comit.simtong.domain.user.spi.UserQueryAuthCodeLimitPort
import team.comit.simtong.domain.user.spi.UserQueryEmployeeCertificatePort
import team.comit.simtong.domain.user.spi.UserQuerySpotPort
import team.comit.simtong.domain.user.spi.UserQueryTeamPort
import team.comit.simtong.domain.user.spi.UserSecurityPort
Expand All @@ -37,8 +39,8 @@ class SignUpUseCase(
private val commandAuthCodeLimitPort: UserCommandAuthCodeLimitPort,
private val querySpotPort: UserQuerySpotPort,
private val queryTeamPort: UserQueryTeamPort,
// private val nickNamePort: NickNamePort,
private val securityPort: UserSecurityPort
private val securityPort: UserSecurityPort,
private val queryEmployeeCertificatePort: UserQueryEmployeeCertificatePort
) {

fun execute(request: SignUpRequest): TokenResponse {
Expand All @@ -55,18 +57,18 @@ class SignUpUseCase(
throw UncertifiedEmailException.EXCEPTION
}

// TODO 비즈니스 로직 직접 구현
// 임직원 확인
val employeeCertificate = queryEmployeeCertificatePort.queryEmployeeCertificateByNameAndEmployeeNumber(name, employeeNumber)
?: throw InvalidEmployeeException.EXCEPTION

val spot = querySpotPort.querySpotByName("test spotName")
val spot = querySpotPort.querySpotByName(employeeCertificate.spotName)
?: throw SpotNotFoundException.EXCEPTION

val team = queryTeamPort.queryTeamByName("test teamName")
val team = queryTeamPort.queryTeamByName(employeeCertificate.teamName)
?: throw TeamNotFoundException.EXCEPTION

val user = commandUserPort.save(
User(
nickname = nickname ?: "", // nickNamePort.random()
nickname = nickname ?: "", // TODO 랜덤 닉네임
name = name,
email = email,
password = securityPort.encode(password),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import team.comit.simtong.domain.auth.exception.RequiredNewEmailAuthenticationEx
import team.comit.simtong.domain.auth.exception.UncertifiedEmailException
import team.comit.simtong.domain.auth.exception.UsedEmailException
import team.comit.simtong.domain.auth.model.AuthCodeLimit
import team.comit.simtong.domain.file.exception.InvalidEmployeeException
import team.comit.simtong.domain.file.model.EmployeeCertificate
import team.comit.simtong.domain.spot.exception.SpotNotFoundException
import team.comit.simtong.domain.spot.model.Spot
import team.comit.simtong.domain.team.exception.TeamNotFoundException
Expand All @@ -23,11 +25,13 @@ import team.comit.simtong.domain.user.spi.QueryUserPort
import team.comit.simtong.domain.user.spi.UserCommandAuthCodeLimitPort
import team.comit.simtong.domain.user.spi.UserJwtPort
import team.comit.simtong.domain.user.spi.UserQueryAuthCodeLimitPort
import team.comit.simtong.domain.user.spi.UserQueryEmployeeCertificatePort
import team.comit.simtong.domain.user.spi.UserQuerySpotPort
import team.comit.simtong.domain.user.spi.UserQueryTeamPort
import team.comit.simtong.domain.user.spi.UserSecurityPort
import team.comit.simtong.global.annotation.SimtongTest
import java.util.*
import java.util.Date
import java.util.UUID

@SimtongTest
class SignUpUseCaseTests {
Expand Down Expand Up @@ -56,6 +60,9 @@ class SignUpUseCaseTests {
@MockBean
private lateinit var commandAuthCodeLimitPort: UserCommandAuthCodeLimitPort

@MockBean
private lateinit var queryEmployeeCertificatePort: UserQueryEmployeeCertificatePort

private lateinit var signUpUseCase: SignUpUseCase

private val employeeNumber: Int = 1234567891
Expand Down Expand Up @@ -112,6 +119,15 @@ class SignUpUseCaseTests {
)
}

private val employeeCertificateStub: EmployeeCertificate by lazy {
EmployeeCertificate(
employeeNumber = employeeNumber,
name = name,
spotName = spotName,
teamName = teamName
)
}

private val requestStub: SignUpRequest by lazy {
SignUpRequest(
nickname = nickname,
Expand Down Expand Up @@ -141,7 +157,8 @@ class SignUpUseCaseTests {
commandAuthCodeLimitPort,
userQuerySpotPort,
userQueryTeamPort,
userSecurityPort
userSecurityPort,
queryEmployeeCertificatePort
)
}

Expand All @@ -160,21 +177,24 @@ class SignUpUseCaseTests {
profileImagePath = profileImagePath
)

given(userQueryAuthCodeLimitPort.queryAuthCodeLimitByEmail(requestStub.email))
.willReturn(authCodeLimitStub)

given(queryUserPort.existsUserByEmail(requestStub.email))
.willReturn(false)

given(userSecurityPort.encode(requestStub.password))
.willReturn(userStub.password)
given(userQueryAuthCodeLimitPort.queryAuthCodeLimitByEmail(requestStub.email))
.willReturn(authCodeLimitStub)

given(queryEmployeeCertificatePort.queryEmployeeCertificateByNameAndEmployeeNumber(requestStub.name, requestStub.employeeNumber))
.willReturn(employeeCertificateStub)

given(userQuerySpotPort.querySpotByName(spotName))
given(userQuerySpotPort.querySpotByName(employeeCertificateStub.spotName))
.willReturn(spotStub)

given(userQueryTeamPort.queryTeamByName(teamName))
given(userQueryTeamPort.queryTeamByName(employeeCertificateStub.teamName))
.willReturn(teamStub)

given(userSecurityPort.encode(requestStub.password))
.willReturn(userStub.password)

given(commandUserPort.save(userStub))
.willReturn(saveUserStub)

Expand Down Expand Up @@ -212,21 +232,24 @@ class SignUpUseCaseTests {
profileImagePath = User.DEFAULT_IMAGE
)

given(userQueryAuthCodeLimitPort.queryAuthCodeLimitByEmail(requestStub.email))
.willReturn(authCodeLimitStub)

given(queryUserPort.existsUserByEmail(requestStub.email))
.willReturn(false)

given(userSecurityPort.encode(requestStub.password))
.willReturn(userStub.password)
given(userQueryAuthCodeLimitPort.queryAuthCodeLimitByEmail(requestStub.email))
.willReturn(authCodeLimitStub)

given(queryEmployeeCertificatePort.queryEmployeeCertificateByNameAndEmployeeNumber(requestStub.name, requestStub.employeeNumber))
.willReturn(employeeCertificateStub)

given(userQuerySpotPort.querySpotByName(spotName))
given(userQuerySpotPort.querySpotByName(employeeCertificateStub.spotName))
.willReturn(spotStub)

given(userQueryTeamPort.queryTeamByName(teamName))
given(userQueryTeamPort.queryTeamByName(employeeCertificateStub.teamName))
.willReturn(teamStub)

given(userSecurityPort.encode(requestStub.password))
.willReturn(userStub.password)

given(commandUserPort.save(userStub))
.willReturn(saveUserStub)

Expand Down Expand Up @@ -286,6 +309,24 @@ class SignUpUseCaseTests {
}
}

@Test
fun `사원 정보 찾기 실패`() {
// given
given(userQueryAuthCodeLimitPort.queryAuthCodeLimitByEmail(requestStub.email))
.willReturn(authCodeLimitStub)

given(queryUserPort.existsUserByEmail(requestStub.email))
.willReturn(false)

given(queryEmployeeCertificatePort.queryEmployeeCertificateByNameAndEmployeeNumber(requestStub.name, requestStub.employeeNumber))
.willReturn(null)

// when & then
assertThrows<InvalidEmployeeException> {
signUpUseCase.execute(requestStub)
}
}

@Test
fun `지점 찾기 실패`() {
// given
Expand All @@ -295,7 +336,10 @@ class SignUpUseCaseTests {
given(queryUserPort.existsUserByEmail(requestStub.email))
.willReturn(false)

given(userQuerySpotPort.querySpotByName(spotName))
given(queryEmployeeCertificatePort.queryEmployeeCertificateByNameAndEmployeeNumber(requestStub.name, requestStub.employeeNumber))
.willReturn(employeeCertificateStub)

given(userQuerySpotPort.querySpotByName(employeeCertificateStub.spotName))
.willReturn(null)

// when & then
Expand All @@ -313,10 +357,13 @@ class SignUpUseCaseTests {
given(queryUserPort.existsUserByEmail(requestStub.email))
.willReturn(false)

given(userQuerySpotPort.querySpotByName(spotName))
given(queryEmployeeCertificatePort.queryEmployeeCertificateByNameAndEmployeeNumber(requestStub.name, requestStub.employeeNumber))
.willReturn(employeeCertificateStub)

given(userQuerySpotPort.querySpotByName(employeeCertificateStub.spotName))
.willReturn(spotStub)

given(userQueryTeamPort.queryTeamByName(teamName))
given(userQueryTeamPort.queryTeamByName(employeeCertificateStub.teamName))
.willReturn(null)

// when & then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ package team.comit.simtong.domain.file.exception
import team.comit.simtong.domain.file.error.FileErrorCode
import team.comit.simtong.global.error.BusinessException

/**
*
* 파일 경로를 찾을 수 없음 에러를 발생시키는 NotFoundFilePathException
*
* @author Chokyunghyeon
* @date 2022/12/08
* @version 1.0.0
**/
class NotFoundFilePathException private constructor() : BusinessException(FileErrorCode.NOT_FOUND_FILE_PATH) {

companion object {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package team.comit.simtong.domain.user.spi

import team.comit.simtong.domain.file.model.EmployeeCertificate

/**
*
* User Domain에서 Employee Certificate에 관한 Query를 요청하는 UserQueryEmployeeCertificatePort
*
* @author Chokyunghyeon
* @date 2022/12/07
* @version 1.0.0
**/
interface UserQueryEmployeeCertificatePort {

fun queryEmployeeCertificateByNameAndEmployeeNumber(name: String, employeeNumber: Int) : EmployeeCertificate?
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import team.comit.simtong.persistence.file.entity.EmployeeCertificateJpaEntity

/**
*
* Spring Repository 기능을 이용하는 EmployeeProofJpaRepository
* Spring Repository 기능을 이용하는 EmployeeCertificateJpaRepository
*
* @author Chokyunghyeon
* @date 2022/12/06
Expand All @@ -17,4 +17,6 @@ interface EmployeeCertificateJpaRepository : CrudRepository<EmployeeCertificateJ

fun existsByNameAndEmployeeNumber(name: String, employeeNumber: Int): Boolean

fun queryEmployeeCertificateJpaEntityByNameAndEmployeeNumber(name: String, employeeNumber: Int): EmployeeCertificateJpaEntity?

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package team.comit.simtong.persistence.file

import org.springframework.stereotype.Component
import team.comit.simtong.domain.file.model.EmployeeCertificate
import team.comit.simtong.domain.file.spi.EmployeeCertificatePort
import team.comit.simtong.persistence.file.mapper.EmployeeCertificateMapper

/**
*
* 직원 명부의 영속성을 관리하는 EmployeeProofPersistenceAdapter
* 직원 명부의 영속성을 관리하는 EmployeeCertificatePersistenceAdapter
*
* @author Chokyunghyeon
* @date 2022/12/06
Expand All @@ -17,9 +18,19 @@ class EmployeeCertificatePersistenceAdapter(
private val employeeCertificateJpaRepository: EmployeeCertificateJpaRepository,
private val employeeCertificateMapper: EmployeeCertificateMapper
) : EmployeeCertificatePort {

override fun existsEmployeeCertificateByNameAndEmployeeNumber(
name: String,
employeeNumber: Int
) = employeeCertificateJpaRepository.existsByNameAndEmployeeNumber(name, employeeNumber)

override fun queryEmployeeCertificateByNameAndEmployeeNumber(
name: String,
employeeNumber: Int
): EmployeeCertificate? {
return employeeCertificateMapper.toDomain(
employeeCertificateJpaRepository.queryEmployeeCertificateJpaEntityByNameAndEmployeeNumber(name, employeeNumber)
)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ import javax.persistence.Entity
import javax.persistence.Id
import javax.persistence.Table

/**
*
* 사원 명부를 관리하는 EmployeeCertificateJpaEntity
*
* @author Chokyunghyeon
* @date 2022/12/08
* @version 1.0.0
**/
@Entity
@Table(name = "tbl_employee_certificate")
data class EmployeeCertificateJpaEntity(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import team.comit.simtong.persistence.file.entity.EmployeeCertificateJpaEntity

/**
*
* 직원 명부 EmployeeProofMapper
* EmployeeCertificate Entity와 Employee Certificate Aggregate를 변환하는 EmployeeCertificateMapper
*
* @author Chokyunghyeon
* @date 2022/12/06
Expand Down