Skip to content

Commit

Permalink
fix : planReview report fillter
Browse files Browse the repository at this point in the history
  • Loading branch information
sycuuui committed Sep 11, 2024
1 parent 8d32619 commit 9593325
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import jakarta.validation.constraints.Null;
import lombok.Builder;
import software.amazon.awssdk.services.s3.endpoints.internal.Value;

import java.util.List;

Expand All @@ -19,11 +20,12 @@ public record PlanReviewRes(
boolean hasReview,
@Null
List<String> imageList,
String profileUrl
String profileUrl,
Boolean isReport
) {
public static PlanReviewRes of(Long reviewId,
String content,
Float grade,boolean isWriter,boolean hasReview,List<String> imageList,String profileUrl){
Float grade,boolean isWriter,boolean hasReview,List<String> imageList,String profileUrl,Boolean isReport){
return PlanReviewRes.builder()
.reviewId(reviewId)
.content(content)
Expand All @@ -32,6 +34,7 @@ public static PlanReviewRes of(Long reviewId,
.hasReview(hasReview)
.imageList(imageList)
.profileUrl(profileUrl)
.isReport(isReport)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@

public interface PlanReviewRepository extends JpaRepository<PlanReview,Long> {
boolean existsAllByPlan(Plan plan);
@Query("SELECT COUNT(pr) > 0 " + "FROM PlanReview pr " + "WHERE (pr.report IS NULL OR pr.report = false)")
boolean existsAllByPlanAndReportFillter(Plan plan);
PlanReview findPlanReviewByPlan(Plan plan);

@Query("SELECT pr FROM PlanReview pr WHERE pr.plan = :plan AND (pr.report IS NULL OR pr.report = false)")
PlanReview findPlanReviewByReportFillter(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,7 +218,7 @@ public PlanReviewRes findPlanReview(Member member,long planId){
if(plan == null){
throw new ApplicationException(ErrorCode.NOT_FOUND_EXCEPTION);
}
PlanReview planReview = planReviewRepository.findPlanReviewByPlan(plan);
PlanReview planReview = planReviewRepository.findPlanReviewByReportFillter(plan);
//Buisness
boolean isWriter;
if (member ==null){
Expand All @@ -229,9 +229,9 @@ public PlanReviewRes findPlanReview(Member member,long planId){
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);
return PlanReviewRes.of(null,null,null,isWriter,false,imageList,profileUrl,planReview.getReport());
}else {
return PlanReviewRes.of(planReview.getPlanReviewId(),planReview.getContent(),planReview.getGrade(),isWriter,true,imageList,profileUrl);
return PlanReviewRes.of(planReview.getPlanReviewId(),planReview.getContent(),planReview.getGrade(),isWriter,true,imageList,profileUrl,planReview.getReport());
}

}
Expand Down Expand Up @@ -311,7 +311,7 @@ public List<MyPlanRes> findMyPlans(Member member) {
String remainDate = null;
Boolean hasReview = null;
if (LocalDate.now().isAfter(plan.getEndDate())){
hasReview = planReviewRepository.existsAllByPlan(plan);
hasReview = planReviewRepository.existsAllByPlanAndReportFillter(plan);
}else 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())){
Expand Down Expand Up @@ -344,7 +344,7 @@ public PlanPageRes findIsCompelete(Member member, Pageable page, Boolean compele
if(compelete){
planPage = planRepository.findAllByMemberAndEndDateBeforeAndDeletedAtIsNull(member,LocalDate.now(),pageable);
planResList = planPage.getContent().stream()
.map(plan -> PlanRes.of(plan,getPlaceFirstImage(plan),null,planReviewRepository.existsAllByPlan(plan)))
.map(plan -> PlanRes.of(plan,getPlaceFirstImage(plan),null,planReviewRepository.existsAllByPlanAndReportFillter(plan)))
.collect(Collectors.toList());
}else {
planPage = planRepository.findAllByMemberAndEndDateGreaterThanEqualAndDeletedAtIsNull(member,LocalDate.now(),pageable);
Expand Down Expand Up @@ -415,7 +415,7 @@ public List<String> getPlaceImageList(Plan plan){

public List<String> getReviewImageList(Plan plan){
List<String> list = new ArrayList<>();
PlanReview planReview = planReviewRepository.findPlanReviewByPlan(plan);
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 9593325

Please sign in to comment.