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 e7b8da6..8a84424 100644 --- a/src/main/java/Journey/Together/domain/plan/repository/PlanRepository.java +++ b/src/main/java/Journey/Together/domain/plan/repository/PlanRepository.java @@ -5,6 +5,8 @@ import org.springframework.data.domain.Page; 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.List; @@ -19,6 +21,12 @@ public interface PlanRepository extends JpaRepository { Page findAllByMemberAndEndDateBeforeAndDeletedAtIsNull(Member member, LocalDate today, Pageable pageable); // 오늘을 포함하여 지나지 않은 계획들 Page findAllByMemberAndEndDateGreaterThanEqualAndDeletedAtIsNull(Member member, LocalDate today, Pageable pageable); - Page findAllByEndDateBeforeAndIsPublicIsTrueAndDeletedAtIsNull(LocalDate today,Pageable pageable); + @Query("SELECT p FROM Plan p " + + "LEFT JOIN PlanReview pr ON p.planId = pr.plan.planId " + + "WHERE p.endDate < :now " + + "AND p.isPublic = true " + + "AND p.deletedAt IS NULL " + + "AND (pr.report IS NULL OR pr.report = false)") + Page findOpenPlans(@Param("now") LocalDate now, Pageable pageable); } diff --git a/src/main/java/Journey/Together/domain/plan/repository/PlanReviewRepository.java b/src/main/java/Journey/Together/domain/plan/repository/PlanReviewRepository.java index 191517f..17025d8 100644 --- a/src/main/java/Journey/Together/domain/plan/repository/PlanReviewRepository.java +++ b/src/main/java/Journey/Together/domain/plan/repository/PlanReviewRepository.java @@ -15,8 +15,8 @@ public interface PlanReviewRepository extends JpaRepository { "WHERE pr.plan = :plan AND (pr.report IS NULL OR pr.report = false))") boolean existsAllByPlanAndReportFilter(@Param("plan") Plan plan); - @Query("SELECT pr FROM PlanReview pr WHERE pr.plan = :plan AND (pr.report IS NULL OR pr.report = false) AND pr.deletedAt is null ") - PlanReview findPlanReviewByReportFillter(Plan plan); + @Query("SELECT pr FROM PlanReview pr WHERE pr.plan = :plan") + PlanReview findPlanReview(Plan plan); PlanReview findPlanReviewByPlanReviewId(Long id); PlanReview findPlanReviewByPlanAndDeletedAtIsNull(Plan plan); 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 276a50b..d96dfd6 100644 --- a/src/main/java/Journey/Together/domain/plan/service/PlanService.java +++ b/src/main/java/Journey/Together/domain/plan/service/PlanService.java @@ -218,7 +218,7 @@ public PlanReviewRes findPlanReview(Member member,long planId){ if(plan == null){ throw new ApplicationException(ErrorCode.NOT_FOUND_EXCEPTION); } - PlanReview planReview = planReviewRepository.findPlanReviewByReportFillter(plan); + PlanReview planReview = planReviewRepository.findPlanReview(plan); //Buisness boolean isWriter; if (member ==null){ @@ -226,11 +226,17 @@ public PlanReviewRes findPlanReview(Member member,long planId){ }else { isWriter = plan.getMember().getMemberId().equals(member.getMemberId()); } - List imageList = getReviewImageList(plan); String profileUrl = s3Client.baseUrl()+plan.getMember().getProfileUuid()+"/profile_"+plan.getMember().getProfileUuid(); if(planReview==null){ - return PlanReviewRes.of(null,null,null,isWriter,false,imageList,profileUrl,null); + //리뷰가 없을 경우 + return PlanReviewRes.of(null,null,null,isWriter,false,null,profileUrl,null); }else { + List imageList = getReviewImageList(planReview); + //리뷰가 있고 신고 없을 경우 + if(planReview.getReport()==null){ + return PlanReviewRes.of(planReview.getPlanReviewId(),planReview.getContent(),planReview.getGrade(),isWriter,true,imageList,profileUrl,null); + } + //리뷰가 있고 신고 비승인 return PlanReviewRes.of(planReview.getPlanReviewId(),planReview.getContent(),planReview.getGrade(),isWriter,true,imageList,profileUrl,planReview.getReport()); } @@ -359,7 +365,7 @@ public PlanPageRes findIsCompelete(Member member, Pageable page, Boolean compele @Transactional public OpenPlanPageRes findOpenPlans(Pageable page){ Pageable pageable = PageRequest.of(page.getPageNumber(), page.getPageSize(), Sort.by("createdAt").descending()); - Page planPage = planRepository.findAllByEndDateBeforeAndIsPublicIsTrueAndDeletedAtIsNull(LocalDate.now(),pageable); + Page planPage = planRepository.findOpenPlans(LocalDate.now(),pageable); List openPlanResList = planPage.getContent().stream() .map(plan -> OpenPlanRes.of(plan, s3Client.baseUrl()+plan.getMember().getProfileUuid()+"/profile_"+plan.getMember().getProfileUuid(),getPlaceFirstImage(plan))) .collect(Collectors.toList()); @@ -413,9 +419,8 @@ public List getPlaceImageList(Plan plan){ return null; } - public List getReviewImageList(Plan plan){ + public List getReviewImageList(PlanReview planReview){ List list = new ArrayList<>(); - PlanReview planReview = planReviewRepository.findPlanReviewByReportFillter(plan); List planReviewImageList = planReviewImageRepository.findAllByPlanReviewAndDeletedAtIsNull(planReview); for(PlanReviewImage planReviewImage : planReviewImageList){ list.add(planReviewImage.getImageUrl());