From f0e3e86f7dc535d5a517c60663d766a96bfc34ca Mon Sep 17 00:00:00 2001 From: CHAE Date: Tue, 28 Nov 2023 11:22:37 +0900 Subject: [PATCH 1/3] =?UTF-8?q?:ambulance:=20Fix:=20jwt=20=EA=B4=80?= =?UTF-8?q?=EB=A0=A8=20=EC=9D=BC=EB=B6=80=20=EC=88=98=EC=A0=95=20(#122)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/diareat/diareat/auth/component/JwtTokenProvider.java | 2 +- .../diareat/diareat/auth/service/CustomUserDetailService.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/diareat/diareat/auth/component/JwtTokenProvider.java b/src/main/java/com/diareat/diareat/auth/component/JwtTokenProvider.java index eed48e3..cbaa13d 100644 --- a/src/main/java/com/diareat/diareat/auth/component/JwtTokenProvider.java +++ b/src/main/java/com/diareat/diareat/auth/component/JwtTokenProvider.java @@ -67,6 +67,6 @@ public boolean validateToken(String jwtToken) { // Request의 Header에서 token 값 가져오기 public String resolveToken(HttpServletRequest request) { - return request.getHeader("X-AUTH-TOKEN"); + return request.getHeader("accessToken"); } } diff --git a/src/main/java/com/diareat/diareat/auth/service/CustomUserDetailService.java b/src/main/java/com/diareat/diareat/auth/service/CustomUserDetailService.java index 622e09f..f74e6fd 100644 --- a/src/main/java/com/diareat/diareat/auth/service/CustomUserDetailService.java +++ b/src/main/java/com/diareat/diareat/auth/service/CustomUserDetailService.java @@ -15,8 +15,8 @@ public class CustomUserDetailService implements UserDetailsService { private final UserRepository userRepository; @Override - public UserDetails loadUserByUsername(String keyCode) throws UsernameNotFoundException { - return userRepository.findByKeyCode(keyCode) + public UserDetails loadUserByUsername(String id) throws UsernameNotFoundException { + return userRepository.findById(Long.parseLong(id)) .orElseThrow(() -> new UsernameNotFoundException(ResponseCode.USER_NOT_FOUND.getMessage())); } } From 85703c53bf34889f6df6b88ac7807058fddaea4f Mon Sep 17 00:00:00 2001 From: CHAE Date: Tue, 28 Nov 2023 11:23:37 +0900 Subject: [PATCH 2/3] =?UTF-8?q?:ambulance:=20Fix:=20=EA=B8=B0=EC=A4=80?= =?UTF-8?q?=EC=84=AD=EC=B7=A8=EB=9F=89=20=EC=9E=90=EB=8F=99=EA=B3=84?= =?UTF-8?q?=EC=82=B0=20=EC=97=AC=EB=B6=80=20boolean=EC=97=90=EC=84=9C=20in?= =?UTF-8?q?t=EB=A1=9C=20=EC=88=98=EC=A0=95=20(#122)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/diareat/diareat/user/domain/User.java | 4 ++-- .../diareat/diareat/user/dto/request/UpdateUserDto.java | 7 ++++--- .../java/com/diareat/diareat/user/service/UserService.java | 2 +- src/main/java/com/diareat/diareat/util/MessageUtil.java | 1 + 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/diareat/diareat/user/domain/User.java b/src/main/java/com/diareat/diareat/user/domain/User.java index f0d7c9c..264d1ac 100644 --- a/src/main/java/com/diareat/diareat/user/domain/User.java +++ b/src/main/java/com/diareat/diareat/user/domain/User.java @@ -112,12 +112,12 @@ public static User createUser(String name, String image, String keyCode, int hei } // 회원정보 수정 - public void updateUser(String name, int height, int weight, int age, boolean autoUpdate) { + public void updateUser(String name, int height, int weight, int age, int autoUpdate) { this.name = name; this.height = height; this.weight = weight; this.age = age; - if(autoUpdate) { + if(autoUpdate == 1) { this.type = UserTypeUtil.decideUserType(this.gender, this.age); } } diff --git a/src/main/java/com/diareat/diareat/user/dto/request/UpdateUserDto.java b/src/main/java/com/diareat/diareat/user/dto/request/UpdateUserDto.java index 818f3e2..c4540ad 100644 --- a/src/main/java/com/diareat/diareat/user/dto/request/UpdateUserDto.java +++ b/src/main/java/com/diareat/diareat/user/dto/request/UpdateUserDto.java @@ -29,9 +29,10 @@ public class UpdateUserDto { @Range(min = 5, max = 100, message = MessageUtil.AGE_RANGE) private int age; - private boolean isAutoUpdateNutrition; // 개인정보를 활용한 기준 영양소 자동계산 여부 + @Range(min = 0, max = 1, message = MessageUtil.ZERO_OR_ONE) + private int autoUpdateNutrition; // 개인정보를 활용한 기준 영양소 자동계산 여부 (0, 1) - public static UpdateUserDto of(Long userId, String userName, int userHeight, int userWeight, int userAge, boolean isAutoUpdateNutrition) { - return new UpdateUserDto(userId, userName, userHeight, userWeight, userAge, isAutoUpdateNutrition); + public static UpdateUserDto of(Long userId, String userName, int userHeight, int userWeight, int userAge, boolean autoUpdateNutrition) { + return new UpdateUserDto(userId, userName, userHeight, userWeight, userAge, Integer.parseInt(String.valueOf(autoUpdateNutrition))); } } diff --git a/src/main/java/com/diareat/diareat/user/service/UserService.java b/src/main/java/com/diareat/diareat/user/service/UserService.java index 66468fa..aaade88 100644 --- a/src/main/java/com/diareat/diareat/user/service/UserService.java +++ b/src/main/java/com/diareat/diareat/user/service/UserService.java @@ -78,7 +78,7 @@ public ResponseUserDto getUserInfo(Long userId) { public void updateUserInfo(UpdateUserDto updateUserDto) { User user = getUserById(updateUserDto.getUserId()); log.info("{} 회원정보 조회 완료: ", user.getName()); - user.updateUser(updateUserDto.getName(), updateUserDto.getHeight(), updateUserDto.getWeight(), updateUserDto.getAge(), updateUserDto.isAutoUpdateNutrition()); + user.updateUser(updateUserDto.getName(), updateUserDto.getHeight(), updateUserDto.getWeight(), updateUserDto.getAge(), updateUserDto.getAutoUpdateNutrition()); userRepository.save(user); log.info("{} 회원정보 수정 완료: ", user.getName()); } diff --git a/src/main/java/com/diareat/diareat/util/MessageUtil.java b/src/main/java/com/diareat/diareat/util/MessageUtil.java index aba71cd..ba4d77b 100644 --- a/src/main/java/com/diareat/diareat/util/MessageUtil.java +++ b/src/main/java/com/diareat/diareat/util/MessageUtil.java @@ -18,6 +18,7 @@ public class MessageUtil { // 반복되는 메시지의 형식을 저장하고 public static final String CARBOHYDRATE_RANGE = "탄수화물은 100 이상, 500 이하의 값을 입력해주세요."; public static final String PROTEIN_RANGE = "단백질은 25 이상, 500 이하의 값을 입력해주세요."; public static final String FAT_RANGE = "지방은 25 이상, 500 이하의 값을 입력해주세요."; + public static final String ZERO_OR_ONE = "0 또는 1의 값을 입력해주세요."; public static final String PAST_OR_PRESENT = "과거 또는 오늘 날짜여야 합니다."; public static final String TIME_STAMP = "addedTime"; From ea677fbbf0f6caeea4f008d56012d04d41a21933 Mon Sep 17 00:00:00 2001 From: CHAE Date: Tue, 28 Nov 2023 11:25:28 +0900 Subject: [PATCH 3/3] =?UTF-8?q?:ambulance:=20Fix:=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=EC=BD=94=EB=93=9C=20=EB=B0=98=EC=98=81=20(#122)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/diareat/diareat/user/dto/request/UpdateUserDto.java | 4 ++-- .../com/diareat/diareat/controller/UserControllerTest.java | 4 ++-- .../java/com/diareat/diareat/service/UserServiceTest.java | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/diareat/diareat/user/dto/request/UpdateUserDto.java b/src/main/java/com/diareat/diareat/user/dto/request/UpdateUserDto.java index c4540ad..8c75931 100644 --- a/src/main/java/com/diareat/diareat/user/dto/request/UpdateUserDto.java +++ b/src/main/java/com/diareat/diareat/user/dto/request/UpdateUserDto.java @@ -32,7 +32,7 @@ public class UpdateUserDto { @Range(min = 0, max = 1, message = MessageUtil.ZERO_OR_ONE) private int autoUpdateNutrition; // 개인정보를 활용한 기준 영양소 자동계산 여부 (0, 1) - public static UpdateUserDto of(Long userId, String userName, int userHeight, int userWeight, int userAge, boolean autoUpdateNutrition) { - return new UpdateUserDto(userId, userName, userHeight, userWeight, userAge, Integer.parseInt(String.valueOf(autoUpdateNutrition))); + public static UpdateUserDto of(Long userId, String userName, int userHeight, int userWeight, int userAge, int autoUpdateNutrition) { + return new UpdateUserDto(userId, userName, userHeight, userWeight, userAge, autoUpdateNutrition); } } diff --git a/src/test/java/com/diareat/diareat/controller/UserControllerTest.java b/src/test/java/com/diareat/diareat/controller/UserControllerTest.java index 8ec9171..d8b1b37 100644 --- a/src/test/java/com/diareat/diareat/controller/UserControllerTest.java +++ b/src/test/java/com/diareat/diareat/controller/UserControllerTest.java @@ -105,7 +105,7 @@ void getUserInfo() throws Exception { void updateUser() throws Exception { // Given ApiResponse expectedResponse = ApiResponse.success(null, ResponseCode.USER_UPDATE_SUCCESS.getMessage()); - UpdateUserDto user = UpdateUserDto.of(testUserId, "test2", 170, 80, 21, true); + UpdateUserDto user = UpdateUserDto.of(testUserId, "test2", 170, 80, 21, 1); String json = mapper.writeValueAsString(user); // When & Then @@ -125,7 +125,7 @@ void updateUser() throws Exception { @WithMockUser("test") void updateUserFail() throws Exception { // Given - UpdateUserDto user = UpdateUserDto.of(testUserId, "", 300, 80, 500, true); + UpdateUserDto user = UpdateUserDto.of(testUserId, "", 300, 80, 500, 1); String json = mapper.writeValueAsString(user); // When & Then diff --git a/src/test/java/com/diareat/diareat/service/UserServiceTest.java b/src/test/java/com/diareat/diareat/service/UserServiceTest.java index ca96d59..41691bf 100644 --- a/src/test/java/com/diareat/diareat/service/UserServiceTest.java +++ b/src/test/java/com/diareat/diareat/service/UserServiceTest.java @@ -112,7 +112,7 @@ void getUserInfo() { @Test void updateUserInfo() { // given - UpdateUserDto updateUserDto = UpdateUserDto.of(1L, "update", 180, 75, 25, false); + UpdateUserDto updateUserDto = UpdateUserDto.of(1L, "update", 180, 75, 25, 0); User user = User.createUser("test", "profile.jpg", "keycode123", 175, 70, 0, 30, BaseNutrition.createNutrition(2000, 300, 80, 80)); given(userRepository.findById(updateUserDto.getUserId())).willReturn(Optional.of(user));