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

hotfix: sort by 인자 수정 (#76) #77

Merged
merged 1 commit into from
Nov 12, 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
14 changes: 7 additions & 7 deletions src/main/java/com/diareat/diareat/food/service/FoodService.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public Long saveFood(CreateFoodDto createFoodDto) {
@Transactional(readOnly = true)
public List<ResponseFoodDto> getFoodListByDate(Long userId, LocalDate date){
validateUser(userId);
Sort sort = Sort.by(Sort.Direction.DESC, "added_time");
Sort sort = Sort.by(Sort.Direction.DESC, "addedTime");
List<Food> foodList = foodRepository.findAllByUserIdAndDate(userId, date, sort);
return foodList.stream()
.map(food -> ResponseFoodDto.of(food.getId(), food.getUser().getId(), food.getName(), food.getBaseNutrition(), food.isFavorite())).collect(Collectors.toList());
Expand Down Expand Up @@ -119,7 +119,7 @@ public void deleteFavoriteFood(Long favoriteFoodId, Long userId) {
// 유저의 특정 날짜에 먹은 음식들의 영양성분별 총합 조회 (섭취영양소/기준영양소 및 비율까지 계산해서 반환, dto 구체적 협의 필요)
public ResponseNutritionSumByDateDto getNutritionSumByDate(Long userId, LocalDate date) {
validateUser(userId);
Sort sort = Sort.by(Sort.Direction.DESC, "added_time");
Sort sort = Sort.by(Sort.Direction.DESC, "addedTime");
List<Food> foodList = foodRepository.findAllByUserIdAndDate(userId, date, sort);
return calculateNutritionSumAndRatio(userId, foodList, date, 1);
}
Expand All @@ -129,7 +129,7 @@ public ResponseNutritionSumByDateDto getNutritionSumByDate(Long userId, LocalDat
public ResponseNutritionSumByDateDto getNutritionSumByWeek(Long userId) {
validateUser(userId);
LocalDate endDate = LocalDate.now();
Sort sort = Sort.by(Sort.Direction.DESC, "added_time");
Sort sort = Sort.by(Sort.Direction.DESC, "addedTime");
List<Food> foodList = foodRepository.findAllByUserIdAndDateBetween(userId, endDate.minusWeeks(1), endDate, sort);

return calculateNutritionSumAndRatio(userId, foodList, endDate, 7);
Expand All @@ -140,7 +140,7 @@ public ResponseNutritionSumByDateDto getNutritionSumByWeek(Long userId) {
public ResponseNutritionSumByDateDto getNutritionSumByMonth(Long userId) {
validateUser(userId);
LocalDate endDate = LocalDate.now();
Sort sort = Sort.by(Sort.Direction.DESC, "added_time");
Sort sort = Sort.by(Sort.Direction.DESC, "addedTime");
List<Food> foodList = foodRepository.findAllByUserIdAndDateBetween(userId, endDate.minusMonths(1), endDate, sort);

return calculateNutritionSumAndRatio(userId, foodList, endDate, 30);
Expand All @@ -151,7 +151,7 @@ public ResponseNutritionSumByDateDto getNutritionSumByMonth(Long userId) {
public ResponseFoodRankDto getBestFoodByWeek(Long userId) {
validateUser(userId);
LocalDate endDate = LocalDate.now();
Sort sort = Sort.by(Sort.Direction.DESC, "added_time");
Sort sort = Sort.by(Sort.Direction.DESC, "addedTime");
List<Food> foodList = foodRepository.findAllByUserIdAndDateBetween(userId, endDate.minusWeeks(1), endDate, sort);

List<Food> top3Foods = foodList.stream()
Expand All @@ -174,7 +174,7 @@ public ResponseFoodRankDto getBestFoodByWeek(Long userId) {
public ResponseFoodRankDto getWorstFoodByWeek(Long userId) {
validateUser(userId);
LocalDate endDate = LocalDate.now();
Sort sort = Sort.by(Sort.Direction.DESC, "added_time");
Sort sort = Sort.by(Sort.Direction.DESC, "addedTime");
List<Food> foodList = foodRepository.findAllByUserIdAndDateBetween(userId, endDate.minusWeeks(1), endDate, sort);

List<Food> worst3Foods = foodList.stream()
Expand Down Expand Up @@ -402,7 +402,7 @@ private void validateFavoriteFood(Long favoriteFoodId, Long userId) {
// 1주일동안 먹은 음식들의 영양성분 총합을 요일을 Key로 한 Map을 통해 반환
private HashMap<LocalDate, List<BaseNutrition>> getNutritionSumByDateMap(Long userId, LocalDate startDate, LocalDate endDate) {
HashMap<LocalDate, List<BaseNutrition>> maps = new HashMap<>();
Sort sort = Sort.by(Sort.Direction.DESC, "added_time");
Sort sort = Sort.by(Sort.Direction.DESC, "addedTime");
List<Food> foodList = foodRepository.findAllByUserIdAndDateBetween(userId, startDate, endDate, sort);
for (Food food : foodList) {
if (maps.containsKey(food.getDate())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ void testGetAnalysisOfUser(){

List<Food> foodListOfWeek = List.of(food1,food1_1, food2, food3);
List<Food> foodListOfMonth = List.of(food1, food1_1,food2, food3, food4, food5);
Sort sort = Sort.by(Sort.Direction.DESC, "added_time");
Sort sort = Sort.by(Sort.Direction.DESC, "addedTime");



Expand Down