-
Notifications
You must be signed in to change notification settings - Fork 1
[Feature] 주문 조회 #204
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
Merged
willjsw
merged 13 commits into
develop
from
feature/#182-feature-customer-order-get-api
Oct 27, 2025
Merged
[Feature] 주문 조회 #204
Changes from 9 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
3c633af
feature #182 : 주문 상태 조회 API
hyeonji91 e89b137
feature #182 : 주문 상세 내역 조회
hyeonji91 dbb3e63
feature #182 : 주문 목록 조회 controller단
hyeonji91 a7da29b
feature #182 : 주문 리스트 조회 custom repository
hyeonji91 3379e15
feature #182 : 주문 목록 조회
hyeonji91 1b116e4
feature #182 : 주문 목록 조회
hyeonji91 839b5f6
style #182 : spotless적용
hyeonji91 bc28601
Merge remote-tracking branch 'origin/develop' into feature/#182-featu…
hyeonji91 d49790d
feature #182 : spotless적용
hyeonji91 70e1ab1
feature #182 : 주문상세조회, 주문상태조회 시 회원 검증 로직 추가
hyeonji91 ddc69bb
Merge branch 'develop' into feature/#182-feature-customer-order-get-api
hyeonji91 a3af258
style $204 : soptless적용
hyeonji91 a852233
fix #204 : merge 오류 해결
hyeonji91 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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
81 changes: 81 additions & 0 deletions
81
src/main/java/com/irum/come2us/domain/order/application/mapper/CustomerOrderMapper.java
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| package com.irum.come2us.domain.order.application.mapper; | ||
|
|
||
| import com.irum.come2us.domain.order.domain.entity.Order; | ||
| import com.irum.come2us.domain.order.domain.entity.OrderDetail; | ||
| import com.irum.come2us.domain.order.infrastructure.repository.dto.CustomerOrderDetailRow; | ||
| import com.irum.come2us.domain.order.infrastructure.repository.dto.CustomerOrderSummaryRow; | ||
| import com.irum.come2us.domain.order.presentation.dto.response.AddressResponse; | ||
| import com.irum.come2us.domain.order.presentation.dto.response.CustomerOrderListResponse; | ||
| import com.irum.come2us.domain.order.presentation.dto.response.OrderDetailResponse; | ||
| import com.irum.come2us.domain.refund.domain.entity.Refund; | ||
| import com.irum.come2us.domain.refund.domain.entity.enums.RefundStatus; | ||
| import java.util.List; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| @Component | ||
| public class CustomerOrderMapper { | ||
|
|
||
| public static OrderDetailResponse toOrderDetailResponse( | ||
| Order order, List<OrderDetail> orderDetailList, Refund refund) { | ||
| List<OrderDetailResponse.ProductResponse> pList = | ||
| orderDetailList.stream().map(CustomerOrderMapper::toProductResponse).toList(); | ||
|
|
||
| RefundStatus refundStatus; | ||
| if (refund == null) { | ||
| refundStatus = null; | ||
| } else { | ||
| refundStatus = refund.getRefundStatus(); | ||
| } | ||
|
|
||
| return OrderDetailResponse.builder() | ||
| .orderAt(order.getCreatedAt()) | ||
| .paymentStatus(order.getPayment().getPaymentStatus()) | ||
| .paymentMethod(order.getPayment().getPaymentMethod()) | ||
| .deliveryFee(order.getDeliveryFee()) | ||
| .discountAmount(order.getPayment().getTotalDiscountAmount()) | ||
| .totalProductPrice(order.getTotalPrice()) | ||
| .totalPaymentPrice(order.getPayment().getAmount()) | ||
| .orderStatusAll(order.getOrderStatusAll()) | ||
| .refundStatus(refundStatus) | ||
| .deliveryRequest(order.getDeliveryRequest()) | ||
| .address(AddressResponse.from(order.getDeliveryAddress().getAddress())) | ||
| .recipientContact(order.getDeliveryAddress().getRecipientContact()) | ||
| .recipientName(order.getDeliveryAddress().getRecipientName()) | ||
| .productResponseList(pList) | ||
| .build(); | ||
| } | ||
|
|
||
| private static OrderDetailResponse.ProductResponse toProductResponse(OrderDetail orderDetail) { | ||
|
|
||
| return OrderDetailResponse.ProductResponse.builder() | ||
| .receivedDate(orderDetail.getArrivedDate().toLocalDate()) | ||
| .productName(orderDetail.getProductName()) | ||
| .optionTitle(orderDetail.getOptionName()) | ||
| .price(orderDetail.getPrice()) | ||
| .quantity(orderDetail.getQuantity()) | ||
| .build(); | ||
| } | ||
|
|
||
| public static CustomerOrderListResponse.OrderResponse toOrderResponse( | ||
| CustomerOrderSummaryRow or, List<CustomerOrderListResponse.ProductResponse> pList) { | ||
|
|
||
| return CustomerOrderListResponse.OrderResponse.builder() | ||
| .orderId(or.orderId()) | ||
| .orderAt(or.orderAt()) | ||
| .refundStatus(or.refundStatus()) | ||
| .productResponseList(pList) | ||
| .build(); | ||
| } | ||
|
|
||
| public static CustomerOrderListResponse.ProductResponse toProductResponse( | ||
| CustomerOrderDetailRow c) { | ||
| return CustomerOrderListResponse.ProductResponse.builder() | ||
| .orderStatus(c.orderStatusIndi()) | ||
| .orderDetailId(c.orderDetailId()) | ||
| .optionName(c.optionName()) | ||
| .price(c.price()) | ||
| .productName(c.productName()) | ||
| .quantity(c.quantity()) | ||
| .build(); | ||
| } | ||
| } |
This file contains hidden or 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
121 changes: 121 additions & 0 deletions
121
src/main/java/com/irum/come2us/domain/order/application/service/CustomerOrderService.java
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| package com.irum.come2us.domain.order.application.service; | ||
|
|
||
| import com.irum.come2us.domain.member.domain.entity.Member; | ||
| import com.irum.come2us.domain.order.application.mapper.CustomerOrderMapper; | ||
| import com.irum.come2us.domain.order.domain.entity.Order; | ||
| import com.irum.come2us.domain.order.domain.entity.OrderDetail; | ||
| import com.irum.come2us.domain.order.domain.repository.OrderDetailRepository; | ||
| import com.irum.come2us.domain.order.domain.repository.OrderRepository; | ||
| import com.irum.come2us.domain.order.infrastructure.repository.dto.CustomerOrderDetailRow; | ||
| import com.irum.come2us.domain.order.infrastructure.repository.dto.CustomerOrderSummaryRow; | ||
| import com.irum.come2us.domain.order.presentation.dto.response.CustomerOrderListResponse; | ||
| import com.irum.come2us.domain.order.presentation.dto.response.OrderDetailResponse; | ||
| import com.irum.come2us.domain.order.presentation.dto.response.OrderDetailStatusResponse; | ||
| import com.irum.come2us.domain.refund.domain.entity.Refund; | ||
| import com.irum.come2us.domain.refund.domain.repository.RefundRepository; | ||
| import com.irum.come2us.global.presentation.advice.exception.CommonException; | ||
| import com.irum.come2us.global.presentation.advice.exception.errorcode.OrderErrorCode; | ||
| import com.irum.come2us.global.util.MemberUtil; | ||
| import java.time.LocalDate; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.UUID; | ||
| import java.util.stream.Collectors; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| @Service | ||
| @Slf4j | ||
| @RequiredArgsConstructor | ||
| @Transactional | ||
| public class CustomerOrderService { | ||
| private final OrderDetailRepository orderDetailRepository; | ||
| private final OrderRepository orderRepository; | ||
| private final RefundRepository refundRepository; | ||
| private final MemberUtil memberUtil; | ||
|
|
||
| @Transactional(readOnly = true) | ||
| public OrderDetailStatusResponse getOrderDetailStatus(UUID orderDetailId) { | ||
| OrderDetail orderDetail = | ||
| orderDetailRepository | ||
| .findByOrderDetailId(orderDetailId) | ||
| .orElseThrow( | ||
| () -> new CommonException(OrderErrorCode.ORDER_DETAIL_NOT_FOUND)); | ||
|
|
||
| return OrderDetailStatusResponse.from(orderDetail); | ||
| } | ||
|
|
||
| @Transactional(readOnly = true) | ||
| public OrderDetailResponse getOrderDetail(UUID orderId) { | ||
| Order order = | ||
| orderRepository | ||
| .findByOrderId(orderId) | ||
| .orElseThrow(() -> new CommonException(OrderErrorCode.ORDER_NOT_FOUND)); | ||
|
|
||
| List<OrderDetail> orderDetailList = orderDetailRepository.findAllByOrder(order); | ||
|
|
||
| Refund refund = refundRepository.findByOrder(order).orElse(null); | ||
|
|
||
| return CustomerOrderMapper.toOrderDetailResponse(order, orderDetailList, refund); | ||
| } | ||
|
|
||
| @Transactional | ||
| public CustomerOrderListResponse getOrderList( | ||
| UUID cursor, int size, LocalDate startDate, LocalDate endDate) { | ||
|
|
||
| Member member = memberUtil.getCurrentMember(); | ||
| log.info("member {}", member.getMemberId()); | ||
|
|
||
| // 2. order list 검색 | ||
| List<CustomerOrderSummaryRow> headerList = | ||
| orderRepository.fetchOrderListByMember(member, startDate, endDate, cursor, size); | ||
| log.info("order list {}", headerList); | ||
|
|
||
| boolean hasNext = headerList.size() > size; | ||
| if (hasNext) { | ||
| headerList = headerList.subList(0, size); | ||
| } | ||
| log.info("hasNext {}", hasNext); | ||
|
|
||
| // 3. order id list | ||
| List<UUID> orderIdList = headerList.stream().map(CustomerOrderSummaryRow::orderId).toList(); | ||
| List<CustomerOrderDetailRow> orderDetailList = | ||
| orderRepository.fetchOrderDetailListByMember(orderIdList); | ||
| log.info("orderDetailList ", orderDetailList); | ||
|
hyeonji91 marked this conversation as resolved.
Outdated
|
||
|
|
||
| // 4. orderId로 그룹핑 : productSummary 제작 | ||
| Map<UUID, List<CustomerOrderListResponse.ProductResponse>> detailMap = | ||
| orderDetailList.stream() | ||
| .collect( | ||
| Collectors.groupingBy( | ||
| CustomerOrderDetailRow::orderId, | ||
| Collectors.mapping( | ||
| CustomerOrderMapper::toProductResponse, | ||
| Collectors.toList()))); | ||
|
|
||
| // 5. orderResponse 제작 | ||
| List<CustomerOrderListResponse.OrderResponse> orderResponseList = | ||
| headerList.stream() | ||
| .filter(order -> detailMap.containsKey(order.orderId())) | ||
| .map( | ||
| order -> | ||
| CustomerOrderMapper.toOrderResponse( | ||
| order, | ||
| detailMap.getOrDefault( | ||
| order.orderId(), | ||
| List.of()) // order detail 없다면 빈 리스트 | ||
| )) | ||
| .toList(); | ||
|
|
||
| // 6. next cursor계산 | ||
| UUID nextCursor = orderResponseList.isEmpty() ? null : headerList.getLast().orderId(); | ||
|
|
||
| return CustomerOrderListResponse.builder() | ||
| .orderList(orderResponseList) | ||
| .hasNext(hasNext) | ||
| .nextCursor(nextCursor) | ||
| .build(); | ||
| } | ||
| } | ||
This file contains hidden or 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
6 changes: 5 additions & 1 deletion
6
src/main/java/com/irum/come2us/domain/order/domain/repository/OrderRepository.java
This file contains hidden or 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,12 +1,16 @@ | ||
| package com.irum.come2us.domain.order.domain.repository; | ||
|
|
||
| import com.irum.come2us.domain.member.domain.entity.Member; | ||
| import com.irum.come2us.domain.order.domain.entity.Order; | ||
| import java.util.List; | ||
| import java.util.Optional; | ||
| import java.util.UUID; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
| import org.springframework.stereotype.Repository; | ||
|
|
||
| @Repository | ||
| public interface OrderRepository extends JpaRepository<Order, UUID> { | ||
| public interface OrderRepository extends JpaRepository<Order, UUID>, OrderRepositoryCustom { | ||
| Optional<Order> findByOrderId(UUID orderId); | ||
|
|
||
| List<Order> findAllByMember(Member member); | ||
| } |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.