From 5df34ba34371a5e4aa9e352b7c311931335e21b8 Mon Sep 17 00:00:00 2001 From: Jo Kyung Hyeon Date: Thu, 8 Dec 2022 00:28:55 +0900 Subject: [PATCH 1/4] =?UTF-8?q?docs:=20(#194)=20=EC=82=AC=EC=9B=90=20?= =?UTF-8?q?=EB=AA=85=EB=B6=80=20javadoc=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../file/entity/EmployeeCertificateJpaEntity.kt | 8 ++++++++ .../persistence/file/mapper/EmployeeCertificateMapper.kt | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/simtong-infrastructure/src/main/kotlin/team/comit/simtong/persistence/file/entity/EmployeeCertificateJpaEntity.kt b/simtong-infrastructure/src/main/kotlin/team/comit/simtong/persistence/file/entity/EmployeeCertificateJpaEntity.kt index 6fd12ced..6d42c8d1 100644 --- a/simtong-infrastructure/src/main/kotlin/team/comit/simtong/persistence/file/entity/EmployeeCertificateJpaEntity.kt +++ b/simtong-infrastructure/src/main/kotlin/team/comit/simtong/persistence/file/entity/EmployeeCertificateJpaEntity.kt @@ -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( diff --git a/simtong-infrastructure/src/main/kotlin/team/comit/simtong/persistence/file/mapper/EmployeeCertificateMapper.kt b/simtong-infrastructure/src/main/kotlin/team/comit/simtong/persistence/file/mapper/EmployeeCertificateMapper.kt index c169e214..2cec1932 100644 --- a/simtong-infrastructure/src/main/kotlin/team/comit/simtong/persistence/file/mapper/EmployeeCertificateMapper.kt +++ b/simtong-infrastructure/src/main/kotlin/team/comit/simtong/persistence/file/mapper/EmployeeCertificateMapper.kt @@ -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 From 1520d9965c66058a7621563e3ed194ca22680721 Mon Sep 17 00:00:00 2001 From: Jo Kyung Hyeon Date: Thu, 8 Dec 2022 00:29:52 +0900 Subject: [PATCH 2/4] =?UTF-8?q?feat:=20(#194)=20=EC=82=AC=EC=9B=90=20?= =?UTF-8?q?=EB=AA=85=EB=B6=80=20=EA=B4=80=EB=A0=A8=20=EC=BF=BC=EB=A6=AC=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/file/spi/EmployeeCertificatePort.kt | 4 +++- .../user/spi/UserQueryEmployeeCertificatePort.kt | 16 ++++++++++++++++ .../file/EmployeeCertificateJpaRepository.kt | 4 +++- .../EmployeeCertificatePersistenceAdapter.kt | 13 ++++++++++++- 4 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 simtong-domain/src/main/kotlin/team/comit/simtong/domain/user/spi/UserQueryEmployeeCertificatePort.kt diff --git a/simtong-application/src/main/kotlin/team/comit/simtong/domain/file/spi/EmployeeCertificatePort.kt b/simtong-application/src/main/kotlin/team/comit/simtong/domain/file/spi/EmployeeCertificatePort.kt index 66e79d04..2dfc419d 100644 --- a/simtong-application/src/main/kotlin/team/comit/simtong/domain/file/spi/EmployeeCertificatePort.kt +++ b/simtong-application/src/main/kotlin/team/comit/simtong/domain/file/spi/EmployeeCertificatePort.kt @@ -1,5 +1,7 @@ package team.comit.simtong.domain.file.spi +import team.comit.simtong.domain.user.spi.UserQueryEmployeeCertificatePort + /** * * 직원 명부 Domain에 관한 요청을 하는 EmployeeCertificatePort @@ -8,4 +10,4 @@ package team.comit.simtong.domain.file.spi * @date 2022/12/06 * @version 1.0.0 **/ -interface EmployeeCertificatePort : CommandEmployeeCertificatePort, QueryEmployeeCertificatePort \ No newline at end of file +interface EmployeeCertificatePort : CommandEmployeeCertificatePort, QueryEmployeeCertificatePort, UserQueryEmployeeCertificatePort \ No newline at end of file diff --git a/simtong-domain/src/main/kotlin/team/comit/simtong/domain/user/spi/UserQueryEmployeeCertificatePort.kt b/simtong-domain/src/main/kotlin/team/comit/simtong/domain/user/spi/UserQueryEmployeeCertificatePort.kt new file mode 100644 index 00000000..1774b47a --- /dev/null +++ b/simtong-domain/src/main/kotlin/team/comit/simtong/domain/user/spi/UserQueryEmployeeCertificatePort.kt @@ -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? +} \ No newline at end of file diff --git a/simtong-infrastructure/src/main/kotlin/team/comit/simtong/persistence/file/EmployeeCertificateJpaRepository.kt b/simtong-infrastructure/src/main/kotlin/team/comit/simtong/persistence/file/EmployeeCertificateJpaRepository.kt index 65720603..dec5b172 100644 --- a/simtong-infrastructure/src/main/kotlin/team/comit/simtong/persistence/file/EmployeeCertificateJpaRepository.kt +++ b/simtong-infrastructure/src/main/kotlin/team/comit/simtong/persistence/file/EmployeeCertificateJpaRepository.kt @@ -6,7 +6,7 @@ import team.comit.simtong.persistence.file.entity.EmployeeCertificateJpaEntity /** * - * Spring Repository 기능을 이용하는 EmployeeProofJpaRepository + * Spring Repository 기능을 이용하는 EmployeeCertificateJpaRepository * * @author Chokyunghyeon * @date 2022/12/06 @@ -17,4 +17,6 @@ interface EmployeeCertificateJpaRepository : CrudRepository Date: Thu, 8 Dec 2022 00:30:22 +0900 Subject: [PATCH 3/4] =?UTF-8?q?refactor:=20(#194)=20=ED=9A=8C=EC=9B=90?= =?UTF-8?q?=EA=B0=80=EC=9E=85=20=EC=B6=94=EA=B0=80=20=EB=A1=9C=EC=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/user/usecase/SignUpUseCase.kt | 16 ++-- .../domain/user/usecase/SignUpUseCaseTests.kt | 85 ++++++++++++++----- 2 files changed, 75 insertions(+), 26 deletions(-) diff --git a/simtong-application/src/main/kotlin/team/comit/simtong/domain/user/usecase/SignUpUseCase.kt b/simtong-application/src/main/kotlin/team/comit/simtong/domain/user/usecase/SignUpUseCase.kt index 8d3549b9..ae01ea73 100644 --- a/simtong-application/src/main/kotlin/team/comit/simtong/domain/user/usecase/SignUpUseCase.kt +++ b/simtong-application/src/main/kotlin/team/comit/simtong/domain/user/usecase/SignUpUseCase.kt @@ -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 @@ -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 @@ -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 { @@ -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), diff --git a/simtong-application/src/test/kotlin/team/comit/simtong/domain/user/usecase/SignUpUseCaseTests.kt b/simtong-application/src/test/kotlin/team/comit/simtong/domain/user/usecase/SignUpUseCaseTests.kt index 564972e3..5181d881 100644 --- a/simtong-application/src/test/kotlin/team/comit/simtong/domain/user/usecase/SignUpUseCaseTests.kt +++ b/simtong-application/src/test/kotlin/team/comit/simtong/domain/user/usecase/SignUpUseCaseTests.kt @@ -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 @@ -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 { @@ -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 @@ -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, @@ -141,7 +157,8 @@ class SignUpUseCaseTests { commandAuthCodeLimitPort, userQuerySpotPort, userQueryTeamPort, - userSecurityPort + userSecurityPort, + queryEmployeeCertificatePort ) } @@ -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) @@ -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) @@ -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 { + signUpUseCase.execute(requestStub) + } + } + @Test fun `지점 찾기 실패`() { // given @@ -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 @@ -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 From 6c2291bb4a26177ce8118290ef1c4be6dc579b25 Mon Sep 17 00:00:00 2001 From: Jo Kyung Hyeon Date: Thu, 8 Dec 2022 00:36:23 +0900 Subject: [PATCH 4/4] =?UTF-8?q?docs:=20(#194)=20=EB=88=84=EB=9D=BD?= =?UTF-8?q?=EB=90=9C=20javadoc=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/file/exception/NotFoundFilePathException.kt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/simtong-domain/src/main/kotlin/team/comit/simtong/domain/file/exception/NotFoundFilePathException.kt b/simtong-domain/src/main/kotlin/team/comit/simtong/domain/file/exception/NotFoundFilePathException.kt index 030fd8b4..b6e40c82 100644 --- a/simtong-domain/src/main/kotlin/team/comit/simtong/domain/file/exception/NotFoundFilePathException.kt +++ b/simtong-domain/src/main/kotlin/team/comit/simtong/domain/file/exception/NotFoundFilePathException.kt @@ -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 {