From 785533528b44e43f6473f4ad857283aac2fe94d4 Mon Sep 17 00:00:00 2001 From: Ahn Jiwan Date: Sun, 7 Jan 2024 22:45:44 +0900 Subject: [PATCH] =?UTF-8?q?:recycle:=20refactor:=20responseSimpleFoodDto?= =?UTF-8?q?=20=EC=82=AD=EC=A0=9C=20=EB=B0=8F=20=EA=B8=B0=EC=A1=B4=20Dto?= =?UTF-8?q?=EB=A1=9C=20=ED=86=B5=ED=95=A9=20(#140)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../diareat/food/dto/ResponseFoodDto.java | 20 ++++++++++-- .../diareat/food/dto/ResponseFoodRankDto.java | 4 +-- .../food/dto/ResponseScoreBestWorstDto.java | 6 ++-- .../food/dto/ResponseSimpleFoodDto.java | 32 ------------------- .../diareat/food/service/FoodService.java | 24 +++++--------- 5 files changed, 31 insertions(+), 55 deletions(-) delete mode 100644 src/main/java/com/diareat/diareat/food/dto/ResponseSimpleFoodDto.java diff --git a/src/main/java/com/diareat/diareat/food/dto/ResponseFoodDto.java b/src/main/java/com/diareat/diareat/food/dto/ResponseFoodDto.java index 91a6878..ca0ee26 100644 --- a/src/main/java/com/diareat/diareat/food/dto/ResponseFoodDto.java +++ b/src/main/java/com/diareat/diareat/food/dto/ResponseFoodDto.java @@ -25,10 +25,26 @@ public class ResponseFoodDto { private int minute; public static ResponseFoodDto of(Long foodId, Long userId, String name, BaseNutrition baseNutrition, boolean favoriteChecked, int hour, int minute) { - return new ResponseFoodDto(foodId, userId, name, baseNutrition, favoriteChecked, hour, minute); + return ResponseFoodDto.builder() + .foodId(foodId) + .userId(userId) + .name(name) + .baseNutrition(baseNutrition) + .favoriteChecked(favoriteChecked) + .hour(hour) + .minute(minute) + .build(); } public static ResponseFoodDto from(Food food) { - return new ResponseFoodDto(food.getId(), food.getUser().getId(), food.getName(), food.getBaseNutrition(), food.isFavorite(), food.getAddedTime().getHour(), food.getAddedTime().getMinute()); + return ResponseFoodDto.builder() + .foodId(food.getId()) + .userId(food.getUser().getId()) + .name(food.getName()) + .baseNutrition(food.getBaseNutrition()) + .favoriteChecked(food.isFavorite()) + .hour(food.getAddedTime().getHour()) + .minute(food.getAddedTime().getMinute()) + .build(); } } diff --git a/src/main/java/com/diareat/diareat/food/dto/ResponseFoodRankDto.java b/src/main/java/com/diareat/diareat/food/dto/ResponseFoodRankDto.java index a55a648..29fcf45 100644 --- a/src/main/java/com/diareat/diareat/food/dto/ResponseFoodRankDto.java +++ b/src/main/java/com/diareat/diareat/food/dto/ResponseFoodRankDto.java @@ -15,11 +15,11 @@ public class ResponseFoodRankDto { private Long userId; - private List rankFoodList; + private List rankFoodList; private LocalDate startDate; //해당 날짜로부터 7일전까지 private boolean isBest; //isBest = true 이면 Best 3, false 이면 Worst 3 - public static ResponseFoodRankDto of(Long userId, List rankFoodList, LocalDate startDate, boolean isBest) { + public static ResponseFoodRankDto of(Long userId, List rankFoodList, LocalDate startDate, boolean isBest) { return new ResponseFoodRankDto(userId, rankFoodList, startDate, isBest); } } diff --git a/src/main/java/com/diareat/diareat/food/dto/ResponseScoreBestWorstDto.java b/src/main/java/com/diareat/diareat/food/dto/ResponseScoreBestWorstDto.java index 3a5bea1..aa03997 100644 --- a/src/main/java/com/diareat/diareat/food/dto/ResponseScoreBestWorstDto.java +++ b/src/main/java/com/diareat/diareat/food/dto/ResponseScoreBestWorstDto.java @@ -18,10 +18,10 @@ public class ResponseScoreBestWorstDto { // 일기 분석 자세히보기에 사 private double proteinScore; private double fatScore; private double totalScore; - private List best; - private List worst; + private List best; + private List worst; - public static ResponseScoreBestWorstDto of(double calorieScore, double carbohydrateScore, double proteinScore, double fatScore, double totalScore, List best, List worst) { + public static ResponseScoreBestWorstDto of(double calorieScore, double carbohydrateScore, double proteinScore, double fatScore, double totalScore, List best, List worst) { return new ResponseScoreBestWorstDto(calorieScore, carbohydrateScore, proteinScore, fatScore, totalScore, best, worst); } } diff --git a/src/main/java/com/diareat/diareat/food/dto/ResponseSimpleFoodDto.java b/src/main/java/com/diareat/diareat/food/dto/ResponseSimpleFoodDto.java deleted file mode 100644 index d3cfedb..0000000 --- a/src/main/java/com/diareat/diareat/food/dto/ResponseSimpleFoodDto.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.diareat.diareat.food.dto; - -import com.diareat.diareat.food.domain.Food; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; - -import java.time.LocalDate; - -@Getter -@Builder -@NoArgsConstructor -@AllArgsConstructor -public class ResponseSimpleFoodDto { // Best 3 and Worst 3에 사용될 객체 - - private String name; - private double calorie; - private double carbohydrate; - private double protein; - private double fat; - private LocalDate date; - - public static ResponseSimpleFoodDto of(String name, double calorie, double carbohydrate, double protein, double fat, LocalDate date) { - return new ResponseSimpleFoodDto(name, calorie, carbohydrate, protein, fat, date); - } - - public static ResponseSimpleFoodDto from(Food food) { - return new ResponseSimpleFoodDto(food.getName(), food.getBaseNutrition().getKcal(), food.getBaseNutrition().getCarbohydrate(), - food.getBaseNutrition().getProtein(), food.getBaseNutrition().getFat(), food.getDate()); - } -} diff --git a/src/main/java/com/diareat/diareat/food/service/FoodService.java b/src/main/java/com/diareat/diareat/food/service/FoodService.java index fb7f21e..4bd28c0 100644 --- a/src/main/java/com/diareat/diareat/food/service/FoodService.java +++ b/src/main/java/com/diareat/diareat/food/service/FoodService.java @@ -184,14 +184,10 @@ public ResponseFoodRankDto getBestFoodByWeek(Long userId, int year, int month, i //사용한 기준은, 고단백과 저지방의 점수 반영 비율을 7:3으로 측정하고, 단백질량이 높을 수록, 지방량이 낮을 수록 점수가 높음. 이후, 내림차순 정렬 // ** Best 3 기준 논의 필요 ** - List top3FoodsDtoList = top3Foods.stream() - .map(food -> ResponseSimpleFoodDto.builder() + List top3FoodsDtoList = top3Foods.stream() + .map(food -> ResponseFoodDto.builder() .name(food.getName()) - .calorie(food.getBaseNutrition().getKcal()) - .carbohydrate(food.getBaseNutrition().getCarbohydrate()) - .protein(food.getBaseNutrition().getProtein()) - .fat(food.getBaseNutrition().getFat()) - .date(food.getDate()) + .baseNutrition(food.getBaseNutrition()) .build()) .collect(Collectors.toList()); @@ -220,14 +216,10 @@ public ResponseFoodRankDto getWorstFoodByWeek(Long userId, int year, int month, // ** 이점은 논의가 필요할 듯? ** // 우선 임시로 지방 비율을 높게 설정 - List worst3FoodDtoList = worst3Foods.stream() - .map(food -> ResponseSimpleFoodDto.builder() + List worst3FoodDtoList = worst3Foods.stream() + .map(food -> ResponseFoodDto.builder() .name(food.getName()) - .calorie(food.getBaseNutrition().getKcal()) - .carbohydrate(food.getBaseNutrition().getCarbohydrate()) - .protein(food.getBaseNutrition().getProtein()) - .fat(food.getBaseNutrition().getFat()) - .date(food.getDate()) + .baseNutrition(food.getBaseNutrition()) .build()) .collect(Collectors.toList()); @@ -263,8 +255,8 @@ public ResponseScoreBestWorstDto getScoreOfUserWithBestAndWorstFoods(Long userId //Dto의 형식에 맞게 Best3와 Worst3 음식 계산 - List simpleBestFoodList = getBestFoodByWeek(userId, year, month, day).getRankFoodList(); - List simpleWorstFoodList = getWorstFoodByWeek(userId, year, month, day).getRankFoodList(); + List simpleBestFoodList = getBestFoodByWeek(userId, year, month, day).getRankFoodList(); + List simpleWorstFoodList = getWorstFoodByWeek(userId, year, month, day).getRankFoodList(); return ResponseScoreBestWorstDto.builder() .totalScore(totalScore)