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

release: 0.1.3 #77

Merged
merged 3 commits into from
Oct 4, 2024
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 @@ -5,6 +5,7 @@
import java.util.List;
import lombok.Getter;
import org.chzz.market.domain.auction.type.AuctionStatus;
import org.chzz.market.domain.product.entity.Product.Category;

@Getter
public class AuctionDetailsResponse {
Expand All @@ -13,6 +14,7 @@ public class AuctionDetailsResponse {
private final String productName;
private final String description;
private final Integer minPrice;
private final Category category;
private final Long timeRemaining;
private final AuctionStatus status;
private final Boolean isSeller;
Expand All @@ -25,7 +27,7 @@ public class AuctionDetailsResponse {

@QueryProjection
public AuctionDetailsResponse(Long productId, String sellerNickname, String productName, String description,
Integer minPrice, Long timeRemaining, AuctionStatus status,
Integer minPrice, Category category, Long timeRemaining, AuctionStatus status,
Boolean isSeller,
Long participantCount, Boolean isParticipated, Long bidId, Long bidAmount,
int remainingBidCount) {
Expand All @@ -34,6 +36,7 @@ public AuctionDetailsResponse(Long productId, String sellerNickname, String prod
this.productName = productName;
this.description = description;
this.minPrice = minPrice;
this.category = category;
this.timeRemaining = timeRemaining;
this.status = status;
this.isSeller = isSeller;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ public Optional<AuctionDetailsResponse> findAuctionDetailsById(Long auctionId, L
product.name,
product.description,
product.minPrice,
product.category,
timeRemaining().longValue(),
auction.status,
userIdEq(userId),
Expand Down
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 @@ -13,7 +13,7 @@
@AllArgsConstructor
public class UpdateProductRequest {
@Size(min = 2, message = "제목은 최소 2글자 이상이어야 합니다")
private String name;
private String productName;

@Size(max = 1000, message = "상품 설명은 최대 1000자까지 가능합니다")
private String description;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.chzz.market.common.validation.annotation.ThousandMultiple;
import org.chzz.market.domain.base.entity.BaseTimeEntity;
import org.chzz.market.domain.image.entity.Image;
import org.chzz.market.domain.like.entity.Like;
Expand Down Expand Up @@ -103,7 +102,7 @@ public void removeLike(Like like) {


public void update(UpdateProductRequest modifiedProduct) {
this.name = modifiedProduct.getName();
this.name = modifiedProduct.getProductName();
this.description = modifiedProduct.getDescription();
this.category = modifiedProduct.getCategory();
this.minPrice = modifiedProduct.getMinPrice();
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 Expand Up @@ -135,8 +136,9 @@ public Page<ProductResponse> findProductsByNickname(String nickname, Pageable pa
public Page<ProductResponse> findProductsByUserId(Long userId, Pageable pageable) {
JPAQuery<?> baseQuery = jpaQueryFactory.from(product)
.join(product.user, user)
.join(auction.product, product)
.on(user.id.eq(product.id));
.leftJoin(auction).on(auction.product.eq(product))
.leftJoin(like).on(like.product.eq(product).and(like.user.id.eq(userId)))
.where(auction.isNull().and(user.id.eq(userId)));

return getProductResponses(pageable, baseQuery);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
public record UserProfileResponse(
String nickname,
String bio,
String link,
ParticipationCountsResponse participantCount,
Long preRegisterCount,
Long registeredAuctionCount
Expand All @@ -16,6 +17,7 @@ public static UserProfileResponse of(User user,
return new UserProfileResponse(
user.getNickname(),
user.getBio(),
user.getLink(),
counts,
preRegisterCount,
registeredAuctionCount
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ public void testGetAuctionDetails_ExistingAuction_NoException() {
Long existingAuctionId = 1L;
Long userId = 1L;
AuctionDetailsResponse auctionDetails = new AuctionDetailsResponse(1L, "닉네임2", "제품1", null, 1000,
123L, PROCEEDING, false, 0L, false, null, 0L, 0);
ELECTRONICS, 123L, PROCEEDING, false, 0L, false, null, 0L, 0);

// when
when(auctionRepository.findAuctionDetailsById(anyLong(), anyLong())).thenReturn(
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
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ void setUp() {
.build();

updateRequest = UpdateProductRequest.builder()
.name("수정된 상품")
.productName("수정된 상품")
.description("수정된 설명")
.category(HOME_APPLIANCES)
.minPrice(20000)
Expand Down Expand Up @@ -204,7 +204,7 @@ void updateProduct_WithoutImages() {
void updateProduct_InvalidUser() {
// given
UpdateProductRequest invalidUserRequest = UpdateProductRequest.builder()
.name("수정된 상품")
.productName("수정된 상품")
.description("수정된 설명")
.category(HOME_APPLIANCES)
.minPrice(20000)
Expand All @@ -221,7 +221,7 @@ void updateProduct_InvalidUser() {
void updateProduct_InvalidOwner() {
// given
UpdateProductRequest invalidUserRequest = UpdateProductRequest.builder()
.name("수정된 상품")
.productName("수정된 상품")
.description("수정된 설명")
.category(HOME_APPLIANCES)
.minPrice(20000)
Expand Down
Loading