Skip to content

Commit

Permalink
refactor: fix register request (#74)
Browse files Browse the repository at this point in the history
* refactor: 요청 필드 추가

- 상품 카테고리 추가

CHZZ-122

* refactor: 상품 카테고리 조회

- 상품 상세정보 조회시 카테고리도 조회되도록 추가

CHZZ-122

* test: 상품 카테고리 테스트 수정

- 상품 상세정보 조회 변경에 따른 테스트 수정

CHZZ-122
  • Loading branch information
YeaChan05 authored Oct 4, 2024
1 parent e9891a2 commit 7cd1af1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import java.time.LocalDateTime;
import java.util.List;
import org.chzz.market.domain.product.entity.Product.Category;

/**
* 사전 등록 상품 상세 조회 DTO
Expand All @@ -20,12 +21,13 @@ public class ProductDetailsResponse {
private final Long likeCount;
private final Boolean isLiked;
private final Boolean isSeller;
private final Category category;
private List<String> imageUrls;

@QueryProjection
public ProductDetailsResponse(Long productId, String productName, String sellerNickname,
Integer minPrice, LocalDateTime createdAt, String description,
Long likeCount, Boolean isLiked, Boolean isSeller) {
Long likeCount, Boolean isLiked, Boolean isSeller, Category category) {
this.productId = productId;
this.productName = productName;
this.sellerNickname = sellerNickname;
Expand All @@ -35,6 +37,7 @@ public ProductDetailsResponse(Long productId, String productName, String sellerN
this.likeCount = likeCount;
this.isLiked = isLiked;
this.isSeller = isSeller;
this.category = category;
}

public void addImageList(List<String> imageUrls) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ public Optional<ProductDetailsResponse> findProductDetailsById(Long productId, L
product.description,
product.likes.size().longValue(),
isProductLikedByUser(userId),
nullSafeBuilder(() -> user.id.eq(userId))
nullSafeBuilder(() -> user.id.eq(userId)),
product.category
))
.from(product)
.join(product.user, user)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import static org.chzz.market.domain.product.entity.Product.Category.BOOKS_AND_MEDIA;
import static org.chzz.market.domain.product.entity.Product.Category.ELECTRONICS;
import static org.chzz.market.domain.product.entity.Product.Category.FASHION_AND_CLOTHING;
import static org.chzz.market.domain.product.entity.Product.builder;

import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
Expand Down Expand Up @@ -69,15 +68,15 @@ static void setUpOnce(@Autowired UserRepository userRepository,
user3 = User.builder().providerId("9012").nickname("닉네임3").email("[email protected]").build();
userRepository.saveAll(List.of(user1, user2, user3));

product1 = builder().user(user1).name("사전등록상품1").category(ELECTRONICS).minPrice(10000).build();
product1 = Product.builder().user(user1).name("사전등록상품1").category(ELECTRONICS).minPrice(10000).build();
ReflectionTestUtils.setField(product1, "createdAt", LocalDateTime.now().minusDays(5));
product2 = builder().user(user1).name("사전등록상품2").category(BOOKS_AND_MEDIA).minPrice(20000).build();
product2 = Product.builder().user(user1).name("사전등록상품2").category(BOOKS_AND_MEDIA).minPrice(20000).build();
ReflectionTestUtils.setField(product2, "createdAt", LocalDateTime.now().minusDays(4));
product3 = builder().user(user2).name("사전등록상품3").category(ELECTRONICS).minPrice(30000).build();
product3 = Product.builder().user(user2).name("사전등록상품3").category(ELECTRONICS).minPrice(30000).build();
ReflectionTestUtils.setField(product3, "createdAt", LocalDateTime.now().minusDays(3));
product4 = builder().user(user2).name("사전등록상품4").category(ELECTRONICS).minPrice(40000).build();
product4 = Product.builder().user(user2).name("사전등록상품4").category(ELECTRONICS).minPrice(40000).build();
ReflectionTestUtils.setField(product4, "createdAt", LocalDateTime.now().minusDays(2));
product5 = builder().user(user3).name("사전등록상품5").category(FASHION_AND_CLOTHING).minPrice(50000).build();
product5 = Product.builder().user(user3).name("사전등록상품5").category(FASHION_AND_CLOTHING).minPrice(50000).build();
ReflectionTestUtils.setField(product5, "createdAt", LocalDateTime.now().minusDays(1));
productRepository.saveAll(List.of(product1, product2, product3, product4, product5));

Expand Down Expand Up @@ -206,6 +205,7 @@ void findProductDetailsById() {
assertThat(result.get().getIsLiked()).isTrue(); // user2가 좋아요 한 상품
assertThat(result.get().getImageUrls()).contains("path/to/image1.jpg");
assertThat(result.get().getIsSeller()).isFalse();
assertThat(result.get().getCategory()).isEqualTo(ELECTRONICS);
}

@Test
Expand Down Expand Up @@ -234,7 +234,7 @@ void findProductDetailsWithoutLike() {
void findProductDetailsWithNoLikes() {
// given
Product productWithoutLikes = productRepository.save(
builder().user(user1).name("좋아요 없는 상품").category(ELECTRONICS).minPrice(10000).build()
Product.builder().user(user1).name("좋아요 없는 상품").category(ELECTRONICS).minPrice(10000).build()
);

// when
Expand Down Expand Up @@ -283,6 +283,7 @@ void findProductDetailsWithAnonymousUser() {
assertThat(result.get().getIsLiked()).isFalse(); // user2가 좋아요 한 상품
assertThat(result.get().getImageUrls()).contains("path/to/image1.jpg");
assertThat(result.get().getIsSeller()).isFalse();
assertThat(result.get().getCategory()).isEqualTo(ELECTRONICS);
}

}
Expand Down

0 comments on commit 7cd1af1

Please sign in to comment.