Skip to content

Commit

Permalink
fix : my에서 startDate 기준으로 가까운 3개
Browse files Browse the repository at this point in the history
  • Loading branch information
sycuuui committed Jun 12, 2024
1 parent 1f4e908 commit a257075
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

public interface PlanRepository extends JpaRepository<Plan, Long> {
Plan findPlanByPlanIdAndDeletedAtIsNull(Long planId);

Plan findPlanByMemberAndPlanIdAndDeletedAtIsNull(Member member,Long planId);
List<Plan> findAllByMemberAndDeletedAtIsNull(Member member);
Plan findPlanByMemberAndPlanIdAndEndDateIsBeforeAndDeletedAtIsNull(Member member, Long planId, LocalDate today);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -279,8 +277,12 @@ public List<MyPlanRes> findMyPlans(Member member) {
return null;
}
//Business
List<Plan> top3list = list.stream()
.sorted(Comparator.comparingLong(plan -> Math.abs(ChronoUnit.DAYS.between(LocalDate.now(), plan.getStartDate()))))
.limit(3)
.toList();
List<MyPlanRes> 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);
Expand Down Expand Up @@ -380,11 +382,15 @@ public String getPlanImageUrl(Member member,Plan plan){

public String getPlaceFirstImage(Member member,Plan plan){
List<Day> 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<String> getReviewImageList(List<PlanReviewImage> planReviewImageList){
Expand Down

0 comments on commit a257075

Please sign in to comment.