diff --git a/src/main/java/org/chzz/market/domain/auction/controller/AuctionController.java b/src/main/java/org/chzz/market/domain/auction/controller/AuctionController.java index 53638a1b..c24fe303 100644 --- a/src/main/java/org/chzz/market/domain/auction/controller/AuctionController.java +++ b/src/main/java/org/chzz/market/domain/auction/controller/AuctionController.java @@ -17,6 +17,7 @@ import org.chzz.market.domain.auction.service.AuctionService; import org.chzz.market.domain.auction.service.register.AuctionRegistrationService; import org.chzz.market.domain.auction.type.AuctionViewType; +import org.chzz.market.domain.auction.type.TestService; import org.chzz.market.domain.bid.service.BidService; import org.chzz.market.domain.product.entity.Product.Category; import org.springframework.data.domain.Page; @@ -42,6 +43,7 @@ public class AuctionController { private final AuctionService auctionService; private final BidService bidService; + private final TestService testService; private final AuctionRegistrationServiceFactory registrationServiceFactory; /** @@ -166,4 +168,16 @@ public ResponseEntity startAuction(@LoginUser Long userId, log.info("경매 상품으로 성공적으로 전환되었습니다. 상품 ID: {}", response.productId()); return ResponseEntity.status(HttpStatus.CREATED).body(response); } + +// --------------------------------------------------------------------------------------- + + /** + * 경매 종료 테스트 API (삭제 필요) + */ + @PostMapping("/test") + public ResponseEntity testEndAuction(@LoginUser Long userId, + @RequestParam("minutes") int minutes) { + testService.test(userId, minutes); + return ResponseEntity.status(HttpStatus.CREATED).build(); + } } diff --git a/src/main/java/org/chzz/market/domain/auction/type/TestService.java b/src/main/java/org/chzz/market/domain/auction/type/TestService.java new file mode 100644 index 00000000..bfd25d00 --- /dev/null +++ b/src/main/java/org/chzz/market/domain/auction/type/TestService.java @@ -0,0 +1,62 @@ +package org.chzz.market.domain.auction.type; + +import jakarta.transaction.Transactional; +import java.time.LocalDateTime; +import java.util.List; +import java.util.Random; +import lombok.RequiredArgsConstructor; +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.product.entity.Product; +import org.chzz.market.domain.product.entity.Product.Category; +import org.chzz.market.domain.product.repository.ProductRepository; +import org.chzz.market.domain.user.entity.User; +import org.chzz.market.domain.user.repository.UserRepository; +import org.springframework.stereotype.Service; + +/** + * 경매종료 테스트 서비스 삭제필요 + */ +@Service +@RequiredArgsConstructor +public class TestService { + private final AuctionRepository auctionRepository; + private final ProductRepository productRepository; + private final ImageRepository imageRepository; + private final UserRepository userRepository; + + @Transactional + public void test(Long userId, int minutes) { + Random random = new Random(); + int randomIndex = random.nextInt(1000) + 1; // 1부터 1000까지 랜덤 숫자 생성 + int randomIndex1 = random.nextInt(1000) + 1; // 1부터 1000까지 랜덤 숫자 생성 + User user = userRepository.findById(userId).get(); + Product product = Product.builder() + .name("테스트" + randomIndex) + .description("test") + .category(Category.ELECTRONICS) + .user(user) + .minPrice(10000) + .build(); + productRepository.save(product); + + Image image1 = Image.builder() + .cdnPath("https://picsum.photos/id/" + randomIndex + "/200/200") + .product(product) + .build(); + Image image2 = Image.builder() + .cdnPath("https://picsum.photos/id/" + randomIndex1 + "/200/200") + .product(product) + .build(); + imageRepository.save(image1); + imageRepository.save(image2); + product.addImages(List.of(image1, image2)); + auctionRepository.save(Auction.builder() + .status(AuctionStatus.PROCEEDING) + .endDateTime(LocalDateTime.now().plusMinutes(minutes)) + .product(product) + .build()); + } +}