diff --git a/src/main/java/com/loopon/journey/application/JourneyQueryServiceImpl.java b/src/main/java/com/loopon/journey/application/JourneyQueryServiceImpl.java index e16e36d0..85f8aa23 100644 --- a/src/main/java/com/loopon/journey/application/JourneyQueryServiceImpl.java +++ b/src/main/java/com/loopon/journey/application/JourneyQueryServiceImpl.java @@ -17,6 +17,7 @@ import com.loopon.user.domain.User; import com.loopon.user.infrastructure.UserJpaRepository; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Slice; import org.springframework.stereotype.Service; @@ -292,13 +293,17 @@ public JourneyResponse.DailyJourneyReportDto getDailyJourneyReport( .orElseThrow(() -> new BusinessException(ErrorCode.JOURNEY_FEEDBACK_NOT_FOUND)); // RoutineReport 조회 - Optional routineReport = - routineReportRepository.findByUserAndJourneyAndDate( + List routineReports = + routineReportRepository.findFirstByUserAndJourneyAndDate( userId, journeyId, - date + date, + PageRequest.of(0,1) ); + Optional first = routineReports.stream().findFirst(); + String recordContent = first.map(RoutineReport::getContent).orElse(null); + return new JourneyResponse.DailyJourneyReportDto( journeyId, journey.getGoal(), @@ -310,7 +315,7 @@ public JourneyResponse.DailyJourneyReportDto getDailyJourneyReport( completedCount, - routineReport.map(RoutineReport::getContent), + Optional.ofNullable(recordContent), routineDtos ); diff --git a/src/main/java/com/loopon/routine/infrastructure/RoutineReportJpaRepository.java b/src/main/java/com/loopon/routine/infrastructure/RoutineReportJpaRepository.java index 5242dd7c..1157bcc2 100644 --- a/src/main/java/com/loopon/routine/infrastructure/RoutineReportJpaRepository.java +++ b/src/main/java/com/loopon/routine/infrastructure/RoutineReportJpaRepository.java @@ -1,24 +1,28 @@ package com.loopon.routine.infrastructure; import com.loopon.routine.domain.RoutineReport; +import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import java.time.LocalDate; -import java.util.Optional; +import java.util.List; + public interface RoutineReportJpaRepository extends JpaRepository { @Query(""" - SELECT rr - FROM RoutineReport rr - WHERE rr.user.id = :userId - AND rr.journey.id = :journeyId - AND DATE(rr.createdAt) = :date - """) - Optional findByUserAndJourneyAndDate( + SELECT rr + FROM RoutineReport rr + WHERE rr.user.id = :userId + AND rr.journey.id = :journeyId + AND DATE(rr.createdAt) = :date + ORDER BY rr.id ASC +""") + List findFirstByUserAndJourneyAndDate( @Param("userId") Long userId, @Param("journeyId") Long journeyId, - @Param("date") LocalDate date + @Param("date") LocalDate date, + Pageable pageable ); }