Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

리뷰 이미지 조회 로직 수정 #193

Merged
merged 2 commits into from
Nov 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@
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.util.List;

public interface ReviewJPARepository extends JpaRepository<Review, Long> {
@Query("select r from Review r join fetch r.match m join fetch m.couple c join fetch m.planner where c.id = :coupleId")
List<Review> findAllByMatchCoupleId(@Param("coupleId")Long coupleId);
Page<Review> findAllByMatchPlannerId(Long plannerId, Pageable pageable);

@Query("select r from Review r join fetch r.match m join fetch m.planner p join fetch m.couple where p.id = :plannerId")
Page<Review> findAllByMatchPlannerId(@Param("plannerId")Long plannerId, Pageable pageable);

List<Review> findAllByMatchPlanner(Planner planner);
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,21 @@ public void addReview(User user, Long chatId, ReviewRequest.AddDTO request) {
public ReviewResponse.FindAllByPlannerDTO findReviewsByPlanner(int page, Long plannerId) {
Pageable pageable = PageRequest.of(page, PAGE_SIZE);
Page<Review> pageContent = reviewJPARepository.findAllByMatchPlannerId(plannerId, pageable);
System.out.println("1번!");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

println 다 지워주세요!

List<Review> reviews = pageContent.getContent();
List<ReviewImageItem> reviewImageItems = reviewImageItemJPARepository.findAllByReviewMatchPlannerId(plannerId);

System.out.println("2번!");
List<Long> reviewIds = reviews.stream().map(Review::getId).toList();
System.out.println("3번!");
List<ReviewImageItem> reviewImageItems = reviewImageItemJPARepository.findAllByReviewIds(reviewIds);
System.out.println("4번!");
return reviewDTOConverter.getFindAllByPlannerDTO(reviews, reviewImageItems);
}

public ReviewResponse.FindAllByCoupleDTO findReviewsByCouple(User user) {

List<Review> reviews = reviewJPARepository.findAllByMatchCoupleId(user.getId());
List<ReviewImageItem> reviewImageItems = reviewImageItemJPARepository.findAllByReviewMatchCoupleId(user.getId());

List<Long> reviewIds = reviews.stream().map(Review::getId).toList();
List<ReviewImageItem> reviewImageItems = reviewImageItemJPARepository.findAllByReviewIds(reviewIds);
return reviewDTOConverter.getFindAllByCoupleDTO(reviews, reviewImageItems);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@
public interface ReviewImageItemJPARepository extends JpaRepository<ReviewImageItem, Long> {

@Modifying
@Query("delete from ReviewImageItem r where r.review.id = :reviewId")
@Query("delete from ReviewImageItem i where i.review.id = :reviewId")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 부분 다른 코드랑 일관성이 안 맞는 것 같아요 r로 변경 부탁드립니다!

void deleteAllByReviewId(@Param("reviewId") Long reviewId);

@Query("select r from ReviewImageItem r where r.review.match.planner.id = :plannerId")
List<ReviewImageItem> findAllByReviewMatchPlannerId(@Param("plannerId") Long plannerId);
@Query("select i from ReviewImageItem i join fetch i.review r where r.id in :reviewIds")
List<ReviewImageItem> findAllByReviewIds(@Param("reviewIds") List<Long> reviewIds);

@Query("select r from ReviewImageItem r where r.review.match.couple.id = :coupleId")
List<ReviewImageItem> findAllByReviewMatchCoupleId(@Param("coupleId") Long coupleId);

@Query("select r.image from ReviewImageItem r where r.review.id = :reviewId")
@Query("select i.image from ReviewImageItem i where i.review.id = :reviewId")
List<String> findByReviewId(@Param("reviewId") Long reviewId);
}
Loading
Loading