From 024cd559c2ab3ba4f2132bf1be17fbddc8f06602 Mon Sep 17 00:00:00 2001 From: Seungrae Date: Thu, 4 Jul 2024 19:39:42 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20Click=20history=20=EA=B3=84=EC=82=B0=20?= =?UTF-8?q?=EB=B6=80=EB=B6=84=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/ClickCountHistoryService.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/click-service/src/main/java/clickme/clickme/history/application/ClickCountHistoryService.java b/click-service/src/main/java/clickme/clickme/history/application/ClickCountHistoryService.java index 2c433ff..c758ab3 100644 --- a/click-service/src/main/java/clickme/clickme/history/application/ClickCountHistoryService.java +++ b/click-service/src/main/java/clickme/clickme/history/application/ClickCountHistoryService.java @@ -11,36 +11,40 @@ import java.util.List; import java.util.Map; import java.util.stream.Collectors; -import java.util.stream.IntStream; @Service @RequiredArgsConstructor public class ClickCountHistoryService { private final ClickCountHistoryRepository clickCountHistoryRepository; + public ClickCountHistoriesResponse findClickCountHistoryByNameAndDateBetween(final String name) { final LocalDate endDate = LocalDate.now().minusDays(1); final LocalDate startDate = endDate.minusDays(6); final List histories = clickCountHistoryRepository .findClickCountHistoryByNameAndDateBetweenOrderByDate(name, startDate, endDate); + final Map dateToClickCount = mapHistoriesToClickCount(histories); - List responses = buildResponse(startDate, dateToClickCount); + final List responses = buildResponse(startDate, endDate, dateToClickCount); return new ClickCountHistoriesResponse(responses); } - private static Map mapHistoriesToClickCount(final List histories) { + private Map mapHistoriesToClickCount(final List histories) { return histories.stream() .collect(Collectors.toMap( ClickCountHistory::getDate, - ClickCountHistory::getClickCount) - ); + ClickCountHistory::getClickCount + )); } - private static List buildResponse(final LocalDate startDate, final Map dateToClickCount) { - return IntStream.rangeClosed(0, 6) - .mapToObj(startDate::plusDays) + private List buildResponse( + final LocalDate startDate, + final LocalDate endDate, + final Map dateToClickCount + ) { + return startDate.datesUntil(endDate.plusDays(1)) .map(date -> new ClickCountHistoryResponse(date, dateToClickCount.getOrDefault(date, 0L))) .toList(); }