Skip to content

Commit

Permalink
✨ Feat: 브리핑 목록 조회 V2 각 순위별 최신 브리핑 모아서 응답 (#153)
Browse files Browse the repository at this point in the history
* ✨ Feat: 브리핑 목록 조회 V2 각 순위별 최신 브리핑 모아서 응답

* ♻️ Refactor: for문 스트림으로 변경 in V2 목록 조회 쿼리
  • Loading branch information
swa07016 authored Jan 10, 2024
1 parent 2a462dd commit 4b9d34e
Showing 1 changed file with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.*;
import java.util.stream.Collectors;

import org.springframework.stereotype.Repository;
Expand Down Expand Up @@ -79,17 +77,23 @@ public List<Briefing> findTop10ByTypeOrderByCreatedAtDesc(BriefingType type) {
.where(briefing.type.eq(type))
.groupBy(briefing)
.orderBy(date.desc(), briefing.ranks.asc())
.limit(10)
.limit(20)
.fetch();

return results.stream()
.map(
tuple -> {
Briefing b = tuple.get(briefing);
b.setScrapCount(Math.toIntExact(tuple.get(scrap.count())));
return b;
})
.collect(Collectors.toCollection(ArrayList::new));
List<Briefing> briefingList =
results.stream()
.map(
tuple -> {
Briefing b = tuple.get(briefing);
b.setScrapCount(Math.toIntExact(tuple.get(scrap.count())));
return b;
})
.collect(Collectors.toCollection(ArrayList::new));

Map<Integer, Briefing> briefingMap = new HashMap<>();
briefingList.forEach(candidate -> briefingMap.putIfAbsent(candidate.getRanks(), candidate));

return briefingMap.values().stream().toList();
}

@Override
Expand Down

0 comments on commit 4b9d34e

Please sign in to comment.