Skip to content
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 @@ -16,27 +16,22 @@
@AllArgsConstructor
@Builder
public class ReviewImage {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "image_id")
private Long imageId;

@Column(name = "review_id", nullable = false)
private Long reviewId;

@Column(name = "image_url", nullable = false, length = 500)
private String imageUrl;

@Column(name = "image_order")
private Integer imageOrder;

@CreationTimestamp
@Column(name = "created_at", nullable = false, updatable = false)
private LocalDateTime createdAt;

// 연관관계 편의 메서드
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "review_id", insertable = false, updatable = false)
private Review review;
}
Original file line number Diff line number Diff line change
@@ -1,47 +1,57 @@
package com.cMall.feedShop.review.domain.repository;

import com.cMall.feedShop.review.domain.entity.ReviewImage;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

/**
* 리뷰 이미지 도메인 Repository 인터페이스
* JpaRepository를 상속하여 기본 CRUD 기능 제공
*/
public interface ReviewImageRepository {
@Repository
public interface ReviewImageRepository extends JpaRepository<ReviewImage, Long> {

/**
* 이미지 저장
* 이미지 저장 (JpaRepository에서 상속)
*/
ReviewImage save(ReviewImage reviewImage);
// save() 메서드는 JpaRepository에서 제공

/**
* ID로 이미지 조회
* ID로 이미지 조회 (JpaRepository에서 상속)
*/
Optional<ReviewImage> findById(Long imageId);
// findById() 메서드는 JpaRepository에서 제공

/**
* 리뷰별 이미지 목록 조회 (순서대로)
*/
List<ReviewImage> findByReviewIdOrderByImageOrder(Long reviewId);
@Query("SELECT ri FROM ReviewImage ri WHERE ri.reviewId = :reviewId ORDER BY ri.imageOrder ASC")
List<ReviewImage> findByReviewIdOrderByImageOrder(@Param("reviewId") Long reviewId);

/**
* 리뷰별 이미지 개수 조회
*/
Long countByReviewId(Long reviewId);
@Query("SELECT COUNT(ri) FROM ReviewImage ri WHERE ri.reviewId = :reviewId")
Long countByReviewId(@Param("reviewId") Long reviewId);

/**
* 이미지 삭제
* 이미지 삭제 (JpaRepository에서 상속)
*/
void deleteById(Long imageId);
// deleteById() 메서드는 JpaRepository에서 제공

/**
* 리뷰별 모든 이미지 삭제
*/
void deleteByReviewId(Long reviewId);
@Query("DELETE FROM ReviewImage ri WHERE ri.reviewId = :reviewId")
void deleteByReviewId(@Param("reviewId") Long reviewId);

/**
* 이미지 소유권 확인
* 이미지 소유권 확인 - 수정된 쿼리
*/
boolean existsByIdAndReviewUserId(Long imageId, Long userId);
@Query("SELECT COUNT(ri) > 0 FROM ReviewImage ri JOIN Review r ON ri.reviewId = r.reviewId WHERE ri.imageId = :imageId AND r.userId = :userId")
boolean existsByIdAndReviewUserId(@Param("imageId") Long imageId, @Param("userId") Long userId);
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.cMall.feedShop.review.domain.entity.Cushion;
import com.cMall.feedShop.review.domain.entity.Stability;
import com.cMall.feedShop.review.domain.repository.ReviewRepository;
import com.cMall.feedShop.review.domain.repository.ReviewImageRepository; // 추가
import com.cMall.feedShop.review.application.dto.request.ReviewCreateRequest;
import com.cMall.feedShop.review.application.dto.request.ReviewUpdateRequest;
import com.cMall.feedShop.review.application.dto.response.ReviewCreateResponse;
Expand All @@ -23,13 +24,17 @@
import static org.junit.jupiter.api.Assertions.*;
import java.util.Optional;
import java.util.List;
import java.util.ArrayList;

@ExtendWith(MockitoExtension.class)
public class ReviewServiceTest {

@Mock
private ReviewRepository reviewRepository;

@Mock
private ReviewImageRepository reviewImageRepository; // Mock 추가

@InjectMocks
private ReviewService reviewService;

Expand Down Expand Up @@ -66,6 +71,7 @@ void setUp() {
@DisplayName("Given 5-level shoe characteristics_When create review_Then return detailed response")
void given5LevelShoeCharacteristics_whenCreateReview_thenReturnDetailedResponse() {
// given
when(reviewRepository.existsByUserIdAndProductIdAndStatusActive(1L, 1L)).thenReturn(false);
when(reviewRepository.save(any(Review.class))).thenReturn(review);

// when
Expand Down Expand Up @@ -106,6 +112,7 @@ void givenExtremeNegativeCharacteristics_whenCreateReview_thenHandleAllExtremeVa
.status(ReviewStatus.ACTIVE)
.build();

when(reviewRepository.existsByUserIdAndProductIdAndStatusActive(1L, 2L)).thenReturn(false);
when(reviewRepository.save(any(Review.class))).thenReturn(extremeReview);

// when
Expand Down Expand Up @@ -141,6 +148,9 @@ void givenVeryBigSizeFilter_whenGetFilteredReviews_thenReturnMatchingReviews() {
when(reviewRepository.findByProductIdAndSizeFitAndStatus(productId, targetSizeFit, ReviewStatus.ACTIVE))
.thenReturn(reviews);

// ReviewImageRepository Mock 설정 추가
when(reviewImageRepository.findByReviewIdOrderByImageOrder(any())).thenReturn(new ArrayList<>());

// when
List<ReviewDetailResponse> responses = reviewService.getReviewsBySizeFit(productId, targetSizeFit);

Expand Down Expand Up @@ -170,6 +180,9 @@ void givenVerySoftCushioningFilter_whenGetReviews_thenReturnUltraComfortReviews(
when(reviewRepository.findByProductIdAndCushioningAndStatus(productId, targetCushioning, ReviewStatus.ACTIVE))
.thenReturn(reviews);

// ReviewImageRepository Mock 설정 추가
when(reviewImageRepository.findByReviewIdOrderByImageOrder(any())).thenReturn(new ArrayList<>());

// when
List<ReviewDetailResponse> responses = reviewService.getReviewsByCushioning(productId, targetCushioning);

Expand All @@ -187,6 +200,9 @@ void givenExistingReviewId_whenGetReviewDetail_thenReturn5LevelCharacteristics()
Long reviewId = 1L;
when(reviewRepository.findById(reviewId)).thenReturn(Optional.of(review));

// ReviewImageRepository Mock 설정 추가
when(reviewImageRepository.findByReviewIdOrderByImageOrder(reviewId)).thenReturn(new ArrayList<>());

// when
ReviewDetailResponse response = reviewService.getReviewDetail(reviewId);

Expand Down
Loading
Loading