From 0d8f5bc8a6d022929e824a25775cb222624fb2fa 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:28:43 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=9C=A0=EC=A0=80=20=EC=A0=95=EB=B3=B4?= =?UTF-8?q?=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../edufocus/user/controller/UserController.java | 13 +++++++++---- .../user/model/service/UserServiceImpl.java | 4 ++-- 2 files changed, 11 insertions(+), 6 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 c4c2c7a..7fe36d3 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 @@ -47,12 +47,17 @@ public class UserController { @PutMapping("/updateinfo") public ResponseEntity updateUserInfo(@RequestBody InfoDto infoDto, HttpServletRequest request) { - String token = request.getHeader("Authorization"); - Long userId = Long.parseLong(jwtUtil.getUserId(token)); - userService.changeUserInfo(infoDto, userId); + try { + String token = request.getHeader("Authorization"); + Long userId = Long.parseLong(jwtUtil.getUserId(token)); + + userService.changeUserInfo(infoDto, userId); + return ResponseEntity.ok("Password changed successfully"); + } catch (Exception e) { + return ResponseEntity.status(HttpStatus.NOT_ACCEPTABLE).body(e.getMessage()); + } - return new ResponseEntity<>(HttpStatus.OK); } // 비밀번호 변경 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 9b71b61..310a2e6 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 @@ -72,11 +72,11 @@ public class UserServiceImpl implements UserService { @Override public void changeUserInfo(InfoDto infoDto, Long id) { - User user = userRepository.findById(id).orElseThrow(IllegalArgumentException::new); + User user = userRepository.findById(id).orElse(null); if (isEmailExist(infoDto.getEmail())) { - throw new IllegalArgumentException("이미 사용 중인 이메일입니다."); + throw new RuntimeException("이미 사용 중인 이메일입니다."); }