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

[#33] 경매 활성화 및 종료 상태 변경 코드 추가 #34

Merged
merged 8 commits into from
Oct 18, 2024

Conversation

JIWON27
Copy link
Collaborator

@JIWON27 JIWON27 commented Sep 19, 2024

경매 활성화 및 종료 상태 변경 코드 추가

  • 상품 조회 시 요청 시간과 비교해서 경매 활성화 및 종료 상태 변경 코드 추가

@JIWON27 JIWON27 requested a review from f-lab-moony September 19, 2024 15:46
@JIWON27 JIWON27 self-assigned this Sep 19, 2024
@JIWON27 JIWON27 changed the title [#33] 경매 Redis 저장/삭제 기능 추가 [#33] 경매 활성화 및 종료 상태 변경 코드 추가 Sep 20, 2024
Copy link
Collaborator

@f-lab-moony f-lab-moony left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생 많으셨습니다 ~ 피드백 확인 부탁드려요!

@@ -44,7 +45,9 @@ public ProductResponse enroll(

@GetMapping("/{id}")
public ProductFindResponse findById(@PathVariable Long id) {
return productFacade.findById(id);
LocalDateTime request = LocalDateTime.now();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

request라는 이름이 좀 어색한 것 같아요 ~ requestTime 이나 좀 더 명시적으로 쓰일 이름으로 바꿔주면 좋을 것 같아요

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵 알겠습니다!

@@ -44,7 +45,9 @@ public ProductResponse enroll(

@GetMapping("/{id}")
public ProductFindResponse findById(@PathVariable Long id) {
return productFacade.findById(id);
LocalDateTime request = LocalDateTime.now();
ProductFindResponse productFindResponse = productFacade.findById(id, request);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이런건 인라인으로 리턴해도 되지 않을까요 ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵!!

@@ -69,4 +69,8 @@ public void updateProductInfo(String productName, String description, LocalDateT
this.startPrice = startPrice;
}

public void updateProductCondition(ProductCondition productCondition) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

엔티티 변경시에는 누가 변경했는지도 같이 받아서 바꿔주면 좋을 것 같아요!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아항 넵 추가하도록 하겠습니다

Product product = productRepository.findById(id)
.orElseThrow(() -> new NotFoundProductException(id));

if (requestTime.isAfter(product.getStartDate()) && requestTime.isBefore(product.getCloseDate())) {
product.updateProductCondition(ProductCondition.ACTIVE);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아 요렇게 쓰이는거군요 ? 이거 상태를 엔티티가 직접 가지고 있을 이유가 있을까요 ? 이러면 조회 요청이 트리거가 돼서 상태가 변경되는건데 상태를 가지는게 아니라 응답에만 포함되어도 될 것 같아요 ~ 추가로, 상태값 관리하는건 별도의 배치나 스케줄러가 있어야 하지 않을까 싶은데 어떻게 생각하실까요 ?

Copy link
Collaborator Author

@JIWON27 JIWON27 Oct 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

음 저도 상태쪽을 솔직히 requestTime을 받아서 필터링하는건 별로라고 생각하고있었는데 피드백 감사합니다!
저도 상태값 관리는 배치나 스케줄러를 사용해도 좋을 것 같습니다!

@JIWON27 JIWON27 linked an issue Oct 12, 2024 that may be closed by this pull request
Copy link
Collaborator

@f-lab-moony f-lab-moony left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생 많으셨습니다!
피드백 확인 부탁드려요 ~

public class ProductConditionUpdate implements ItemProcessor<Product, Product> {
// 상품의 상태를 갱신하는 로직
@Override
public Product process(Product product) throws Exception {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

요거 그냥 Writer에서 하고 Processor 빼도 될거같아요 ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵 수정하도록 하겠습니다!


@Component
public class ProductReader implements ItemReader<List<Product>> {
private static final int PAGE_SIZE = 500; // 한번에 읽을 데이터 개수 (청크 사이즈)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

요거 CHUNK_SIZE를 같이 사용하는게 어떨까요 ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아하 넵!!


@Override
public List<Product> read() throws
Exception,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

예외 목록이 약간 읽기 어렵게 줄바꿈이 된 것 같아요

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

요게 저두 불편한데,, 줄바꿈을 제가 바꿔두 save 하면 저런식으로 줄바꿈이 되더라구용,,,🥲

List<Product> products = productRepository.findAll(pageable).getContent();

if (products.isEmpty()) {
currentPage = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

요거는 혹시 무슨 의도인가요 ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

엇 이게 DB에서 더이상 읽어올게없으면 다시 처음부터 읽을 수 있도록 pageNo를 0으로 하는 코드였습니다!

UnexpectedInputException,
ParseException,
NonTransientResourceException {
Pageable pageable = PageRequest.of(currentPage, PAGE_SIZE);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

전체를 다 읽는거라 데이터가 많아지면 점점 느려질 것 같아요, more 방식으로 읽도록 변경하는게 어떨까요 ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아 그렇네요!! more 방식으로 수정하도록 하겠습니다!

Copy link

Copy link
Collaborator

@f-lab-moony f-lab-moony left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생 많으셨습니다 ~ 요거 머지 할게요!

@@ -17,26 +17,24 @@
@Configuration
@EnableBatchProcessing
public class BatchConfig {

public static final int CHUNK_SIZE = 500;
@Value("${ready.auction.spring.batch.chunkSize}")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

요거 근데 아마 잡마다 청크사이즈가 달라서 이렇게 퉁치긴 좀 어렵긴 할텐데 나중에 기회되면 바꿔보시죠 ~
저는 JobConfig가 최상단이라 거기 있는 애들 public static으로 같이 쓰고 있어요

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아하 넵 ! 저도 해보다가 애매하면 JobConfig에 사이즈를 두고 사용하도록 하겠습니다

@@ -21,6 +23,17 @@ public ProductConditionWriter(ProductRepository productRepository) {
@Override
public void write(Chunk<? extends Product> chunk) throws Exception {
List<? extends Product> products = chunk.getItems();
LocalDateTime now = LocalDateTime.now();
// 경매 상태 업데이트
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

요 주석들 굳이 없어도 읽는데 문제 없을 것 같아요 ~
주석은 최대한 일반적이지 않은 코드를 위한 히스토리 혹은 참고할 문서가 있는 경우에만 남겨주세요

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵 알겠습니다!

@f-lab-moony f-lab-moony merged commit 7afcf63 into main Oct 18, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🚨 경매 시작/종료 기능
2 participants