Skip to content

Commit

Permalink
fix: 양도대기 중인 상품의 주문 정보 가져오는 로직 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
yurim0628 committed Jan 24, 2024
1 parent 35b0b78 commit 4eb7adf
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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, "자신의 상품에는 네고를 할 수 없습니다."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ public interface OrderRepository extends JpaRepository<Order, Long> {

Optional<Order> findByProductIdAndStatus(Long productId, OrderStatus orderStatus);

List<Order> findByStatusAndProductId(OrderStatus status, Long productId);

Order findByProductId(Long productId);

List<Order> findByUserIdAndStatus(Long userId, OrderStatus status);

List<Order> findByStatus(OrderStatus orderStatus);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,8 @@ public PaymentResponse savePayment(PaymentRequest request, PrincipalDetails prin
return PaymentResponse.success(chatRoomId);
}

public List<Order> findByStatusAndProductId(OrderStatus orderStatus, Long productId) {
return orderRepository.findByStatusAndProductId(orderStatus, productId);
}

public Order findByProductId(Long productId) {
return orderRepository.findByProductId(productId);
public Optional<Order> findByProductIdAndStatus(Long productId, OrderStatus orderStatus) {
return orderRepository.findByProductIdAndStatus(productId, orderStatus);
}

public void cancelPayment(String impUid) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -80,9 +81,11 @@ public List<ProductProgressHistoryResponse> getProgressProducts(Long userId) {
List<ProgressChatResponse> progressChatResponseList = new ArrayList<>();

// 2.1 주문
List<Order> orderList = getOrdersForProduct(productId);
Optional<Order> 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);

Expand Down Expand Up @@ -167,7 +170,8 @@ public List<ProductCompletedHistoryResponse> 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);
Expand All @@ -192,8 +196,8 @@ public Long deleteCompletedProduct(Long productId) {
return productId;
}

public List<Order> getOrdersForProduct(Long productId) {
return paymentService.findByStatusAndProductId(OrderStatus.WAITING_TRANSFER, productId);
public Optional<Order> getOrdersForProduct(Long productId) {
return paymentService.findByProductIdAndStatus(productId, OrderStatus.WAITING_TRANSFER);
}

private List<Nego> getNegotiationsForProduct(Product product) {
Expand Down

0 comments on commit 4eb7adf

Please sign in to comment.