Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: 기준섭취량 자동계산 boolean 누락된 버그 수정 (#122) #123

Merged
merged 3 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
}
4 changes: 2 additions & 2 deletions src/main/java/com/diareat/diareat/user/domain/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, int autoUpdateNutrition) {
return new UpdateUserDto(userId, userName, userHeight, userWeight, userAge, autoUpdateNutrition);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/diareat/diareat/util/MessageUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ void getUserInfo() throws Exception {
void updateUser() throws Exception {
// Given
ApiResponse<Void> 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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down