From eaedc9690b2986b990d7acf0e1d5fecce64b1a63 Mon Sep 17 00:00:00 2001 From: KimBeomJin Date: Wed, 11 Jan 2023 12:24:44 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20(#286)=20User=20Aggregate=20?= =?UTF-8?q?=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/user/usecase/AdminSignInUseCase.kt | 11 ++-- .../domain/user/usecase/ChangeEmailUseCase.kt | 9 +-- .../user/usecase/ChangeNicknameUseCase.kt | 8 +-- .../user/usecase/ChangePasswordUseCase.kt | 13 ++-- .../user/usecase/ChangeProfileImageUseCase.kt | 5 +- .../domain/user/usecase/ChangeSpotUseCase.kt | 5 +- .../usecase/CheckEmailDuplicationUseCase.kt | 1 - .../usecase/CheckMatchedAccountUseCase.kt | 1 - .../CheckNicknameDuplicationUseCase.kt | 1 - .../user/usecase/ComparePasswordUseCase.kt | 5 +- .../user/usecase/FindEmployeeNumberUseCase.kt | 5 +- .../user/usecase/QueryAdminInfoUseCase.kt | 4 +- .../user/usecase/QueryUserInfoUseCase.kt | 4 +- .../user/usecase/ResetPasswordUseCase.kt | 4 +- .../domain/user/usecase/SignInUseCase.kt | 24 ++++---- .../domain/user/usecase/SignUpUseCase.kt | 7 +-- .../simtong/domain/user/model/DeviceToken.kt | 9 ++- .../domain/user/model/EmployeeNumber.kt | 22 +++++++ .../simtong/domain/user/model/NickName.kt | 29 +++++++++ .../simtong/domain/user/model/Password.kt | 29 +++++++++ .../comit/simtong/domain/user/model/User.kt | 60 +++++++++++++++++-- .../persistence/user/mapper/UserMapper.kt | 10 ++-- 22 files changed, 189 insertions(+), 77 deletions(-) create mode 100644 simtong-domain/src/main/kotlin/team/comit/simtong/domain/user/model/EmployeeNumber.kt create mode 100644 simtong-domain/src/main/kotlin/team/comit/simtong/domain/user/model/NickName.kt create mode 100644 simtong-domain/src/main/kotlin/team/comit/simtong/domain/user/model/Password.kt diff --git a/simtong-application/src/main/kotlin/team/comit/simtong/domain/user/usecase/AdminSignInUseCase.kt b/simtong-application/src/main/kotlin/team/comit/simtong/domain/user/usecase/AdminSignInUseCase.kt index 77f80fa5..9dd7cd39 100644 --- a/simtong-application/src/main/kotlin/team/comit/simtong/domain/user/usecase/AdminSignInUseCase.kt +++ b/simtong-application/src/main/kotlin/team/comit/simtong/domain/user/usecase/AdminSignInUseCase.kt @@ -14,8 +14,9 @@ import team.comit.simtong.global.annotation.UseCase * 관리자의 로그인 기능을 담당하는 AdminSignInUseCase * * @author Chokyunghyeon + * @author kimbeomjin * @date 2022/10/04 - * @version 1.0.0 + * @version 1.2.5 **/ @UseCase class AdminSignInUseCase( @@ -26,13 +27,10 @@ class AdminSignInUseCase( fun execute(request: AdminSignInRequest): TokenResponse { val admin = queryUserPort.queryUserByEmployeeNumber(request.employeeNumber) + ?.apply { this.checkAuthority(Authority.ROLE_ADMIN) } ?: throw UserExceptions.NotFound("관리자가 존재하지 않습니다.") - if (Authority.ROLE_COMMON == admin.authority) { - throw UserExceptions.DifferentPermissionAccount("관리자 계정이 아닙니다.") - } - - if (!securityPort.compare(request.password, admin.password)) { + if (!securityPort.compare(request.password, admin.password.value)) { throw UserExceptions.DifferentPassword() } @@ -41,5 +39,4 @@ class AdminSignInUseCase( authority = admin.authority ) } - } \ No newline at end of file diff --git a/simtong-application/src/main/kotlin/team/comit/simtong/domain/user/usecase/ChangeEmailUseCase.kt b/simtong-application/src/main/kotlin/team/comit/simtong/domain/user/usecase/ChangeEmailUseCase.kt index 768a6815..51d14318 100644 --- a/simtong-application/src/main/kotlin/team/comit/simtong/domain/user/usecase/ChangeEmailUseCase.kt +++ b/simtong-application/src/main/kotlin/team/comit/simtong/domain/user/usecase/ChangeEmailUseCase.kt @@ -15,7 +15,7 @@ import team.comit.simtong.global.annotation.UseCase * * @author Chokyunghyeon * @date 2022/10/03 - * @version 1.0.0 + * @version 1.2.5 **/ @UseCase class ChangeEmailUseCase( @@ -38,13 +38,10 @@ class ChangeEmailUseCase( } val currentUserId = securityPort.getCurrentUserId() - val user = queryUserPort.queryUserById(currentUserId) ?: throw UserExceptions.NotFound() + val employee = queryUserPort.queryUserById(currentUserId) ?: throw UserExceptions.NotFound() commandUserPort.save( - user.copy( - email = request.email - ) + employee.changeEmail(request.email) ) } - } \ No newline at end of file diff --git a/simtong-application/src/main/kotlin/team/comit/simtong/domain/user/usecase/ChangeNicknameUseCase.kt b/simtong-application/src/main/kotlin/team/comit/simtong/domain/user/usecase/ChangeNicknameUseCase.kt index 7dade2d5..3b58c9e7 100644 --- a/simtong-application/src/main/kotlin/team/comit/simtong/domain/user/usecase/ChangeNicknameUseCase.kt +++ b/simtong-application/src/main/kotlin/team/comit/simtong/domain/user/usecase/ChangeNicknameUseCase.kt @@ -13,7 +13,7 @@ import team.comit.simtong.global.annotation.UseCase * * @author Chokyunghyeon * @date 2022/10/03 - * @version 1.0.0 + * @version 1.2.5 **/ @UseCase class ChangeNicknameUseCase( @@ -28,12 +28,10 @@ class ChangeNicknameUseCase( } val currentUserId = securityPort.getCurrentUserId() - val user = queryUserPort.queryUserById(currentUserId) ?: throw UserExceptions.NotFound() + val employee = queryUserPort.queryUserById(currentUserId) ?: throw UserExceptions.NotFound() commandUserPort.save( - user.copy( - nickname = request.nickname - ) + employee.changeNickname(request.nickname) ) } } \ No newline at end of file diff --git a/simtong-application/src/main/kotlin/team/comit/simtong/domain/user/usecase/ChangePasswordUseCase.kt b/simtong-application/src/main/kotlin/team/comit/simtong/domain/user/usecase/ChangePasswordUseCase.kt index ff2ebb58..398faddb 100644 --- a/simtong-application/src/main/kotlin/team/comit/simtong/domain/user/usecase/ChangePasswordUseCase.kt +++ b/simtong-application/src/main/kotlin/team/comit/simtong/domain/user/usecase/ChangePasswordUseCase.kt @@ -13,28 +13,27 @@ import team.comit.simtong.global.annotation.UseCase * * @author Chokyunghyeon * @date 2022/10/14 - * @version 1.0.0 + * @version 1.2.5 **/ @UseCase class ChangePasswordUseCase( private val queryUserPort: QueryUserPort, - private val userSecurityPort: UserSecurityPort, + private val securityPort: UserSecurityPort, private val commandUserPort: CommandUserPort ) { fun execute(request: ChangePasswordRequest) { - val currentUserId = userSecurityPort.getCurrentUserId() + val currentUserId = securityPort.getCurrentUserId() val user = queryUserPort.queryUserById(currentUserId) ?: throw UserExceptions.NotFound() - if (!userSecurityPort.compare(request.password, user.password)) { + if (!securityPort.compare(request.password, user.password.value)) { throw UserExceptions.DifferentPassword() } commandUserPort.save( - user.copy( - password = userSecurityPort.encode(request.newPassword) + user.changePassword( + password = securityPort.encode(request.newPassword) ) ) } - } \ No newline at end of file diff --git a/simtong-application/src/main/kotlin/team/comit/simtong/domain/user/usecase/ChangeProfileImageUseCase.kt b/simtong-application/src/main/kotlin/team/comit/simtong/domain/user/usecase/ChangeProfileImageUseCase.kt index 2b174310..c80255a8 100644 --- a/simtong-application/src/main/kotlin/team/comit/simtong/domain/user/usecase/ChangeProfileImageUseCase.kt +++ b/simtong-application/src/main/kotlin/team/comit/simtong/domain/user/usecase/ChangeProfileImageUseCase.kt @@ -15,7 +15,7 @@ import team.comit.simtong.global.annotation.UseCase * * @author Chokyunghyeon * @date 2022/10/03 - * @version 1.0.0 + * @version 1.2.5 **/ @UseCase class ChangeProfileImageUseCase( @@ -34,10 +34,9 @@ class ChangeProfileImageUseCase( val user = queryUserPort.queryUserById(currentUserId) ?: throw UserExceptions.NotFound() commandUserPort.save( - user.copy( + user.changeProfileImage( profileImagePath = request.profileImagePath ) ) } - } \ No newline at end of file diff --git a/simtong-application/src/main/kotlin/team/comit/simtong/domain/user/usecase/ChangeSpotUseCase.kt b/simtong-application/src/main/kotlin/team/comit/simtong/domain/user/usecase/ChangeSpotUseCase.kt index 2336c910..3a7a1348 100644 --- a/simtong-application/src/main/kotlin/team/comit/simtong/domain/user/usecase/ChangeSpotUseCase.kt +++ b/simtong-application/src/main/kotlin/team/comit/simtong/domain/user/usecase/ChangeSpotUseCase.kt @@ -15,7 +15,7 @@ import java.util.UUID * * @author kimbeomjin * @date 2022/10/15 - * @version 1.0.0 + * @version 1.2.5 **/ @UseCase class ChangeSpotUseCase( @@ -34,10 +34,9 @@ class ChangeSpotUseCase( } commandUserPort.save( - user.copy( + user.changeSpot( spotId = newSpotId ) ) } - } \ No newline at end of file diff --git a/simtong-application/src/main/kotlin/team/comit/simtong/domain/user/usecase/CheckEmailDuplicationUseCase.kt b/simtong-application/src/main/kotlin/team/comit/simtong/domain/user/usecase/CheckEmailDuplicationUseCase.kt index ed84637a..5b23f27a 100644 --- a/simtong-application/src/main/kotlin/team/comit/simtong/domain/user/usecase/CheckEmailDuplicationUseCase.kt +++ b/simtong-application/src/main/kotlin/team/comit/simtong/domain/user/usecase/CheckEmailDuplicationUseCase.kt @@ -22,5 +22,4 @@ class CheckEmailDuplicationUseCase( throw AuthExceptions.AlreadyUsedEmail() } } - } \ No newline at end of file diff --git a/simtong-application/src/main/kotlin/team/comit/simtong/domain/user/usecase/CheckMatchedAccountUseCase.kt b/simtong-application/src/main/kotlin/team/comit/simtong/domain/user/usecase/CheckMatchedAccountUseCase.kt index 3d7c296c..34600ab9 100644 --- a/simtong-application/src/main/kotlin/team/comit/simtong/domain/user/usecase/CheckMatchedAccountUseCase.kt +++ b/simtong-application/src/main/kotlin/team/comit/simtong/domain/user/usecase/CheckMatchedAccountUseCase.kt @@ -24,5 +24,4 @@ class CheckMatchedAccountUseCase( throw UserExceptions.NotFound() } } - } \ No newline at end of file diff --git a/simtong-application/src/main/kotlin/team/comit/simtong/domain/user/usecase/CheckNicknameDuplicationUseCase.kt b/simtong-application/src/main/kotlin/team/comit/simtong/domain/user/usecase/CheckNicknameDuplicationUseCase.kt index 9f53e311..f1eaafc2 100644 --- a/simtong-application/src/main/kotlin/team/comit/simtong/domain/user/usecase/CheckNicknameDuplicationUseCase.kt +++ b/simtong-application/src/main/kotlin/team/comit/simtong/domain/user/usecase/CheckNicknameDuplicationUseCase.kt @@ -22,5 +22,4 @@ class CheckNicknameDuplicationUseCase( throw UserExceptions.AlreadyUsedNickname() } } - } \ No newline at end of file diff --git a/simtong-application/src/main/kotlin/team/comit/simtong/domain/user/usecase/ComparePasswordUseCase.kt b/simtong-application/src/main/kotlin/team/comit/simtong/domain/user/usecase/ComparePasswordUseCase.kt index 41108351..e092415c 100644 --- a/simtong-application/src/main/kotlin/team/comit/simtong/domain/user/usecase/ComparePasswordUseCase.kt +++ b/simtong-application/src/main/kotlin/team/comit/simtong/domain/user/usecase/ComparePasswordUseCase.kt @@ -11,7 +11,7 @@ import team.comit.simtong.global.annotation.ReadOnlyUseCase * * @author Chokyunghyeon * @date 2022/12/05 - * @version 1.0.0 + * @version 1.2.5 **/ @ReadOnlyUseCase class ComparePasswordUseCase( @@ -23,9 +23,8 @@ class ComparePasswordUseCase( val user = queryUserPort.queryUserById(securityPort.getCurrentUserId()) ?: throw UserExceptions.NotFound() - if (!securityPort.compare(password, user.password)) { + if (!securityPort.compare(password, user.password.value)) { throw UserExceptions.DifferentPassword() } } - } \ No newline at end of file diff --git a/simtong-application/src/main/kotlin/team/comit/simtong/domain/user/usecase/FindEmployeeNumberUseCase.kt b/simtong-application/src/main/kotlin/team/comit/simtong/domain/user/usecase/FindEmployeeNumberUseCase.kt index de06dcd6..e1c8701e 100644 --- a/simtong-application/src/main/kotlin/team/comit/simtong/domain/user/usecase/FindEmployeeNumberUseCase.kt +++ b/simtong-application/src/main/kotlin/team/comit/simtong/domain/user/usecase/FindEmployeeNumberUseCase.kt @@ -11,7 +11,7 @@ import team.comit.simtong.global.annotation.UseCase * * @author Chokyunghyeon * @date 2022/09/11 - * @version 1.0.0 + * @version 1.2.5 **/ @UseCase class FindEmployeeNumberUseCase( @@ -22,7 +22,6 @@ class FindEmployeeNumberUseCase( val user = queryUserPort.queryUserByNameAndSpotAndEmail(request.name, request.spotId, request.email) ?: throw UserExceptions.NotFound() - return user.employeeNumber + return user.employeeNumber.value } - } \ No newline at end of file diff --git a/simtong-application/src/main/kotlin/team/comit/simtong/domain/user/usecase/QueryAdminInfoUseCase.kt b/simtong-application/src/main/kotlin/team/comit/simtong/domain/user/usecase/QueryAdminInfoUseCase.kt index ecdf4797..adc20ccb 100644 --- a/simtong-application/src/main/kotlin/team/comit/simtong/domain/user/usecase/QueryAdminInfoUseCase.kt +++ b/simtong-application/src/main/kotlin/team/comit/simtong/domain/user/usecase/QueryAdminInfoUseCase.kt @@ -14,7 +14,7 @@ import team.comit.simtong.global.annotation.ReadOnlyUseCase * * @author Chokyunghyeon * @date 2022/12/11 - * @version 1.0.0 + * @version 1.2.5 **/ @ReadOnlyUseCase class QueryAdminInfoUseCase( @@ -33,7 +33,7 @@ class QueryAdminInfoUseCase( return QueryAdminInfoResponse( name = user.name, email = user.email, - nickname = user.nickname, + nickname = user.nickname.value, spot = QueryAdminInfoResponse.SpotResponse( id = spot.id, name = spot.name diff --git a/simtong-application/src/main/kotlin/team/comit/simtong/domain/user/usecase/QueryUserInfoUseCase.kt b/simtong-application/src/main/kotlin/team/comit/simtong/domain/user/usecase/QueryUserInfoUseCase.kt index 0f935a4b..72c0aeba 100644 --- a/simtong-application/src/main/kotlin/team/comit/simtong/domain/user/usecase/QueryUserInfoUseCase.kt +++ b/simtong-application/src/main/kotlin/team/comit/simtong/domain/user/usecase/QueryUserInfoUseCase.kt @@ -14,7 +14,7 @@ import team.comit.simtong.global.annotation.ReadOnlyUseCase * * @author Chokyunghyeon * @date 2022/09/27 - * @version 1.0.0 + * @version 1.2.5 **/ @ReadOnlyUseCase class QueryUserInfoUseCase( @@ -32,7 +32,7 @@ class QueryUserInfoUseCase( return QueryUserInfoResponse( name = user.name, email = user.email, - nickname = user.nickname, + nickname = user.nickname.value, spot = spot.name, profileImagePath = user.profileImagePath ) diff --git a/simtong-application/src/main/kotlin/team/comit/simtong/domain/user/usecase/ResetPasswordUseCase.kt b/simtong-application/src/main/kotlin/team/comit/simtong/domain/user/usecase/ResetPasswordUseCase.kt index c2b77cbb..a21d9444 100644 --- a/simtong-application/src/main/kotlin/team/comit/simtong/domain/user/usecase/ResetPasswordUseCase.kt +++ b/simtong-application/src/main/kotlin/team/comit/simtong/domain/user/usecase/ResetPasswordUseCase.kt @@ -16,7 +16,7 @@ import team.comit.simtong.global.annotation.UseCase * * @author Chokyunghyeon * @date 2022/09/27 - * @version 1.0.0 + * @version 1.2.5 **/ @UseCase class ResetPasswordUseCase( @@ -39,7 +39,7 @@ class ResetPasswordUseCase( ?: throw UserExceptions.NotFound() commandUserPort.save( - user.copy( + user.changePassword( password = securityPort.encode(request.newPassword) ) ) diff --git a/simtong-application/src/main/kotlin/team/comit/simtong/domain/user/usecase/SignInUseCase.kt b/simtong-application/src/main/kotlin/team/comit/simtong/domain/user/usecase/SignInUseCase.kt index 93cb85f6..c5e5b4ca 100644 --- a/simtong-application/src/main/kotlin/team/comit/simtong/domain/user/usecase/SignInUseCase.kt +++ b/simtong-application/src/main/kotlin/team/comit/simtong/domain/user/usecase/SignInUseCase.kt @@ -17,39 +17,35 @@ import team.comit.simtong.global.annotation.UseCase * * @author kimbeomjin * @date 2022/09/08 - * @version 1.0.0 + * @version 1.2.5 **/ @UseCase class SignInUseCase( private val queryUserPort: QueryUserPort, - private val userSecurityPort: UserSecurityPort, - private val userJwtPort: UserJwtPort, + private val securityPort: UserSecurityPort, + private val jwtPort: UserJwtPort, private val commandDeviceTokenPort: CommandDeviceTokenPort ) { fun execute(request: UserSignInRequest): TokenResponse { - val user = queryUserPort.queryUserByEmployeeNumber(request.employeeNumber) + val employee = queryUserPort.queryUserByEmployeeNumber(request.employeeNumber) + ?.apply { checkAuthority(Authority.ROLE_COMMON) } ?: throw UserExceptions.NotFound() - if (Authority.ROLE_COMMON != user.authority) { - throw UserExceptions.DifferentPermissionAccount("사원 계정이 아닙니다.") - } - - if (!userSecurityPort.compare(request.password, user.password)) { + if (!securityPort.compare(request.password, employee.password.value)) { throw UserExceptions.DifferentPassword() } commandDeviceTokenPort.save( - DeviceToken( - userId = user.id, + DeviceToken.of( + userId = employee.id, token = request.deviceToken ) ) - return userJwtPort.receiveToken( - userId = user.id, + return jwtPort.receiveToken( + userId = employee.id, authority = Authority.ROLE_COMMON ) } - } \ No newline at end of file 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 f3e3d03a..a6722b99 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 @@ -29,7 +29,7 @@ import team.comit.simtong.global.annotation.UseCase * @author Chokyunghyeon * @author kimbeomjin * @date 2022/09/04 - * @version 1.2.1 + * @version 1.2.5 **/ @UseCase class SignUpUseCase( @@ -76,7 +76,7 @@ class SignUpUseCase( ?: throw TeamExceptions.NotFound() val user = commandUserPort.save( - User( + User.of( nickname = nickname, name = name, email = email, @@ -92,7 +92,7 @@ class SignUpUseCase( commandAuthCodeLimitPort.delete(authCodeLimit) commandDeviceTokenPort.save( - DeviceToken( + DeviceToken.of( userId = user.id, token = request.deviceToken ) @@ -103,5 +103,4 @@ class SignUpUseCase( authority = user.authority ) } - } \ No newline at end of file diff --git a/simtong-domain/src/main/kotlin/team/comit/simtong/domain/user/model/DeviceToken.kt b/simtong-domain/src/main/kotlin/team/comit/simtong/domain/user/model/DeviceToken.kt index f4281651..e2d7c4a8 100644 --- a/simtong-domain/src/main/kotlin/team/comit/simtong/domain/user/model/DeviceToken.kt +++ b/simtong-domain/src/main/kotlin/team/comit/simtong/domain/user/model/DeviceToken.kt @@ -9,11 +9,16 @@ import java.util.UUID * * @author kimbeomjin * @date 2023/01/01 - * @version 1.1.0 + * @version 1.2.5 **/ @Aggregate data class DeviceToken( val userId: UUID, val token: String -) +) { + + companion object { + fun of(userId: UUID, token: String) = DeviceToken(userId, token) + } +} diff --git a/simtong-domain/src/main/kotlin/team/comit/simtong/domain/user/model/EmployeeNumber.kt b/simtong-domain/src/main/kotlin/team/comit/simtong/domain/user/model/EmployeeNumber.kt new file mode 100644 index 00000000..3ed90a34 --- /dev/null +++ b/simtong-domain/src/main/kotlin/team/comit/simtong/domain/user/model/EmployeeNumber.kt @@ -0,0 +1,22 @@ +package team.comit.simtong.domain.user.model + +/** + * + * EmployeeNumber + * + * @author kimbeomjin + * @date 2023/01/10 + * @version 1.2.5 + **/ +@JvmInline +value class EmployeeNumber( + val value: Int +) { + + companion object { + const val MIN_VALUE: Long = 1200000000 + const val MAX_VALUE: Long = 1299999999 + + fun of(employeeNumber: Int) = EmployeeNumber(employeeNumber) + } +} \ No newline at end of file diff --git a/simtong-domain/src/main/kotlin/team/comit/simtong/domain/user/model/NickName.kt b/simtong-domain/src/main/kotlin/team/comit/simtong/domain/user/model/NickName.kt new file mode 100644 index 00000000..8ac732d6 --- /dev/null +++ b/simtong-domain/src/main/kotlin/team/comit/simtong/domain/user/model/NickName.kt @@ -0,0 +1,29 @@ +package team.comit.simtong.domain.user.model + +/** + * + * NickName + * + * @author kimbeomjin + * @date 2023/01/10 + * @version 1.2.5 + **/ +@JvmInline +value class NickName( + val value: String +) { + + companion object { + const val MIN_LENGTH = 1 + const val MAX_LENGTH = 20 + + /** + * first word & Last word - space X + * + * space , _ , . , a ~ z , A ~ Z , 가 ~ 힣 , 0 ~ 9 + */ + const val PATTERN = """(?=^\S)(?=^[\w\s가-힣.]{$MIN_LENGTH,$MAX_LENGTH}$).*(?=\S$).""" + + fun of(nickName: String) = NickName(nickName) + } +} \ No newline at end of file diff --git a/simtong-domain/src/main/kotlin/team/comit/simtong/domain/user/model/Password.kt b/simtong-domain/src/main/kotlin/team/comit/simtong/domain/user/model/Password.kt new file mode 100644 index 00000000..b4dd32d6 --- /dev/null +++ b/simtong-domain/src/main/kotlin/team/comit/simtong/domain/user/model/Password.kt @@ -0,0 +1,29 @@ +package team.comit.simtong.domain.user.model + +/** + * + * Password + * + * @author kimbeomjin + * @date 2023/01/10 + * @version 1.2.5 + **/ +@JvmInline +value class Password( + val value: String +) { + + companion object { + const val MIN_LENGTH = 8 + const val MAX_LENGTH = 20 + + /** + * a ~ z or A ~ Z & 0 ~ 9 - must more than once + * + * non-space, $ , + , - , _ , a ~ z , A ~ Z , 0 ~ 9 + */ + const val PATTERN = """(?=.*[a-zA-Z])(?=.*\d)(?=^[\w$+-]{$MIN_LENGTH,$MAX_LENGTH$).*""" + + fun of(password: String) = Password(password) + } +} \ No newline at end of file diff --git a/simtong-domain/src/main/kotlin/team/comit/simtong/domain/user/model/User.kt b/simtong-domain/src/main/kotlin/team/comit/simtong/domain/user/model/User.kt index 02d70913..f94cc1c6 100644 --- a/simtong-domain/src/main/kotlin/team/comit/simtong/domain/user/model/User.kt +++ b/simtong-domain/src/main/kotlin/team/comit/simtong/domain/user/model/User.kt @@ -1,5 +1,6 @@ package team.comit.simtong.domain.user.model +import team.comit.simtong.domain.user.exception.UserExceptions import team.comit.simtong.global.DomainProperties.getProperty import team.comit.simtong.global.DomainPropertiesPrefix import team.comit.simtong.global.annotation.Aggregate @@ -13,21 +14,21 @@ import java.util.UUID * @author Chokyunghyeon * @author kimbeomjin * @date 2022/09/04 - * @version 1.0.0 + * @version 1.2.5 **/ @Aggregate data class User( - val id: UUID = UUID(0, 0), + val id: UUID, - val nickname: String, + val nickname: NickName, val name: String, val email: String, - val password: String, + val password: Password, - val employeeNumber: Int, + val employeeNumber: EmployeeNumber, val authority: Authority, @@ -37,12 +38,59 @@ data class User( val profileImagePath: String, - val deletedAt: LocalDateTime? = null + val deletedAt: LocalDateTime? ) { companion object { + fun of( + id: UUID = UUID(0, 0), + nickname: String, + name: String, + email: String, + password: String, + employeeNumber: Int, + authority: Authority, + spotId: UUID, + teamId: UUID, + profileImagePath: String, + deletedAt: LocalDateTime? = null + ) = User( + id = id, + nickname = NickName.of(nickname), + name = name, + email = email, + password = Password.of(password), + employeeNumber = EmployeeNumber.of(employeeNumber), + authority = authority, + spotId = spotId, + teamId = teamId, + profileImagePath = profileImagePath, + deletedAt = deletedAt + ) + @JvmField val DEFAULT_IMAGE = getProperty(DomainPropertiesPrefix.USER_DEFAULT_IMAGE) } + fun checkAuthority(authority: Authority) { + when(authority) { + Authority.ROLE_COMMON -> if (!isEmployee()) throw UserExceptions.DifferentPermissionAccount("사원 계정이 아닙니다.") + + Authority.ROLE_SUPER, Authority.ROLE_ADMIN -> if (!isAdmin()) throw UserExceptions.DifferentPermissionAccount("관리자 계정이 아닙니다.") + } + } + + fun isAdmin() = (this.authority == Authority.ROLE_ADMIN) || (this.authority == Authority.ROLE_SUPER) + + fun isEmployee() = this.authority == Authority.ROLE_COMMON + + fun changeEmail(email: String) = this.copy(email = email) + + fun changeNickname(nickname: String) = this.copy(nickname = NickName.of(nickname)) + + fun changePassword(password: String) = this.copy(password = Password.of(password)) + + fun changeProfileImage(profileImagePath: String) = this.copy(profileImagePath = profileImagePath) + + fun changeSpot(spotId: UUID) = this.copy(spotId = spotId) } \ No newline at end of file diff --git a/simtong-infrastructure/src/main/kotlin/team/comit/simtong/persistence/user/mapper/UserMapper.kt b/simtong-infrastructure/src/main/kotlin/team/comit/simtong/persistence/user/mapper/UserMapper.kt index 9ce8221a..f6c9ff3f 100644 --- a/simtong-infrastructure/src/main/kotlin/team/comit/simtong/persistence/user/mapper/UserMapper.kt +++ b/simtong-infrastructure/src/main/kotlin/team/comit/simtong/persistence/user/mapper/UserMapper.kt @@ -29,12 +29,12 @@ class UserMapper( return UserJpaEntity( id = model.id, - employeeNumber = model.employeeNumber, + employeeNumber = model.employeeNumber.value, email = model.email, authority = model.authority, name = model.name, - nickname = model.nickname, - password = model.password, + nickname = model.nickname.value, + password = model.password.value, spot = spot, team = team, profileImagePath = model.profileImagePath, @@ -44,7 +44,7 @@ class UserMapper( override fun toDomain(entity: UserJpaEntity?): User? { return entity?.let { - User( + User.of( id = it.id!!, nickname = it.nickname, name = it.name, @@ -61,7 +61,7 @@ class UserMapper( } override fun toDomainNotNull(entity: UserJpaEntity): User { - return User( + return User.of( id = entity.id!!, nickname = entity.nickname, name = entity.name,