diff --git a/src/main/java/Journey/Together/domain/dairy/dto/PlanDetailRes.java b/src/main/java/Journey/Together/domain/dairy/dto/PlanDetailRes.java index 36fe30e..7f46b59 100644 --- a/src/main/java/Journey/Together/domain/dairy/dto/PlanDetailRes.java +++ b/src/main/java/Journey/Together/domain/dairy/dto/PlanDetailRes.java @@ -4,10 +4,16 @@ import Journey.Together.domain.member.entity.Member; import lombok.Builder; +import java.time.LocalDate; import java.util.List; @Builder public record PlanDetailRes( + String title, + LocalDate startDate, + LocalDate endDate, + String remainDate, + Boolean isPublic, List imageUrls, List dailyList, Boolean isWriter, @@ -15,8 +21,13 @@ public record PlanDetailRes( String writerNickname ) { public static PlanDetailRes of(List imageUrls, - List dailyList, Boolean isWriter, Plan plan){ + List dailyList, Boolean isWriter, Plan plan,String remainDate){ return PlanDetailRes.builder() + .title(plan.getTitle()) + .startDate(plan.getStartDate()) + .endDate(plan.getEndDate()) + .remainDate(remainDate) + .isPublic(plan.getIsPublic()) .imageUrls(imageUrls) .dailyList(dailyList) .isWriter(isWriter) diff --git a/src/main/java/Journey/Together/domain/dairy/service/PlanService.java b/src/main/java/Journey/Together/domain/dairy/service/PlanService.java index 453029a..3cf6c9f 100644 --- a/src/main/java/Journey/Together/domain/dairy/service/PlanService.java +++ b/src/main/java/Journey/Together/domain/dairy/service/PlanService.java @@ -59,6 +59,7 @@ public void savePlan(Member member, PlanReq planReq){ .title(planReq.title()) .startDate(planReq.startDate()) .endDate(planReq.endDate()) + .isPublic(false) .build(); planRepository.save(plan); //날짜별 장소 정보 저장 @@ -129,7 +130,7 @@ public PlanDetailRes findPlanDetail(Member member, Long planId){ if(plan.getEndDate().isAfter(LocalDate.now())){ //imageUrl : 장소 사진 for(Day day : dayList){ - if(day.getPlace().getFirstImg()!=null){ + if(!day.getPlace().getFirstImg().isEmpty()){ imageUrls.add(day.getPlace().getFirstImg()); } } @@ -139,7 +140,7 @@ public PlanDetailRes findPlanDetail(Member member, Long planId){ if(planReviewImageList == null){ //imageUrl : 장소사진 for(Day day : dayList){ - if(day.getPlace().getFirstImg()!=null){ + if(!day.getPlace().getFirstImg().isEmpty()){ imageUrls.add(day.getPlace().getFirstImg()); } } @@ -164,9 +165,18 @@ public PlanDetailRes findPlanDetail(Member member, Long planId){ }else { isWriter = plan.getMember().getMemberId().equals(member.getMemberId()); } + + String remainDate = null; + if ((LocalDate.now().isEqual(plan.getStartDate()) || LocalDate.now().isAfter(plan.getStartDate())) && (LocalDate.now().isEqual(plan.getEndDate()) || LocalDate.now().isBefore(plan.getEndDate()))){ + remainDate = "D-Day"; + }else if (LocalDate.now().isBefore(plan.getStartDate())){ + Period period = Period.between(LocalDate.now(),plan.getStartDate()); + remainDate = "D-"+ period.getDays(); + } + //PlanDetailRes - List imageUrls, List dailyList, Boolean isWriter //Response - return PlanDetailRes.of(imageUrls,dailyLists,isWriter,plan); + return PlanDetailRes.of(imageUrls,dailyLists,isWriter,plan,remainDate); } @Transactional @@ -373,7 +383,7 @@ 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==null){ + if(!placeImageUrl.isEmpty()){ return null; } return dayList.get(0).getPlace().getFirstImg();