diff --git a/src/main/kotlin/com/toyProject7/karrot/profile/service/ProfileService.kt b/src/main/kotlin/com/toyProject7/karrot/profile/service/ProfileService.kt index 1f34c57..4af7b8d 100644 --- a/src/main/kotlin/com/toyProject7/karrot/profile/service/ProfileService.kt +++ b/src/main/kotlin/com/toyProject7/karrot/profile/service/ProfileService.kt @@ -69,7 +69,7 @@ class ProfileService( user: User, request: EditProfileRequest, ): Profile { - if (user.nickname == request.nickname) { + if (user.nickname != request.nickname && userService.existUserEntityByNickname(request.nickname)) { throw ProfileEditNicknameConflictException() } diff --git a/src/main/kotlin/com/toyProject7/karrot/user/service/UserService.kt b/src/main/kotlin/com/toyProject7/karrot/user/service/UserService.kt index 1510012..e3ca5a6 100644 --- a/src/main/kotlin/com/toyProject7/karrot/user/service/UserService.kt +++ b/src/main/kotlin/com/toyProject7/karrot/user/service/UserService.kt @@ -179,4 +179,9 @@ class UserService( fun getUserEntityByNickname(nickname: String): UserEntity { return userRepository.findByNickname(nickname) ?: throw UserNotFoundException() } + + @Transactional + fun existUserEntityByNickname(nickname: String): Boolean { + return userRepository.existsByNickname(nickname) + } }