From 423332bacba71f05cf40275639aba3e549942b46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B0=95=EC=A0=95=EB=AF=BC?= Date: Fri, 9 Aug 2024 14:19:10 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=ED=9A=8C=EC=9B=90=EC=A0=95=EB=B3=B4=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=EC=8B=9C=20=EC=9D=B4=EB=A9=94=EC=9D=BC=20?= =?UTF-8?q?=EC=A4=91=EB=B3=B5=20=EA=B2=80=EC=82=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../edufocus/edufocus/user/controller/UserController.java | 4 ++-- .../edufocus/user/model/repository/UserRepository.java | 4 ++-- .../edufocus/user/model/service/UserServiceImpl.java | 8 +++++++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/backend/src/main/java/com/edufocus/edufocus/user/controller/UserController.java b/backend/src/main/java/com/edufocus/edufocus/user/controller/UserController.java index bb3818f..c4c2c7a 100644 --- a/backend/src/main/java/com/edufocus/edufocus/user/controller/UserController.java +++ b/backend/src/main/java/com/edufocus/edufocus/user/controller/UserController.java @@ -37,7 +37,7 @@ public class UserController { if (userService.isUserIdExist(requestJoinDto.getUserId())) return new ResponseEntity<>("아이디가 중복 됐습니다.", HttpStatus.CONFLICT); - if(userService.isEmailExist(requestJoinDto.getEmail())) + if (userService.isEmailExist(requestJoinDto.getEmail())) return new ResponseEntity<>("이메일이 중복 됐습니다.", HttpStatus.CONFLICT); userService.join(requestJoinDto); @@ -65,7 +65,7 @@ public class UserController { userService.changePassword(passwordDto, userId); return ResponseEntity.ok("Password changed successfully"); } catch (Exception e) { - return ResponseEntity.badRequest().body(e.getMessage()); + return ResponseEntity.status(HttpStatus.NOT_ACCEPTABLE).body(e.getMessage()); } } diff --git a/backend/src/main/java/com/edufocus/edufocus/user/model/repository/UserRepository.java b/backend/src/main/java/com/edufocus/edufocus/user/model/repository/UserRepository.java index 6aea378..c3d42e6 100644 --- a/backend/src/main/java/com/edufocus/edufocus/user/model/repository/UserRepository.java +++ b/backend/src/main/java/com/edufocus/edufocus/user/model/repository/UserRepository.java @@ -9,7 +9,7 @@ import org.springframework.data.repository.query.Param; import java.util.Optional; -public interface UserRepository extends JpaRepository { +public interface UserRepository extends JpaRepository { @Modifying @Transactional @Query("UPDATE User u SET u.refreshToken = :refreshToken WHERE u.id = :id") @@ -26,7 +26,7 @@ public interface UserRepository extends JpaRepository { @Transactional @Modifying @Query("UPDATE User u set u.password = :password where u.id= :id") - void updatePassword(@Param("id") Long id , @Param("password") String password); + void updatePassword(@Param("id") Long id, @Param("password") String password); Optional findByUserId(String userId); diff --git a/backend/src/main/java/com/edufocus/edufocus/user/model/service/UserServiceImpl.java b/backend/src/main/java/com/edufocus/edufocus/user/model/service/UserServiceImpl.java index ac6a6d8..9b71b61 100644 --- a/backend/src/main/java/com/edufocus/edufocus/user/model/service/UserServiceImpl.java +++ b/backend/src/main/java/com/edufocus/edufocus/user/model/service/UserServiceImpl.java @@ -74,6 +74,12 @@ public class UserServiceImpl implements UserService { User user = userRepository.findById(id).orElseThrow(IllegalArgumentException::new); + + if (isEmailExist(infoDto.getEmail())) { + throw new IllegalArgumentException("이미 사용 중인 이메일입니다."); + + } + if (infoDto.getName() != null) user.setName(infoDto.getName()); @@ -159,7 +165,7 @@ public class UserServiceImpl implements UserService { } @Override - public boolean isTeacher(long userId){ + public boolean isTeacher(long userId) { return userRepository.findById(userId).orElseThrow(IllegalArgumentException::new).getRole() == UserRole.ADMIN; } }