Skip to content

Commit

Permalink
merge: (#286) User 도메인 리팩토링 (#307)
Browse files Browse the repository at this point in the history
  • Loading branch information
softpeanut authored Jan 13, 2023
2 parents 020bbef + 517c809 commit 0bd21fc
Show file tree
Hide file tree
Showing 51 changed files with 286 additions and 189 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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()
}

Expand All @@ -41,5 +39,4 @@ class AdminSignInUseCase(
authority = admin.authority
)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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)
)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -34,10 +34,9 @@ class ChangeProfileImageUseCase(
val user = queryUserPort.queryUserById(currentUserId) ?: throw UserExceptions.NotFound()

commandUserPort.save(
user.copy(
user.changeProfileImage(
profileImagePath = request.profileImagePath
)
)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -34,10 +34,9 @@ class ChangeSpotUseCase(
}

commandUserPort.save(
user.copy(
user.changeSpot(
spotId = newSpotId
)
)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,4 @@ class CheckEmailDuplicationUseCase(
throw AuthExceptions.AlreadyUsedEmail()
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,4 @@ class CheckMatchedAccountUseCase(
throw UserExceptions.NotFound()
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,4 @@ class CheckNicknameDuplicationUseCase(
throw UserExceptions.AlreadyUsedNickname()
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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()
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -39,7 +39,7 @@ class ResetPasswordUseCase(
?: throw UserExceptions.NotFound()

commandUserPort.save(
user.copy(
user.changePassword(
password = securityPort.encode(request.newPassword)
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}

}
Loading

0 comments on commit 0bd21fc

Please sign in to comment.