From e7494e74d8ba1296b4e5680f68f1c6b12d5aba9b Mon Sep 17 00:00:00 2001 From: CHAE Date: Tue, 17 Oct 2023 02:21:49 +0900 Subject: [PATCH] =?UTF-8?q?:sparkles:=20Feat:=20=EC=9C=A0=EC=A0=80?= =?UTF-8?q?=EC=97=90=20type=20=EC=86=8D=EC=84=B1=20=EC=B6=94=EA=B0=80=20?= =?UTF-8?q?=EB=B0=8F=20=EA=B8=B0=EC=A4=80=EC=84=AD=EC=B7=A8=EB=9F=89=20?= =?UTF-8?q?=EC=9D=91=EB=8B=B5=20dto=20=EA=B0=92=20=EC=B6=94=EA=B0=80=20(#3?= =?UTF-8?q?5)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/diareat/diareat/user/domain/User.java | 9 ++++++++- .../user/dto/ResponseUserNutritionDto.java | 16 +++++++++++----- 2 files changed, 19 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 98e16d7..5af69ea 100644 --- a/src/main/java/com/diareat/diareat/user/domain/User.java +++ b/src/main/java/com/diareat/diareat/user/domain/User.java @@ -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; @@ -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}) // 유저가 탈퇴하면 촬영한 음식도 삭제 @@ -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); + } } // 회원 기준영양소 직접 수정 diff --git a/src/main/java/com/diareat/diareat/user/dto/ResponseUserNutritionDto.java b/src/main/java/com/diareat/diareat/user/dto/ResponseUserNutritionDto.java index a2db114..41a6826 100644 --- a/src/main/java/com/diareat/diareat/user/dto/ResponseUserNutritionDto.java +++ b/src/main/java/com/diareat/diareat/user/dto/ResponseUserNutritionDto.java @@ -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); } }