Skip to content

Commit

Permalink
fix : isReport 관련 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
sycuuui committed Sep 15, 2024
1 parent a047460 commit b4f75fa
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -19,6 +21,12 @@ public interface PlanRepository extends JpaRepository<Plan, Long> {
Page<Plan> findAllByMemberAndEndDateBeforeAndDeletedAtIsNull(Member member, LocalDate today, Pageable pageable);
// 오늘을 포함하여 지나지 않은 계획들
Page<Plan> findAllByMemberAndEndDateGreaterThanEqualAndDeletedAtIsNull(Member member, LocalDate today, Pageable pageable);
Page<Plan> 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<Plan> findOpenPlans(@Param("now") LocalDate now, Pageable pageable);

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public interface PlanReviewRepository extends JpaRepository<PlanReview,Long> {
"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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,19 +218,25 @@ 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){
isWriter = false;
}else {
isWriter = plan.getMember().getMemberId().equals(member.getMemberId());
}
List<String> 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<String> 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());
}

Expand Down Expand Up @@ -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<Plan> planPage = planRepository.findAllByEndDateBeforeAndIsPublicIsTrueAndDeletedAtIsNull(LocalDate.now(),pageable);
Page<Plan> planPage = planRepository.findOpenPlans(LocalDate.now(),pageable);
List<OpenPlanRes> openPlanResList = planPage.getContent().stream()
.map(plan -> OpenPlanRes.of(plan, s3Client.baseUrl()+plan.getMember().getProfileUuid()+"/profile_"+plan.getMember().getProfileUuid(),getPlaceFirstImage(plan)))
.collect(Collectors.toList());
Expand Down Expand Up @@ -413,9 +419,8 @@ public List<String> getPlaceImageList(Plan plan){
return null;
}

public List<String> getReviewImageList(Plan plan){
public List<String> getReviewImageList(PlanReview planReview){
List<String> list = new ArrayList<>();
PlanReview planReview = planReviewRepository.findPlanReviewByReportFillter(plan);
List<PlanReviewImage> planReviewImageList = planReviewImageRepository.findAllByPlanReviewAndDeletedAtIsNull(planReview);
for(PlanReviewImage planReviewImage : planReviewImageList){
list.add(planReviewImage.getImageUrl());
Expand Down

0 comments on commit b4f75fa

Please sign in to comment.