Skip to content

Commit

Permalink
♻️ refactor: responseSimpleFoodDto 삭제 및 기존 Dto로 통합 (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
synoti21 committed Jan 7, 2024
1 parent 254eec2 commit 7855335
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 55 deletions.
20 changes: 18 additions & 2 deletions src/main/java/com/diareat/diareat/food/dto/ResponseFoodDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
public class ResponseFoodRankDto {

private Long userId;
private List<ResponseSimpleFoodDto> rankFoodList;
private List<ResponseFoodDto> rankFoodList;
private LocalDate startDate; //해당 날짜로부터 7일전까지
private boolean isBest; //isBest = true 이면 Best 3, false 이면 Worst 3

public static ResponseFoodRankDto of(Long userId, List<ResponseSimpleFoodDto> rankFoodList, LocalDate startDate, boolean isBest) {
public static ResponseFoodRankDto of(Long userId, List<ResponseFoodDto> rankFoodList, LocalDate startDate, boolean isBest) {
return new ResponseFoodRankDto(userId, rankFoodList, startDate, isBest);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ public class ResponseScoreBestWorstDto { // 일기 분석 자세히보기에 사
private double proteinScore;
private double fatScore;
private double totalScore;
private List<ResponseSimpleFoodDto> best;
private List<ResponseSimpleFoodDto> worst;
private List<ResponseFoodDto> best;
private List<ResponseFoodDto> worst;

public static ResponseScoreBestWorstDto of(double calorieScore, double carbohydrateScore, double proteinScore, double fatScore, double totalScore, List<ResponseSimpleFoodDto> best, List<ResponseSimpleFoodDto> worst) {
public static ResponseScoreBestWorstDto of(double calorieScore, double carbohydrateScore, double proteinScore, double fatScore, double totalScore, List<ResponseFoodDto> best, List<ResponseFoodDto> worst) {
return new ResponseScoreBestWorstDto(calorieScore, carbohydrateScore, proteinScore, fatScore, totalScore, best, worst);
}
}

This file was deleted.

24 changes: 8 additions & 16 deletions src/main/java/com/diareat/diareat/food/service/FoodService.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,14 +184,10 @@ public ResponseFoodRankDto getBestFoodByWeek(Long userId, int year, int month, i
//사용한 기준은, 고단백과 저지방의 점수 반영 비율을 7:3으로 측정하고, 단백질량이 높을 수록, 지방량이 낮을 수록 점수가 높음. 이후, 내림차순 정렬
// ** Best 3 기준 논의 필요 **

List<ResponseSimpleFoodDto> top3FoodsDtoList = top3Foods.stream()
.map(food -> ResponseSimpleFoodDto.builder()
List<ResponseFoodDto> 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());

Expand Down Expand Up @@ -220,14 +216,10 @@ public ResponseFoodRankDto getWorstFoodByWeek(Long userId, int year, int month,
// ** 이점은 논의가 필요할 듯? **
// 우선 임시로 지방 비율을 높게 설정

List<ResponseSimpleFoodDto> worst3FoodDtoList = worst3Foods.stream()
.map(food -> ResponseSimpleFoodDto.builder()
List<ResponseFoodDto> 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());

Expand Down Expand Up @@ -263,8 +255,8 @@ public ResponseScoreBestWorstDto getScoreOfUserWithBestAndWorstFoods(Long userId


//Dto의 형식에 맞게 Best3와 Worst3 음식 계산
List<ResponseSimpleFoodDto> simpleBestFoodList = getBestFoodByWeek(userId, year, month, day).getRankFoodList();
List<ResponseSimpleFoodDto> simpleWorstFoodList = getWorstFoodByWeek(userId, year, month, day).getRankFoodList();
List<ResponseFoodDto> simpleBestFoodList = getBestFoodByWeek(userId, year, month, day).getRankFoodList();
List<ResponseFoodDto> simpleWorstFoodList = getWorstFoodByWeek(userId, year, month, day).getRankFoodList();

return ResponseScoreBestWorstDto.builder()
.totalScore(totalScore)
Expand Down

0 comments on commit 7855335

Please sign in to comment.