-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix(#128): 불필요한 조회 제거, 사전예약 캐시 데이터에 Product 아이디 추가 * feat(#128): 사전예약정보 변경시 캐싱 되어있는 정보 삭제, 오픈되어있는 사전예약정보만 저장할 수 있도록 진행
- Loading branch information
Showing
5 changed files
with
26 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 3 additions & 20 deletions
23
...t/server/src/main/java/com/sparta/product/application/preorder/PreOrderFacadeService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,24 @@ | ||
package com.sparta.product.application.preorder; | ||
|
||
import com.sparta.common.domain.entity.KafkaTopicConstant; | ||
import com.sparta.product.domain.model.PreOrder; | ||
import com.sparta.product.domain.model.PreOrderState; | ||
import com.sparta.product.infrastructure.messaging.PreOrderProducer; | ||
import com.sparta.product.presentation.exception.ProductErrorCode; | ||
import com.sparta.product.presentation.exception.ProductServerException; | ||
import com.sparta.product.infrastructure.utils.PreOrderRedisDto; | ||
import dto.OrderCreateRequest; | ||
import java.time.LocalDateTime; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class PreOrderFacadeService { | ||
private final PreOrderService preOrderService; | ||
private final PreOrderProducer preOrderProducer; | ||
private final PreOrderLockService preOrderLockService; | ||
|
||
@Transactional | ||
public void preOrder(Long preOrderId, Long addressId, Long userId) { | ||
PreOrder preOrder = preOrderService.findPreOrderByPreOrderId(preOrderId); | ||
preOrderLockService.reservation(preOrderId, userId); | ||
OrderCreateRequest createRequest = | ||
PreOrderMapper.toDto(preOrder.getProductId().toString(), addressId); | ||
PreOrderRedisDto cachedData = preOrderLockService.reservation(preOrderId, userId); | ||
OrderCreateRequest createRequest = PreOrderMapper.toDto(cachedData.productId(), addressId); | ||
preOrderProducer.send( | ||
KafkaTopicConstant.PROCESS_PREORDER, Long.toString(userId), createRequest); | ||
} | ||
|
||
private void validatePreOrder(PreOrder preOrder) { | ||
if (preOrder.getState() != PreOrderState.OPEN_FOR_ORDER) | ||
throw new ProductServerException(ProductErrorCode.NOT_OPEN_FOR_PREORDER); | ||
|
||
LocalDateTime now = LocalDateTime.now(); | ||
if (now.isBefore(preOrder.getStartDateTime()) || now.isAfter(preOrder.getEndDateTime())) { | ||
throw new ProductServerException(ProductErrorCode.CLOSED_PREORDER); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters