From a257075ec97b45e45731a5b71a198e11ac800f95 Mon Sep 17 00:00:00 2001 From: sycuuui <102959791+sycuuui@users.noreply.github.com> Date: Wed, 12 Jun 2024 12:39:41 +0900 Subject: [PATCH] =?UTF-8?q?fix=20:=20my=EC=97=90=EC=84=9C=20startDate=20?= =?UTF-8?q?=EA=B8=B0=EC=A4=80=EC=9C=BC=EB=A1=9C=20=EA=B0=80=EA=B9=8C?= =?UTF-8?q?=EC=9A=B4=203=EA=B0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plan/repository/PlanRepository.java | 1 - .../domain/plan/service/PlanService.java | 24 ++++++++++++------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/main/java/Journey/Together/domain/plan/repository/PlanRepository.java b/src/main/java/Journey/Together/domain/plan/repository/PlanRepository.java index 0379de7..e7b8da6 100644 --- a/src/main/java/Journey/Together/domain/plan/repository/PlanRepository.java +++ b/src/main/java/Journey/Together/domain/plan/repository/PlanRepository.java @@ -11,7 +11,6 @@ public interface PlanRepository extends JpaRepository { Plan findPlanByPlanIdAndDeletedAtIsNull(Long planId); - Plan findPlanByMemberAndPlanIdAndDeletedAtIsNull(Member member,Long planId); List findAllByMemberAndDeletedAtIsNull(Member member); Plan findPlanByMemberAndPlanIdAndEndDateIsBeforeAndDeletedAtIsNull(Member member, Long planId, LocalDate today); diff --git a/src/main/java/Journey/Together/domain/plan/service/PlanService.java b/src/main/java/Journey/Together/domain/plan/service/PlanService.java index 0363c42..aab2fc1 100644 --- a/src/main/java/Journey/Together/domain/plan/service/PlanService.java +++ b/src/main/java/Journey/Together/domain/plan/service/PlanService.java @@ -28,10 +28,8 @@ import java.time.LocalDate; import java.time.Period; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; -import java.util.UUID; +import java.time.temporal.ChronoUnit; +import java.util.*; import java.util.stream.Collectors; @Service @@ -279,8 +277,12 @@ public List findMyPlans(Member member) { return null; } //Business + List top3list = list.stream() + .sorted(Comparator.comparingLong(plan -> Math.abs(ChronoUnit.DAYS.between(LocalDate.now(), plan.getStartDate())))) + .limit(3) + .toList(); List myPlanResList = new ArrayList<>(); - for(Plan plan : list){ + for(Plan plan : top3list){ String image = getPlanImageUrl(member,plan); if (LocalDate.now().isAfter(plan.getEndDate())){ Boolean hasReview = planReviewRepository.existsAllByPlan(plan); @@ -380,11 +382,15 @@ public String getPlanImageUrl(Member member,Plan plan){ public String getPlaceFirstImage(Member member,Plan plan){ List dayList = dayRepository.findByMemberAndDateAndPlanOrderByCreatedAtDesc(member,plan.getStartDate(),plan); - String placeImageUrl = dayList.get(0).getPlace().getFirstImg(); - if(!placeImageUrl.isEmpty()){ - return null; + if(!dayList.isEmpty()){ + System.out.println(dayList); + String placeImageUrl = dayList.get(0).getPlace().getFirstImg(); + if(!placeImageUrl.isEmpty()){ + return null; + } + return dayList.get(0).getPlace().getFirstImg(); } - return dayList.get(0).getPlace().getFirstImg(); + return null; } public List getReviewImageList(List planReviewImageList){