feat: 유저 정보 변경

This commit is contained in:
박정민 2024-08-09 14:28:43 +09:00
parent 5ccd0e87a9
commit 0d8f5bc8a6
2 changed files with 11 additions and 6 deletions

View File

@ -47,12 +47,17 @@ public class UserController {
@PutMapping("/updateinfo")
public ResponseEntity<String> updateUserInfo(@RequestBody InfoDto infoDto, HttpServletRequest request) {
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);
}
// 비밀번호 변경

View File

@ -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("이미 사용 중인 이메일입니다.");
}