Skip to content

Commit

Permalink
✨ Feat: 유저에 type 속성 추가 및 기준섭취량 응답 dto 값 추가 (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
win-luck committed Oct 16, 2023
1 parent efcafea commit e7494e7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
9 changes: 8 additions & 1 deletion src/main/java/com/diareat/diareat/user/domain/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.diareat.diareat.food.domain.FavoriteFood;
import com.diareat.diareat.food.domain.Food;
import com.diareat.diareat.util.UserTypeUtil;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.*;
import org.springframework.security.core.GrantedAuthority;
Expand Down Expand Up @@ -39,6 +40,8 @@ public class User implements UserDetails {

private int age; // 나이

private int type; // 성별과 연령에 따른 유저 타입 (1~12)

private BaseNutrition baseNutrition; // 기준영양소

@OneToMany(mappedBy = "user", cascade = {CascadeType.PERSIST, CascadeType.REMOVE}) // 유저가 탈퇴하면 촬영한 음식도 삭제
Expand Down Expand Up @@ -102,15 +105,19 @@ public static User createUser(String name, String image, String keyCode, int hei
user.gender = gender;
user.age = age;
user.baseNutrition = baseNutrition;
user.type = UserTypeUtil.decideUserType(gender, age);
return user;
}

// 회원정보 수정
public void updateUser(String name, int height, int weight, int age) {
public void updateUser(String name, int height, int weight, int age, boolean autoUpdate) {
this.name = name;
this.height = height;
this.weight = weight;
this.age = age;
if(autoUpdate) {
this.type = UserTypeUtil.decideUserType(this.gender, this.age);
}
}

// 회원 기준영양소 직접 수정
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,22 @@
@AllArgsConstructor
public class ResponseUserNutritionDto {

private int calorie;
private int calorie; // 유저가 설정한(할 수 있는) 현재 영양소 기준섭취량
private int carbohydrate;
private int protein;
private int fat;

public static ResponseUserNutritionDto of(int calorie, int carbohydrate, int protein, int fat) {
return new ResponseUserNutritionDto(calorie, carbohydrate, protein, fat);
private int defaultCalorie; // 개인정보에 따라 기본적으로 설정되는 영양소 기준섭취량
private int defaultCarbohydrate;
private int defaultProtein;
private int defaultFat;

public static ResponseUserNutritionDto of(int calorie, int carbohydrate, int protein, int fat, int defaultCalorie, int defaultCarbohydrate, int defaultProtein, int defaultFat) {
return new ResponseUserNutritionDto(calorie, carbohydrate, protein, fat, defaultCalorie, defaultCarbohydrate, defaultProtein, defaultFat);
}

public static ResponseUserNutritionDto from(User user) {
return new ResponseUserNutritionDto(user.getBaseNutrition().getKcal(), user.getBaseNutrition().getCarbohydrate(), user.getBaseNutrition().getProtein(), user.getBaseNutrition().getFat());
public static ResponseUserNutritionDto from(User user, int defaultCalorie, int defaultCarbohydrate, int defaultProtein, int defaultFat) {
return new ResponseUserNutritionDto(user.getBaseNutrition().getKcal(), user.getBaseNutrition().getCarbohydrate(),
user.getBaseNutrition().getProtein(), user.getBaseNutrition().getFat(), defaultCalorie, defaultCarbohydrate, defaultProtein, defaultFat);
}
}

0 comments on commit e7494e7

Please sign in to comment.