Skip to content

Commit

Permalink
feat: 경매 종료 임시 테스트 API 작성
Browse files Browse the repository at this point in the history
CHZZ-118
  • Loading branch information
junest66 committed Oct 2, 2024
1 parent ef9fbe7 commit 1f6dac1
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -42,6 +43,7 @@
public class AuctionController {
private final AuctionService auctionService;
private final BidService bidService;
private final TestService testService;
private final AuctionRegistrationServiceFactory registrationServiceFactory;

/**
Expand Down Expand Up @@ -166,4 +168,16 @@ public ResponseEntity<StartAuctionResponse> 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();
}
}
62 changes: 62 additions & 0 deletions src/main/java/org/chzz/market/domain/auction/type/TestService.java
Original file line number Diff line number Diff line change
@@ -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());
}
}

0 comments on commit 1f6dac1

Please sign in to comment.