diff --git a/src/main/java/com/umc/refit/web/service/ClotheService.java b/src/main/java/com/umc/refit/web/service/ClotheService.java index 2125e17..c18e4af 100644 --- a/src/main/java/com/umc/refit/web/service/ClotheService.java +++ b/src/main/java/com/umc/refit/web/service/ClotheService.java @@ -74,22 +74,20 @@ public List showClotheMain(Integer category, Integer s return new ArrayList<>(); } - List sortedClothes = sortClothes(clothes); - - - return sortClothes(sortedClothes).stream() + return sortClothes(clothes).stream() .map(clothe -> clothe.from(this.calculateRemainedDay(clothe))) .collect(Collectors.toList()); } else if (sort.equals("most-worn")) { - return this.closetRepository.findAllByCategoryAndSeasonAndMemberOrderByCountDesc(category, season, member) - .stream() + List clothes = this.closetRepository.findAllByCategoryAndSeasonAndMemberOrderByCountDesc(category, season, member); + + return checkSorting(clothes).stream() .map(clothe -> clothe.from(this.calculateRemainedDay(clothe))) .collect(Collectors.toList()); } else { - return this.closetRepository.findAllByCategoryAndSeasonAndMemberOrderByCountAsc(category, season, member) - .stream() + List clothes = this.closetRepository.findAllByCategoryAndSeasonAndMemberOrderByCountAsc(category, season, member); + return checkSorting(clothes).stream() .map(clothe -> clothe.from(this.calculateRemainedDay(clothe))) .collect(Collectors.toList()); } @@ -165,6 +163,7 @@ private List sortClothes(List clothes) { return checkSorting(clothes); } + private List checkSorting(List clothes) { ArrayList resultClothes = new ArrayList<>();