From 7838289ab9c23727d459bd3e1d58c4305e15c64b Mon Sep 17 00:00:00 2001 From: syyling Date: Wed, 1 May 2024 14:52:23 +0900 Subject: [PATCH] =?UTF-8?q?[feat]=20=EB=A6=AC=EB=B7=B0=20=EC=9B=94?= =?UTF-8?q?=EB=B3=84=20=EC=A1=B0=ED=9A=8C=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/response/RecordResponse.java | 27 +++++++++++ .../application/mapper/RecordMapper.java | 13 ++++++ .../application/service/RecordGetService.java | 46 ++++++++++++++++++- .../domain/repository/RecordRepository.java | 6 ++- .../domain/service/RecordQueryService.java | 5 ++ .../record/presentation/RecordController.java | 8 ++++ 6 files changed, 103 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/mookive/mookive_backend/record/application/dto/response/RecordResponse.java b/src/main/java/com/mookive/mookive_backend/record/application/dto/response/RecordResponse.java index 3b3661c..0a1cd7d 100644 --- a/src/main/java/com/mookive/mookive_backend/record/application/dto/response/RecordResponse.java +++ b/src/main/java/com/mookive/mookive_backend/record/application/dto/response/RecordResponse.java @@ -26,4 +26,31 @@ public RecordDetailResponse(String rating, String review, LocalDate date, List> getRecordByCalendar(String year, String month) { + String start = "01"; String end = "31"; + LocalDate startDate = getLocalDate(year, month, start); + LocalDate endDate = getLocalDate(year, month, end); + + List byDateBetween = recordQueryService.findByDateBetween(startDate, endDate); + List> RecordCalendarResponseList = new ArrayList<>(32); + for(int i = 0; i < 32; i++){ + RecordCalendarResponseList.add(null); + } + for(Record record : byDateBetween){ + Long movieId = record.getMovie().getId(); + Movie movie = movieQueryService.findById(movieId); + RecordResponse.RecordCalendarResponse recordCalendarResponse = RecordMapper.mapToRecordCalendarResponse(record, movie); + int dayOfMonth = record.getDate().getDayOfMonth(); + if(RecordCalendarResponseList.get(dayOfMonth) != null) { + RecordCalendarResponseList.get(dayOfMonth).add(recordCalendarResponse); + } else { + List recordCalendarResponseList = new ArrayList<>(); + recordCalendarResponseList.add(recordCalendarResponse); + RecordCalendarResponseList.add(dayOfMonth, recordCalendarResponseList); + } + } + return RecordCalendarResponseList; + } + + private static LocalDate getLocalDate(String year, String month, String day) { + if(day.equals("31")) { + if(month.equals("2")) { + day = "28"; + } else if(month.equals("4") || month.equals("6") || month.equals("9") || month.equals("11")) { + day = "30"; + } + } + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + String localDate = year + "-" + month + "-" + day; + return LocalDate.parse(localDate, formatter); + } + } diff --git a/src/main/java/com/mookive/mookive_backend/record/domain/repository/RecordRepository.java b/src/main/java/com/mookive/mookive_backend/record/domain/repository/RecordRepository.java index 9887baf..1f991fb 100644 --- a/src/main/java/com/mookive/mookive_backend/record/domain/repository/RecordRepository.java +++ b/src/main/java/com/mookive/mookive_backend/record/domain/repository/RecordRepository.java @@ -3,9 +3,13 @@ import com.mookive.mookive_backend.record.domain.entity.Record; import org.springframework.data.jpa.repository.JpaRepository; +import java.time.LocalDate; +import java.util.List; import java.util.Optional; public interface RecordRepository extends JpaRepository { - Optional findByUserIdAndMovieId(Long userId, Long movieId);; + Optional findByUserIdAndMovieId(Long userId, Long movieId); + + List findByDateBetween(LocalDate startDate, LocalDate endDate); } diff --git a/src/main/java/com/mookive/mookive_backend/record/domain/service/RecordQueryService.java b/src/main/java/com/mookive/mookive_backend/record/domain/service/RecordQueryService.java index 625d614..b05f222 100644 --- a/src/main/java/com/mookive/mookive_backend/record/domain/service/RecordQueryService.java +++ b/src/main/java/com/mookive/mookive_backend/record/domain/service/RecordQueryService.java @@ -6,6 +6,8 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import java.time.LocalDate; +import java.util.List; import java.util.Optional; @Service @@ -24,4 +26,7 @@ public Optional findByUserIdAndMovieId(Long userId, Long movieId) { return recordRepository.findByUserIdAndMovieId(userId, movieId); } + public List findByDateBetween(LocalDate startDate, LocalDate endDate) { + return recordRepository.findByDateBetween(startDate, endDate); + } } diff --git a/src/main/java/com/mookive/mookive_backend/record/presentation/RecordController.java b/src/main/java/com/mookive/mookive_backend/record/presentation/RecordController.java index 080cdc6..525efdc 100644 --- a/src/main/java/com/mookive/mookive_backend/record/presentation/RecordController.java +++ b/src/main/java/com/mookive/mookive_backend/record/presentation/RecordController.java @@ -7,6 +7,7 @@ import com.mookive.mookive_backend.record.application.service.RecordGetService; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.*; +import java.util.List; @RestController @RequiredArgsConstructor @@ -31,4 +32,11 @@ public void deleteRecord(@PathVariable Long recordId) { recordDeleteService.deleteRecord(recordId); } + @GetMapping("/record/calendar") + public List> getRecordByCalendar(@RequestParam String year, @RequestParam String month) { + return recordGetService.getRecordByCalendar(year, month); + + } + + }