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

fix: 정식 경매 제품을 사전 경매 조회 시 조회되는 버그 수정 #88

Merged
merged 8 commits into from
Oct 15, 2024
2 changes: 1 addition & 1 deletion .github/workflows/pr-title-and-branch-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:

jobs:
validate-title-and-branch:
if: ${{ !(startsWith(github.head_ref, 'release/') && github.base_ref == 'develop') && github.actor != 'jira[bot]' }} # release/* -> develop일 때는 실행하지 않음, 또한 Jira Bot이 실행하는 경우 무시
if: ${{ !(startsWith(github.head_ref, 'release/') && github.base_ref == 'develop')}} # release/* -> develop일 때는 실행하지 않음
runs-on: ubuntu-latest
steps:
- name: Check out code
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
public enum ProductErrorCode implements ErrorCode {
PRODUCT_REGISTER_FAILED(HttpStatus.BAD_REQUEST, "상품 등록에 실패했습니다."),
INVALID_PRODUCT_STATE(HttpStatus.BAD_REQUEST, "상품 상태가 유효하지 않습니다."),
ALREADY_IN_AUCTION(HttpStatus.BAD_REQUEST, "이미 경매가 진행 중인 상품입니다."),
ALREADY_IN_AUCTION(HttpStatus.BAD_REQUEST, "이미 정식경매로 등록된 상품입니다."),
PRODUCT_ALREADY_AUCTIONED(HttpStatus.BAD_REQUEST, "상품이 이미 경매로 등록되어 삭제할 수 없습니다."),
FORBIDDEN_PRODUCT_ACCESS(HttpStatus.FORBIDDEN, "상품에 접근할 수 없습니다."),
PRODUCT_NOT_FOUND(HttpStatus.NOT_FOUND, "상품을 찾을 수 없습니다."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,9 @@ public Optional<ProductDetailsResponse> findProductDetailsById(Long productId, L
product.category
))
.from(product)
.leftJoin(auction).on(auction.product.id.eq(product.id))
.join(product.user, user)
.where(product.id.eq(productId))
.where(auction.id.isNull().and(product.id.eq(productId)))
.fetchOne());

return result.map(response -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ public Page<ProductResponse> getProductListByCategory(Category category, Long us
* 상품 상세 정보 조회
*/
public ProductDetailsResponse getProductDetails(Long productId, Long userId) {
if (auctionRepository.existsByProductId(productId)) {
throw new ProductException(ALREADY_IN_AUCTION);
}
return productRepository.findProductDetailsById(productId, userId)
.orElseThrow(() -> new ProductException(PRODUCT_NOT_FOUND));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import java.util.NoSuchElementException;
import java.util.Optional;
import org.chzz.market.common.DatabaseTest;
import org.chzz.market.domain.auction.entity.Auction;
import org.chzz.market.domain.auction.repository.AuctionRepository;
import org.chzz.market.domain.image.entity.Image;
import org.chzz.market.domain.image.repository.ImageRepository;
import org.chzz.market.domain.like.entity.Like;
Expand Down Expand Up @@ -55,17 +57,22 @@ class ProductRepositoryCustomImplTest {
@Autowired
LikeRepository likeRepository;

@Autowired
AuctionRepository auctionRepository;

@PersistenceContext
EntityManager entityManager;

private static User user1, user2, user3;
private static Product product1, product2, product3, product4, product5;
private static Image image1, image2, image3, image4, image5;
private static Product product1, product2, product3, product4, product5, product6;
private static Image image1, image2, image3, image4, image5, image6;
private static Like like1, like2, like3;
private static Auction auction1;

@BeforeAll
static void setUpOnce(@Autowired UserRepository userRepository,
@Autowired ProductRepository productRepository,
@Autowired AuctionRepository auctionRepository,
@Autowired ImageRepository imageRepository,
@Autowired LikeRepository likeRepository) {
user1 = User.builder().providerId("1234").nickname("닉네임1").email("[email protected]").build();
Expand All @@ -83,19 +90,24 @@ static void setUpOnce(@Autowired UserRepository userRepository,
ReflectionTestUtils.setField(product4, "createdAt", LocalDateTime.now().minusDays(2));
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));
product6 = Product.builder().user(user3).name("사전등록상품6").category(FASHION_AND_CLOTHING).minPrice(50000).build();
productRepository.saveAll(List.of(product1, product2, product3, product4, product5, product6));

image1 = Image.builder().product(product1).cdnPath("path/to/image1.jpg").sequence(1).build();
image2 = Image.builder().product(product2).cdnPath("path/to/image2.jpg").sequence(1).build();
image3 = Image.builder().product(product3).cdnPath("path/to/image3.jpg").sequence(1).build();
image4 = Image.builder().product(product4).cdnPath("path/to/image4.jpg").sequence(1).build();
image5 = Image.builder().product(product5).cdnPath("path/to/image5.jpg").sequence(1).build();
imageRepository.saveAll(List.of(image1, image2, image3, image4, image5));
image6 = Image.builder().product(product6).cdnPath("path/to/image6.jpg").sequence(1).build();
imageRepository.saveAll(List.of(image1, image2, image3, image4, image5, image6));

like1 = Like.builder().user(user2).product(product1).build();
like2 = Like.builder().user(user3).product(product1).build();
like3 = Like.builder().user(user1).product(product3).build();
likeRepository.saveAll(List.of(like1, like2, like3));

auction1 = Auction.toEntity(product6);
auctionRepository.save(auction1);
}

@AfterEach
Expand All @@ -104,6 +116,7 @@ void tearDown() {
imageRepository.deleteAll();
productRepository.deleteAll();
userRepository.deleteAll();
auctionRepository.deleteAll();
}

@Nested
Expand Down Expand Up @@ -308,6 +321,14 @@ void findProductDetailsWithAnonymousUser() {
});
}

@Test
@DisplayName("8. 정식 경매 상품의 사전 경매 조회 불가")
void findPreAuctionDetailsForRegularAuctionProduct() {
Optional<ProductDetailsResponse> result = productRepository.findProductDetailsById(
product6.getId(), null);
assertThat(result).isEmpty();
}

}

@Nested
Expand Down
Loading