Skip to content

Commit

Permalink
Merge pull request #106 from Journey-Together/refactor/#101
Browse files Browse the repository at this point in the history
fix : report filter to planreview
  • Loading branch information
sycuuui authored Sep 11, 2024
2 parents 1bcc502 + 9593325 commit 4d8b365
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public record OpenPlanRes(
) {
public static OpenPlanRes of(Plan plan,String memberImageUrl,String imageUrl){
Period period = Period.between(plan.getStartDate(),plan.getEndDate());
String date = period.getDays()+"일일정";
String date = (period.getDays()+1)+"일일정";

return OpenPlanRes.builder()
.planId(plan.getPlanId())
Expand Down
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 4d8b365

Please sign in to comment.