From f3494c3152a329f9ec61b8eca69e35f23eb4ee84 Mon Sep 17 00:00:00 2001 From: yel-m Date: Sun, 26 May 2024 00:27:59 +0900 Subject: [PATCH 1/7] =?UTF-8?q?feat=20:=20=ED=96=89=EB=B3=B5=20=EC=A2=85?= =?UTF-8?q?=ED=95=A9=20=EB=A6=AC=ED=8F=AC=ED=8A=B8=20API=20=EA=B5=AC?= =?UTF-8?q?=EC=B6=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../record/repository/RecordRepository.java | 1 + .../domain/report/api/ReportController.java | 37 +++++++++++- .../ActivityHappinessAnalyzer.java | 59 +++++++++++++++++++ .../LocationHappinessAnalyzer.java | 57 ++++++++++++++++++ .../application/ReportSummaryService.java | 55 +++++++++++++++++ .../TimePeriodHappinessAnalyzer.java | 51 ++++++++++++++++ .../report/converter/ReportConverter.java | 14 +++++ .../domain/report/domain/TimePeriod.java | 43 ++++++++++++++ .../report/dto/ReportSummaryResponseDto.java | 23 ++++++++ 9 files changed, 339 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/hobak/happinessql/domain/report/application/ActivityHappinessAnalyzer.java create mode 100644 src/main/java/com/hobak/happinessql/domain/report/application/LocationHappinessAnalyzer.java create mode 100644 src/main/java/com/hobak/happinessql/domain/report/application/ReportSummaryService.java create mode 100644 src/main/java/com/hobak/happinessql/domain/report/application/TimePeriodHappinessAnalyzer.java create mode 100644 src/main/java/com/hobak/happinessql/domain/report/converter/ReportConverter.java create mode 100644 src/main/java/com/hobak/happinessql/domain/report/domain/TimePeriod.java create mode 100644 src/main/java/com/hobak/happinessql/domain/report/dto/ReportSummaryResponseDto.java diff --git a/src/main/java/com/hobak/happinessql/domain/record/repository/RecordRepository.java b/src/main/java/com/hobak/happinessql/domain/record/repository/RecordRepository.java index 37ee8bb..f3e3b16 100644 --- a/src/main/java/com/hobak/happinessql/domain/record/repository/RecordRepository.java +++ b/src/main/java/com/hobak/happinessql/domain/record/repository/RecordRepository.java @@ -13,4 +13,5 @@ public interface RecordRepository extends JpaRepository { Page findByUserOrderByRecordIdDesc(User user, Pageable pageRequest); Page findByRecordIdLessThanAndUserOrderByRecordIdDesc(Long recordId, User user, Pageable pageRequest); List findAllByCreatedAtBetweenAndUser(LocalDateTime startOfMonth, LocalDateTime endOfMonth, User user); + List findAllByUser(User user); } diff --git a/src/main/java/com/hobak/happinessql/domain/report/api/ReportController.java b/src/main/java/com/hobak/happinessql/domain/report/api/ReportController.java index caf0b16..f052854 100644 --- a/src/main/java/com/hobak/happinessql/domain/report/api/ReportController.java +++ b/src/main/java/com/hobak/happinessql/domain/report/api/ReportController.java @@ -1,15 +1,50 @@ package com.hobak.happinessql.domain.report.api; +import com.hobak.happinessql.domain.report.application.ReportSummaryService; +import com.hobak.happinessql.domain.report.dto.ReportSummaryResponseDto; +import com.hobak.happinessql.domain.user.application.UserFindService; +import com.hobak.happinessql.domain.user.domain.User; +import com.hobak.happinessql.global.response.DataResponseDto; +import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; +import org.springframework.security.core.annotation.AuthenticationPrincipal; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @Tag(name="Report", description = "행복 분석 리포트 관련 REST API에 대한 명세를 제공합니다.") @RestController @RequiredArgsConstructor -@RequestMapping("api/my-report") +@RequestMapping("api/report") public class ReportController { + private final UserFindService userFindService; + private final ReportSummaryService reportSummaryService; + @Operation(summary = "[전체] 행복 종합 리포트", description = "언제, 어디에서, 무엇을 할 때 행복했는지에 대한 종합적인 리포트를 제공합니다.") + @GetMapping("/all/summary") + public DataResponseDto getAllSummary(@AuthenticationPrincipal UserDetails userDetails) { + User user = userFindService.findByUserDetails(userDetails); + ReportSummaryResponseDto responseDto = reportSummaryService.getAllSummary(user); + return DataResponseDto.of(responseDto, "행복 종합 리포트(전체)를 성공적으로 조회했습니다."); + } + + @Operation(summary = "[연간] 행복 종합 리포트", description = "이번 해 언제, 어디에서, 무엇을 할 때 행복했는지에 대한 종합적인 리포트를 제공합니다.") + @GetMapping("/year/summary") + public DataResponseDto getAnnualSummary(@AuthenticationPrincipal UserDetails userDetails) { + User user = userFindService.findByUserDetails(userDetails); + ReportSummaryResponseDto responseDto = reportSummaryService.getAnnualSummary(user); + return DataResponseDto.of(responseDto, "행복 종합 리포트(연간)를 성공적으로 조회했습니다."); + } + + @Operation(summary = "[주간] 행복 종합 리포트", description = "이번 주 언제, 어디에서, 무엇을 할 때 행복했는지에 대한 종합적인 리포트를 제공합니다.") + @GetMapping("/week/summary") + public DataResponseDto getWeeklySummary(@AuthenticationPrincipal UserDetails userDetails) { + User user = userFindService.findByUserDetails(userDetails); + ReportSummaryResponseDto responseDto = reportSummaryService.getWeeklySummary(user); + return DataResponseDto.of(responseDto, "행복 종합 리포트(주간)를 성공적으로 조회했습니다."); + } + } diff --git a/src/main/java/com/hobak/happinessql/domain/report/application/ActivityHappinessAnalyzer.java b/src/main/java/com/hobak/happinessql/domain/report/application/ActivityHappinessAnalyzer.java new file mode 100644 index 0000000..a52a299 --- /dev/null +++ b/src/main/java/com/hobak/happinessql/domain/report/application/ActivityHappinessAnalyzer.java @@ -0,0 +1,59 @@ +package com.hobak.happinessql.domain.report.application; + +import com.hobak.happinessql.domain.record.domain.Record; + +import java.util.*; +import java.util.stream.Collectors; + +public class ActivityHappinessAnalyzer { + + public static String getHappiestActivity(List records) { + + if (records == null || records.isEmpty()) { + return null; + } + + // Activity를 기준으로 Record 그룹화 + Map> activityRecordsMap = records.stream() + .filter(record -> record.getActivity() != null) + .collect(Collectors.groupingBy(record -> record.getActivity().getName())); + + // 각 Activity별 평균 행복도와 빈도 계산 + Map activityAverageHappiness = new HashMap<>(); + Map activityFrequency = new HashMap<>(); + + activityRecordsMap.forEach((activity, recordList) -> { + activityAverageHappiness.put(activity, recordList.stream() + .mapToInt(Record::getHappiness) + .average() + .orElse(Double.NaN)); + activityFrequency.put(activity, recordList.size()); + }); + + // 평균 행복도가 가장 높은 Activity 찾기 + double maxHappiness = Collections.max(activityAverageHappiness.values()); + + + + // 평균 행복도가 가장 높은 Activity들 중 빈도가 가장 높은 Activity 찾기 + Optional happiestActivity = activityAverageHappiness.entrySet().stream() + .filter(entry -> entry.getValue() == maxHappiness) + .max(Comparator.comparing(entry -> activityFrequency.get(entry.getKey()))) + .map(Map.Entry::getKey); + + System.out.println("평균 행복도가 높은 Activity : " + happiestActivity + "행복도 : " + maxHappiness); + // 평균 행복도와 빈도가 같은 Activity가 여러 개인 경우, 랜덤으로 선택 + List happiestActivities = activityAverageHappiness.entrySet().stream() + .filter(entry -> entry.getValue() == maxHappiness) + .map(Map.Entry::getKey) + .collect(Collectors.toList()); + + if (happiestActivities.size() > 1) { + Collections.shuffle(happiestActivities); + return happiestActivities.get(0); + } else { + return happiestActivity.orElse(null); + } + } +} + diff --git a/src/main/java/com/hobak/happinessql/domain/report/application/LocationHappinessAnalyzer.java b/src/main/java/com/hobak/happinessql/domain/report/application/LocationHappinessAnalyzer.java new file mode 100644 index 0000000..f51ff7a --- /dev/null +++ b/src/main/java/com/hobak/happinessql/domain/report/application/LocationHappinessAnalyzer.java @@ -0,0 +1,57 @@ +package com.hobak.happinessql.domain.report.application; + +import com.hobak.happinessql.domain.record.domain.Record; + +import java.util.*; +import java.util.stream.Collectors; + +public class LocationHappinessAnalyzer { + + public static String getHappiestLocation(List records) { + + if (records == null || records.isEmpty()) { + return null; + } + + // 도시와 구를 기준으로 Record 그룹화 + Map> locationRecordsMap = records.stream() + .filter(record -> record.getLocation() != null) + .collect(Collectors.groupingBy(record -> + record.getLocation().getCity() + " " + record.getLocation().getDistrict())); + + // 각 위치별 평균 행복도와 빈도 계산 + Map locationAverageHappiness = new HashMap<>(); + Map locationFrequency = new HashMap<>(); + + locationRecordsMap.forEach((location, recordList) -> { + locationAverageHappiness.put(location, recordList.stream() + .mapToInt(Record::getHappiness) + .average() + .orElse(Double.NaN)); + locationFrequency.put(location, recordList.size()); + }); + + // 평균 행복도가 가장 높은 위치 찾기 + double maxHappiness = Collections.max(locationAverageHappiness.values()); + + // 평균 행복도가 가장 높은 위치들 중 빈도가 가장 높은 위치를 찾기 + Optional happiestLocation = locationAverageHappiness.entrySet().stream() + .filter(entry -> entry.getValue() == maxHappiness) + .max(Comparator.comparing(entry -> locationFrequency.get(entry.getKey()))) + .map(Map.Entry::getKey); + + // 평균 행복도와 빈도가 같다면, 랜덤으로 선택 + List happiestLocations = locationAverageHappiness.entrySet().stream() + .filter(entry -> entry.getValue() == maxHappiness) + .map(Map.Entry::getKey) + .collect(Collectors.toList()); + + if (happiestLocations.size() > 1) { + Collections.shuffle(happiestLocations); + return happiestLocations.get(0); + } else { + return happiestLocation.orElse(null); + } + } + +} diff --git a/src/main/java/com/hobak/happinessql/domain/report/application/ReportSummaryService.java b/src/main/java/com/hobak/happinessql/domain/report/application/ReportSummaryService.java new file mode 100644 index 0000000..a931f6e --- /dev/null +++ b/src/main/java/com/hobak/happinessql/domain/report/application/ReportSummaryService.java @@ -0,0 +1,55 @@ +package com.hobak.happinessql.domain.report.application; + +import com.hobak.happinessql.domain.record.domain.Record; +import com.hobak.happinessql.domain.record.repository.RecordRepository; +import com.hobak.happinessql.domain.report.converter.ReportConverter; +import com.hobak.happinessql.domain.report.domain.TimePeriod; +import com.hobak.happinessql.domain.report.dto.ReportSummaryResponseDto; +import com.hobak.happinessql.domain.user.domain.User; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import java.time.DayOfWeek; +import java.time.LocalDate; +import java.time.LocalDateTime; + +import java.util.List; + +@Service +@RequiredArgsConstructor +public class ReportSummaryService { + + private final RecordRepository recordRepository; + + public ReportSummaryResponseDto getAllSummary(User user) { + List records = recordRepository.findAllByUser(user); + return generateReportSummary(records); + } + + public ReportSummaryResponseDto getAnnualSummary(User user) { + Integer currentYear = LocalDate.now().getYear(); + LocalDateTime startOfYear = LocalDateTime.of(currentYear, 1, 1, 0, 0); + LocalDateTime endOfYear = LocalDateTime.of(currentYear, 12, 31, 23, 59, 59); + + List annualRecords = recordRepository.findAllByCreatedAtBetweenAndUser(startOfYear, endOfYear, user); + return generateReportSummary(annualRecords); + } + + public ReportSummaryResponseDto getWeeklySummary(User user) { + LocalDate today = LocalDate.now().with(DayOfWeek.MONDAY); + LocalDate startOfWeek = today.with(DayOfWeek.MONDAY); + LocalDateTime startOfWeekDateTime = startOfWeek.atStartOfDay(); + LocalDateTime endOfWeekDateTime = startOfWeek.plusDays(6).atTime(23, 59, 59); + + List weeklyRecords = recordRepository.findAllByCreatedAtBetweenAndUser(startOfWeekDateTime, endOfWeekDateTime, user); + return generateReportSummary(weeklyRecords); + } + + private ReportSummaryResponseDto generateReportSummary(List records) { + String location = LocationHappinessAnalyzer.getHappiestLocation(records); + TimePeriod timePeriod = TimePeriodHappinessAnalyzer.getHappiestTimePeriod(records); + String activity = ActivityHappinessAnalyzer.getHappiestActivity(records); + + return ReportConverter.toReportSummaryResponseDto(timePeriod, location, activity); + } +} diff --git a/src/main/java/com/hobak/happinessql/domain/report/application/TimePeriodHappinessAnalyzer.java b/src/main/java/com/hobak/happinessql/domain/report/application/TimePeriodHappinessAnalyzer.java new file mode 100644 index 0000000..d3f0672 --- /dev/null +++ b/src/main/java/com/hobak/happinessql/domain/report/application/TimePeriodHappinessAnalyzer.java @@ -0,0 +1,51 @@ +package com.hobak.happinessql.domain.report.application; + +import com.hobak.happinessql.domain.record.domain.Record; +import com.hobak.happinessql.domain.report.domain.TimePeriod; + +import java.util.*; +import java.util.stream.Collectors; + +public class TimePeriodHappinessAnalyzer { + + public static TimePeriod getHappiestTimePeriod(List records) { + + if (records == null || records.isEmpty()) { + return null; + } + + Map> timePeriodHappinessMap = new HashMap<>(); + + // 시간대별 행복도를 매핑 + for (Record record : records) { + TimePeriod timePeriod = TimePeriod.of(record.getCreatedAt().getHour()); + Integer happiness = record.getHappiness(); + + timePeriodHappinessMap.computeIfAbsent(timePeriod, k -> new ArrayList<>()).add(happiness); + } + + // 평균 행복도 계산 + Map averageHappinessMap = timePeriodHappinessMap.entrySet().stream() + .collect(Collectors.toMap(Map.Entry::getKey, + entry -> entry.getValue().stream().mapToInt(Integer::intValue).average().orElse(0))); + + // 최대 평균 행복도를 가진 시간대 찾기 + double maxAverageHappiness = averageHappinessMap.values().stream() + .max(Double::compare) + .orElse(Double.MIN_VALUE); + + // 최대 평균 행복도를 가진 시간대 후보들 필터링 + List candidates = averageHappinessMap.entrySet().stream() + .filter(entry -> entry.getValue() == maxAverageHappiness) + .map(Map.Entry::getKey) + .collect(Collectors.toList()); + for(TimePeriod candidate : candidates) { + System.out.println("candidate : " + candidate); + } + + // 후보 중 빈도수가 가장 높은 시간대 찾기, 동일 빈도시 랜덤 선택 + return candidates.stream() + .max(Comparator.comparingInt(tp -> timePeriodHappinessMap.get(tp).size())) + .orElseGet(() -> candidates.get(new Random().nextInt(candidates.size()))); + } +} diff --git a/src/main/java/com/hobak/happinessql/domain/report/converter/ReportConverter.java b/src/main/java/com/hobak/happinessql/domain/report/converter/ReportConverter.java new file mode 100644 index 0000000..d517377 --- /dev/null +++ b/src/main/java/com/hobak/happinessql/domain/report/converter/ReportConverter.java @@ -0,0 +1,14 @@ +package com.hobak.happinessql.domain.report.converter; + +import com.hobak.happinessql.domain.report.domain.TimePeriod; +import com.hobak.happinessql.domain.report.dto.ReportSummaryResponseDto; + +public class ReportConverter { + public static ReportSummaryResponseDto toReportSummaryResponseDto(TimePeriod timePeriod, String location, String activity) { + return ReportSummaryResponseDto.builder() + .activity(activity) + .location(location) + .timePeriod(timePeriod) + .build(); + } +} diff --git a/src/main/java/com/hobak/happinessql/domain/report/domain/TimePeriod.java b/src/main/java/com/hobak/happinessql/domain/report/domain/TimePeriod.java new file mode 100644 index 0000000..1a5e770 --- /dev/null +++ b/src/main/java/com/hobak/happinessql/domain/report/domain/TimePeriod.java @@ -0,0 +1,43 @@ +package com.hobak.happinessql.domain.report.domain; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; +import com.hobak.happinessql.domain.user.domain.Gender; +import lombok.AllArgsConstructor; + +@AllArgsConstructor +public enum TimePeriod { + MORNING("아침"), + AFTERNOON("점심"), + EVENING("저녁"), + NIGHT("밤"); + + private final String viewName; + + public static TimePeriod of(int hour) { + if (hour >= 6 && hour < 12) { + return MORNING; + } else if (hour >= 12 && hour < 18) { + return AFTERNOON; + } else if (hour >= 18 && hour < 24) { + return EVENING; + } else { + return NIGHT; + } + } + + @JsonCreator + public static TimePeriod from(String value) { + for (TimePeriod status : TimePeriod.values()) { + if (status.getViewName().equals(value)) { + return status; + } + } + return null; + } + + @JsonValue + public String getViewName() { + return viewName; + } +} diff --git a/src/main/java/com/hobak/happinessql/domain/report/dto/ReportSummaryResponseDto.java b/src/main/java/com/hobak/happinessql/domain/report/dto/ReportSummaryResponseDto.java new file mode 100644 index 0000000..2e14c83 --- /dev/null +++ b/src/main/java/com/hobak/happinessql/domain/report/dto/ReportSummaryResponseDto.java @@ -0,0 +1,23 @@ +package com.hobak.happinessql.domain.report.dto; + +import com.hobak.happinessql.domain.report.domain.TimePeriod; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + + +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class ReportSummaryResponseDto { + private TimePeriod timePeriod; + private String location; + private String activity; + + @Builder + public ReportSummaryResponseDto(TimePeriod timePeriod, String location, String activity) { + this.timePeriod = timePeriod; + this.location = location; + this.activity = activity; + } +} From be4ad068cdb8a5759fdb69c4dccfb694599b0125 Mon Sep 17 00:00:00 2001 From: yel-m Date: Sun, 26 May 2024 00:31:50 +0900 Subject: [PATCH 2/7] =?UTF-8?q?fix=20:=20currentYear=20=ED=83=80=EC=9E=85?= =?UTF-8?q?=20int=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/report/application/ReportSummaryService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/hobak/happinessql/domain/report/application/ReportSummaryService.java b/src/main/java/com/hobak/happinessql/domain/report/application/ReportSummaryService.java index a931f6e..0a6a095 100644 --- a/src/main/java/com/hobak/happinessql/domain/report/application/ReportSummaryService.java +++ b/src/main/java/com/hobak/happinessql/domain/report/application/ReportSummaryService.java @@ -27,7 +27,7 @@ public ReportSummaryResponseDto getAllSummary(User user) { } public ReportSummaryResponseDto getAnnualSummary(User user) { - Integer currentYear = LocalDate.now().getYear(); + int currentYear = LocalDate.now().getYear(); LocalDateTime startOfYear = LocalDateTime.of(currentYear, 1, 1, 0, 0); LocalDateTime endOfYear = LocalDateTime.of(currentYear, 12, 31, 23, 59, 59); From 4ff783795afb7a99960d11a51896bfcc198ec00c Mon Sep 17 00:00:00 2001 From: yel-m Date: Sun, 26 May 2024 00:32:16 +0900 Subject: [PATCH 3/7] =?UTF-8?q?refactor=20:=20=EC=82=AC=EC=9A=A9=ED=95=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EB=8A=94=20import=EB=AC=B8=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/hobak/happinessql/domain/report/domain/TimePeriod.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/hobak/happinessql/domain/report/domain/TimePeriod.java b/src/main/java/com/hobak/happinessql/domain/report/domain/TimePeriod.java index 1a5e770..6937d05 100644 --- a/src/main/java/com/hobak/happinessql/domain/report/domain/TimePeriod.java +++ b/src/main/java/com/hobak/happinessql/domain/report/domain/TimePeriod.java @@ -2,7 +2,6 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonValue; -import com.hobak.happinessql.domain.user.domain.Gender; import lombok.AllArgsConstructor; @AllArgsConstructor From 1c6b73a25624a97ab2c40cb60827cf07f12047bb Mon Sep 17 00:00:00 2001 From: yel-m Date: Sun, 26 May 2024 00:33:11 +0900 Subject: [PATCH 4/7] =?UTF-8?q?refactor=20:=20=EB=A1=9C=EA=B7=B8=20?= =?UTF-8?q?=ED=94=84=EB=A6=B0=ED=8A=B8=20=EC=82=AD=EC=A0=9C=20=EB=B0=8F=20?= =?UTF-8?q?=EB=B9=88=20=EB=A6=AC=EC=8A=A4=ED=8A=B8=EC=97=90=EC=84=9C=20?= =?UTF-8?q?=EB=9E=9C=EB=8D=A4=20=EC=9A=94=EC=86=8C=20=EA=B0=80=EC=A0=B8?= =?UTF-8?q?=EC=98=A4=EA=B8=B0=20=EB=B0=A9=EC=A7=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../report/application/TimePeriodHappinessAnalyzer.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/hobak/happinessql/domain/report/application/TimePeriodHappinessAnalyzer.java b/src/main/java/com/hobak/happinessql/domain/report/application/TimePeriodHappinessAnalyzer.java index d3f0672..5b7d259 100644 --- a/src/main/java/com/hobak/happinessql/domain/report/application/TimePeriodHappinessAnalyzer.java +++ b/src/main/java/com/hobak/happinessql/domain/report/application/TimePeriodHappinessAnalyzer.java @@ -38,9 +38,10 @@ public static TimePeriod getHappiestTimePeriod(List records) { List candidates = averageHappinessMap.entrySet().stream() .filter(entry -> entry.getValue() == maxAverageHappiness) .map(Map.Entry::getKey) - .collect(Collectors.toList()); - for(TimePeriod candidate : candidates) { - System.out.println("candidate : " + candidate); + .toList(); + + if (candidates.isEmpty()) { + return null; } // 후보 중 빈도수가 가장 높은 시간대 찾기, 동일 빈도시 랜덤 선택 From 64be7b9bd0621eef2fd624ff5a06e9d40af09b93 Mon Sep 17 00:00:00 2001 From: yel-m Date: Sun, 26 May 2024 00:44:23 +0900 Subject: [PATCH 5/7] =?UTF-8?q?fix=20:=20=EC=A3=BC=EA=B0=84=20=EB=A6=AC?= =?UTF-8?q?=ED=8F=AC=ED=8A=B8=20->=20=EC=9B=94=EA=B0=84=20=EB=A6=AC?= =?UTF-8?q?=ED=8F=AC=ED=8A=B8=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/report/api/ReportController.java | 10 +++++----- .../report/application/ReportSummaryService.java | 14 ++++++-------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/hobak/happinessql/domain/report/api/ReportController.java b/src/main/java/com/hobak/happinessql/domain/report/api/ReportController.java index f052854..b14dbb0 100644 --- a/src/main/java/com/hobak/happinessql/domain/report/api/ReportController.java +++ b/src/main/java/com/hobak/happinessql/domain/report/api/ReportController.java @@ -39,12 +39,12 @@ public DataResponseDto getAnnualSummary(@Authenticatio return DataResponseDto.of(responseDto, "행복 종합 리포트(연간)를 성공적으로 조회했습니다."); } - @Operation(summary = "[주간] 행복 종합 리포트", description = "이번 주 언제, 어디에서, 무엇을 할 때 행복했는지에 대한 종합적인 리포트를 제공합니다.") - @GetMapping("/week/summary") - public DataResponseDto getWeeklySummary(@AuthenticationPrincipal UserDetails userDetails) { + @Operation(summary = "[월간] 행복 종합 리포트", description = "이번 달 언제, 어디에서, 무엇을 할 때 행복했는지에 대한 종합적인 리포트를 제공합니다.") + @GetMapping("/month/summary") + public DataResponseDto getMonthlySummary(@AuthenticationPrincipal UserDetails userDetails) { User user = userFindService.findByUserDetails(userDetails); - ReportSummaryResponseDto responseDto = reportSummaryService.getWeeklySummary(user); - return DataResponseDto.of(responseDto, "행복 종합 리포트(주간)를 성공적으로 조회했습니다."); + ReportSummaryResponseDto responseDto = reportSummaryService.getMonthlySummary(user); + return DataResponseDto.of(responseDto, "행복 종합 리포트(월간)를 성공적으로 조회했습니다."); } } diff --git a/src/main/java/com/hobak/happinessql/domain/report/application/ReportSummaryService.java b/src/main/java/com/hobak/happinessql/domain/report/application/ReportSummaryService.java index 0a6a095..a79745e 100644 --- a/src/main/java/com/hobak/happinessql/domain/report/application/ReportSummaryService.java +++ b/src/main/java/com/hobak/happinessql/domain/report/application/ReportSummaryService.java @@ -9,7 +9,6 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; -import java.time.DayOfWeek; import java.time.LocalDate; import java.time.LocalDateTime; @@ -35,14 +34,13 @@ public ReportSummaryResponseDto getAnnualSummary(User user) { return generateReportSummary(annualRecords); } - public ReportSummaryResponseDto getWeeklySummary(User user) { - LocalDate today = LocalDate.now().with(DayOfWeek.MONDAY); - LocalDate startOfWeek = today.with(DayOfWeek.MONDAY); - LocalDateTime startOfWeekDateTime = startOfWeek.atStartOfDay(); - LocalDateTime endOfWeekDateTime = startOfWeek.plusDays(6).atTime(23, 59, 59); + public ReportSummaryResponseDto getMonthlySummary(User user) { + LocalDate today = LocalDate.now(); + LocalDateTime startOfMonth = today.withDayOfMonth(1).atStartOfDay(); + LocalDateTime endOfMonth = today.withDayOfMonth(today.lengthOfMonth()).atTime(23, 59, 59); - List weeklyRecords = recordRepository.findAllByCreatedAtBetweenAndUser(startOfWeekDateTime, endOfWeekDateTime, user); - return generateReportSummary(weeklyRecords); + List monthlyRecords = recordRepository.findAllByCreatedAtBetweenAndUser(startOfMonth, endOfMonth, user); + return generateReportSummary(monthlyRecords); } private ReportSummaryResponseDto generateReportSummary(List records) { From 32ba027ff55e45001fd22cd73ebf3913ec36fcaf Mon Sep 17 00:00:00 2001 From: yel-m Date: Sun, 26 May 2024 01:03:49 +0900 Subject: [PATCH 6/7] =?UTF-8?q?fix=20:=20JSON=20Key=20=EA=B0=92=20?= =?UTF-8?q?=EC=8A=A4=EB=84=A4=EC=9D=B4=ED=81=AC=20=EC=BC=80=EC=9D=B4?= =?UTF-8?q?=EC=8A=A4=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/report/dto/ReportSummaryResponseDto.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/com/hobak/happinessql/domain/report/dto/ReportSummaryResponseDto.java b/src/main/java/com/hobak/happinessql/domain/report/dto/ReportSummaryResponseDto.java index 2e14c83..cab3aa2 100644 --- a/src/main/java/com/hobak/happinessql/domain/report/dto/ReportSummaryResponseDto.java +++ b/src/main/java/com/hobak/happinessql/domain/report/dto/ReportSummaryResponseDto.java @@ -1,5 +1,6 @@ package com.hobak.happinessql.domain.report.dto; +import com.fasterxml.jackson.annotation.JsonProperty; import com.hobak.happinessql.domain.report.domain.TimePeriod; import lombok.AccessLevel; import lombok.Builder; @@ -10,8 +11,12 @@ @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) public class ReportSummaryResponseDto { + + @JsonProperty("time_period") private TimePeriod timePeriod; + private String location; + private String activity; @Builder From 63f8e30a7ea0dc014167ceaf232209780b58c6f8 Mon Sep 17 00:00:00 2001 From: yel-m Date: Sun, 26 May 2024 01:16:11 +0900 Subject: [PATCH 7/7] =?UTF-8?q?fix=20:=20=EC=8B=9C=EA=B0=84=EB=8C=80=20?= =?UTF-8?q?=EA=B8=B0=EC=A4=80=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../happinessql/domain/report/domain/TimePeriod.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/hobak/happinessql/domain/report/domain/TimePeriod.java b/src/main/java/com/hobak/happinessql/domain/report/domain/TimePeriod.java index 6937d05..79d1f98 100644 --- a/src/main/java/com/hobak/happinessql/domain/report/domain/TimePeriod.java +++ b/src/main/java/com/hobak/happinessql/domain/report/domain/TimePeriod.java @@ -6,19 +6,22 @@ @AllArgsConstructor public enum TimePeriod { + DAWN("새벽"), MORNING("아침"), - AFTERNOON("점심"), + AFTERNOON("낮"), EVENING("저녁"), NIGHT("밤"); private final String viewName; public static TimePeriod of(int hour) { - if (hour >= 6 && hour < 12) { + if (hour >= 0 && hour < 5) { + return DAWN; + } else if (hour >= 5 && hour < 9) { return MORNING; - } else if (hour >= 12 && hour < 18) { + } else if (hour >= 9 && hour < 17) { return AFTERNOON; - } else if (hour >= 18 && hour < 24) { + } else if (hour >= 17 && hour < 21) { return EVENING; } else { return NIGHT;