From 4eb7adf03f8ad5a77d4527b76a281ba747a52459 Mon Sep 17 00:00:00 2001 From: yurim0628 Date: Wed, 24 Jan 2024 23:49:41 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EC=96=91=EB=8F=84=EB=8C=80=EA=B8=B0=20?= =?UTF-8?q?=EC=A4=91=EC=9D=B8=20=EC=83=81=ED=92=88=EC=9D=98=20=EC=A3=BC?= =?UTF-8?q?=EB=AC=B8=20=EC=A0=95=EB=B3=B4=20=EA=B0=80=EC=A0=B8=EC=98=A4?= =?UTF-8?q?=EB=8A=94=20=EB=A1=9C=EC=A7=81=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../goldenticket/common/response/ErrorCode.java | 1 + .../domain/payment/repository/OrderRepository.java | 4 ---- .../domain/payment/service/PaymentService.java | 8 ++------ .../product/service/ProductOrderService.java | 14 +++++++++----- 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/main/java/site/goldenticket/common/response/ErrorCode.java b/src/main/java/site/goldenticket/common/response/ErrorCode.java index a41f349c..2c721f42 100644 --- a/src/main/java/site/goldenticket/common/response/ErrorCode.java +++ b/src/main/java/site/goldenticket/common/response/ErrorCode.java @@ -40,6 +40,7 @@ public enum ErrorCode { NEGO_COMPLETED(BAD_REQUEST, "다른 유저가 네고를 성공해 진행할수 없습니다."), NEGO_COUNT_OVER(BAD_REQUEST,"네고를 3회이상 제안하실수 없습니다."), NO_TRANSFER_PENDING_NEGO(BAD_REQUEST, "양도 대기중인 네고가 없습니다."), + NO_COMPLETED_TRANSFER_ORDER(BAD_REQUEST, "양도 완료된 상품의 주문 정보가 없습니다."), NO_REGISTERED_ACCOUNT(NOT_FOUND, "등록된 계좌가 없습니다"), TRANSFER_PENDING_NEGO(BAD_REQUEST,"양도 대기 중인 상품이 있어 결제할 수 없습니다."), CANNOT_NEGOTIATE_SELF_PRODUCT(BAD_REQUEST, "자신의 상품에는 네고를 할 수 없습니다."), diff --git a/src/main/java/site/goldenticket/domain/payment/repository/OrderRepository.java b/src/main/java/site/goldenticket/domain/payment/repository/OrderRepository.java index 1dc3a296..81277148 100644 --- a/src/main/java/site/goldenticket/domain/payment/repository/OrderRepository.java +++ b/src/main/java/site/goldenticket/domain/payment/repository/OrderRepository.java @@ -11,10 +11,6 @@ public interface OrderRepository extends JpaRepository { Optional findByProductIdAndStatus(Long productId, OrderStatus orderStatus); - List findByStatusAndProductId(OrderStatus status, Long productId); - - Order findByProductId(Long productId); - List findByUserIdAndStatus(Long userId, OrderStatus status); List findByStatus(OrderStatus orderStatus); diff --git a/src/main/java/site/goldenticket/domain/payment/service/PaymentService.java b/src/main/java/site/goldenticket/domain/payment/service/PaymentService.java index 1de587f0..51a0c106 100644 --- a/src/main/java/site/goldenticket/domain/payment/service/PaymentService.java +++ b/src/main/java/site/goldenticket/domain/payment/service/PaymentService.java @@ -150,12 +150,8 @@ public PaymentResponse savePayment(PaymentRequest request, PrincipalDetails prin return PaymentResponse.success(chatRoomId); } - public List findByStatusAndProductId(OrderStatus orderStatus, Long productId) { - return orderRepository.findByStatusAndProductId(orderStatus, productId); - } - - public Order findByProductId(Long productId) { - return orderRepository.findByProductId(productId); + public Optional findByProductIdAndStatus(Long productId, OrderStatus orderStatus) { + return orderRepository.findByProductIdAndStatus(productId, orderStatus); } public void cancelPayment(String impUid) { diff --git a/src/main/java/site/goldenticket/domain/product/service/ProductOrderService.java b/src/main/java/site/goldenticket/domain/product/service/ProductOrderService.java index 194c3bd5..3d29faf0 100644 --- a/src/main/java/site/goldenticket/domain/product/service/ProductOrderService.java +++ b/src/main/java/site/goldenticket/domain/product/service/ProductOrderService.java @@ -30,6 +30,7 @@ import java.util.*; import java.util.stream.Collectors; +import static site.goldenticket.common.constants.OrderStatus.COMPLETED_TRANSFER; import static site.goldenticket.common.redis.constants.RedisConstants.AUTOCOMPLETE_KEY; @Slf4j @@ -80,9 +81,11 @@ public List getProgressProducts(Long userId) { List progressChatResponseList = new ArrayList<>(); // 2.1 주문 - List orderList = getOrdersForProduct(productId); + Optional optionalOrder = getOrdersForProduct(productId); + + if (!optionalOrder.isPresent()) { + Order order = optionalOrder.get(); - for (Order order : orderList) { ProgressProductStatus progressProductStatus = ProgressProductStatus.valueOf(String.valueOf(order.getStatus())); progressProductStatusSet.add(progressProductStatus); @@ -167,7 +170,8 @@ public List getAllCompletedProducts(Long userId public ProductCompletedSoldOutResponse getSoldOutCaseProductDetails(Long productId) { Product product = productService.findByProductStatusAndProductId(ProductStatus.SOLD_OUT, productId); - Order order = paymentService.findByProductId(productId); + Order order = paymentService.findByProductIdAndStatus(productId, COMPLETED_TRANSFER) + .orElseThrow(() -> new CustomException(ErrorCode.NO_COMPLETED_TRANSFER_ORDER)); Long userId = order.getUserId(); User user = userService.findById(userId); @@ -192,8 +196,8 @@ public Long deleteCompletedProduct(Long productId) { return productId; } - public List getOrdersForProduct(Long productId) { - return paymentService.findByStatusAndProductId(OrderStatus.WAITING_TRANSFER, productId); + public Optional getOrdersForProduct(Long productId) { + return paymentService.findByProductIdAndStatus(productId, OrderStatus.WAITING_TRANSFER); } private List getNegotiationsForProduct(Product product) {