From 7f0cf85ca28197b985ba97c7686a33554c3f7ec6 Mon Sep 17 00:00:00 2001 From: wonseok Date: Fri, 31 Jan 2025 15:15:40 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Add=20db=20check=20in=20editProf?= =?UTF-8?q?ile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/toyProject7/karrot/profile/service/ProfileService.kt | 2 +- .../com/toyProject7/karrot/user/service/UserService.kt | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) 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) + } }