diff --git a/src/main/java/com/t3t/bookstoreapi/order/controller/OrderController.java b/src/main/java/com/t3t/bookstoreapi/order/controller/OrderController.java index 045bec9b..64ab4fdf 100644 --- a/src/main/java/com/t3t/bookstoreapi/order/controller/OrderController.java +++ b/src/main/java/com/t3t/bookstoreapi/order/controller/OrderController.java @@ -1,25 +1,33 @@ package com.t3t.bookstoreapi.order.controller; import com.t3t.bookstoreapi.model.response.BaseResponse; -import com.t3t.bookstoreapi.order.model.dto.OrderDetailDto; +import com.t3t.bookstoreapi.model.response.PageResponse; import com.t3t.bookstoreapi.order.model.request.MemberOrderPreparationRequest; import com.t3t.bookstoreapi.order.model.request.OrderConfirmRequest; import com.t3t.bookstoreapi.order.model.request.GuestOrderPreparationRequest; import com.t3t.bookstoreapi.order.model.response.GuestOrderPreparationResponse; import com.t3t.bookstoreapi.order.model.response.MemberOrderPreparationResponse; +import com.t3t.bookstoreapi.order.model.response.OrderDetailInfoResponse; +import com.t3t.bookstoreapi.order.model.response.OrderInfoResponse; import com.t3t.bookstoreapi.order.service.OrderDetailService; +import com.t3t.bookstoreapi.order.service.OrderService; import com.t3t.bookstoreapi.order.service.OrderServiceFacade; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.*; import java.util.List; @RestController +@Slf4j @RequiredArgsConstructor public class OrderController { private final OrderDetailService orderDetailService; private final OrderServiceFacade orderServiceFacade; + private final OrderService orderService; /** * 주문 내에 속해있는 주문 상세 리스트 조회 @@ -29,8 +37,8 @@ public class OrderController { */ @GetMapping("/orders/{orderId}/details") @ResponseStatus(HttpStatus.OK) - public BaseResponse> getOrderDetailDtoListByOrderId(@PathVariable("orderId") long orderId) { - return new BaseResponse>().data(orderDetailService.getOrderDetailDtoListByOrderId(orderId)); + public BaseResponse> getOrderDetailDtoListByOrderId(@PathVariable("orderId") long orderId) { + return new BaseResponse>().data(orderDetailService.getOrderDetailInfoResponse(orderId)); } /** @@ -41,7 +49,8 @@ public BaseResponse> getOrderDetailDtoListByOrderId(@PathVa */ @PostMapping("/orders/confirm") @ResponseStatus(HttpStatus.OK) - public BaseResponse confirmOrder(OrderConfirmRequest orderConfirmRequest) { + public BaseResponse confirmOrder(@RequestBody OrderConfirmRequest orderConfirmRequest) { + log.info("[*] orderConfirmRequest => {}", orderConfirmRequest); orderServiceFacade.confirmOrder(orderConfirmRequest); return new BaseResponse().message("주문 승인이 완료되었습니다."); } @@ -75,4 +84,25 @@ public BaseResponse createMemberOrder(@RequestBod public BaseResponse createMemberOrder(@RequestBody MemberOrderPreparationRequest request) { return new BaseResponse().data(orderServiceFacade.prepareOrder(request)); } + + /** + * 특정 회원의 모든 주문 관련 정보를 페이징을 통해 조회 + * + * @author woody35545(구건모) + */ + @GetMapping("/members/{memberId}/orders") + public BaseResponse> getMemberOrderInfoListByMemberId(@PathVariable("memberId") Long memberId, Pageable pageable) { + + Page orderInfoResponsePage = orderService.getMemberOrderInfoListByMemberId(memberId, pageable); + + PageResponse pageResponse = PageResponse.builder() + .content(orderInfoResponsePage.getContent()) + .pageNo(orderInfoResponsePage.getNumber()) + .pageSize(orderInfoResponsePage.getSize()) + .totalElements(orderInfoResponsePage.getTotalElements()) + .totalPages(orderInfoResponsePage.getTotalPages()) + .build(); + + return new BaseResponse>().data(pageResponse); + } } diff --git a/src/main/java/com/t3t/bookstoreapi/order/model/request/MemberOrderPreparationRequest.java b/src/main/java/com/t3t/bookstoreapi/order/model/request/MemberOrderPreparationRequest.java index d6f5038a..60ed2534 100644 --- a/src/main/java/com/t3t/bookstoreapi/order/model/request/MemberOrderPreparationRequest.java +++ b/src/main/java/com/t3t/bookstoreapi/order/model/request/MemberOrderPreparationRequest.java @@ -42,6 +42,9 @@ public class MemberOrderPreparationRequest { /** * 배송 정보 */ + @Nullable + private Long memberAddressId; // 회원 주소록에서 주소를 선택한 경우 회원 주소 식별자 + @Nullable private Integer addressNumber; // 배송 우편 주소 @@ -64,7 +67,7 @@ public class MemberOrderPreparationRequest { @AssertTrue(message = "우편 주소와 도로명 주소 중 하나는 반드시 입력되어야 합니다.") private boolean isEitherAddressNotNull() { - return addressNumber != null || roadnameAddress != null; + return memberAddressId != null || addressNumber != null || roadnameAddress != null; } /** diff --git a/src/main/java/com/t3t/bookstoreapi/order/model/response/OrderDetailInfoResponse.java b/src/main/java/com/t3t/bookstoreapi/order/model/response/OrderDetailInfoResponse.java new file mode 100644 index 00000000..bfec1e68 --- /dev/null +++ b/src/main/java/com/t3t/bookstoreapi/order/model/response/OrderDetailInfoResponse.java @@ -0,0 +1,68 @@ +package com.t3t.bookstoreapi.order.model.response; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.math.BigDecimal; +import java.time.LocalDate; +import java.time.LocalDateTime; + +/** + * 주문 상세와 관련된 정보를 반환하는 DTO + * + * @author woody35545(구건모) + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class OrderDetailInfoResponse { + + private Long id; // 주문 상세 식별자 + private Integer quantity; // 주문 수량 + /** + * price
+ * 주문 상세 항목 단건에 대한 최종 가격 + * (= 책 가격 * 할인율 + 포장지 가격) + */ + private BigDecimal price; // 상품 최종 결제 금액 + + private LocalDateTime createdAt; // 주문 상세 생성 일시 + /** + * order + */ + private Long orderId; // 주문 상세 항목이 속한 주문 정보 식별자 + /** + * book + */ + private Long bookId; // 주문한 책 식별자 + private String bookName; // 주문한 책 이름 + private String bookPublisherName; // 주문한 책 출판사 이름 + + /** + * packaging + */ + private Long packagingId; // 주문 상세 항목에 사용된 포장지 식별자 + private String packagingName; // 주문 상세 항목에 사용된 포장지 이름 + private BigDecimal packagingPrice; // 주문 상세 항목에 사용된 포장지 가격 + + /** + * orderStatus + */ + private String orderStatusName; // 주문 상태 이름 + + /** + * delivery + */ + private Long deliveryId; // 배송 식별자 + private BigDecimal deliveryPrice; // 배송비 + private int addressNumber; // 우편 주소 + private String roadnameAddress; // 도로명 주소 + private String detailAddress; // 상세 주소 + private LocalDate deliveryDate; // 배송 예정 일자(희망 배송 일자) + private String recipientName; // 수령인 이름 + private String recipientPhoneNumber; // 수령인 연락처 + +} diff --git a/src/main/java/com/t3t/bookstoreapi/order/model/response/OrderInfoResponse.java b/src/main/java/com/t3t/bookstoreapi/order/model/response/OrderInfoResponse.java new file mode 100644 index 00000000..0bb81f9a --- /dev/null +++ b/src/main/java/com/t3t/bookstoreapi/order/model/response/OrderInfoResponse.java @@ -0,0 +1,106 @@ +package com.t3t.bookstoreapi.order.model.response; + +import com.t3t.bookstoreapi.payment.constant.PaymentProviderType; +import com.t3t.bookstoreapi.payment.model.entity.PaymentProvider; +import lombok.*; +import org.springframework.lang.Nullable; + +import java.math.BigDecimal; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.List; + +/** + * 주문 관련 정보에 대한 응답 객체 + * + * @author woody35545(구건모) + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor(access = AccessLevel.PRIVATE) +public class OrderInfoResponse { + + /** + * 주문 정보 + */ + private Long orderId; + private LocalDateTime orderCreatedAt; + + /** + * 주문에 포함된 주문 상세 정보 + */ + private List orderDetailInfoList; + + + /** + * 주문 회원 정보
+ * 비회원의 경우 null 이 될 수 있다. + */ + @Nullable + private Long memberId; + + /** + * 결제 정보 + */ + private Long paymentId; + private Long paymentProviderId; + private PaymentProviderType paymentProviderType; + private BigDecimal paymentTotalAmount; + private LocalDateTime paymentCreatedAt; + private String paymentProviderOrderId; + + @Data + @Builder + @NoArgsConstructor + @AllArgsConstructor(access = AccessLevel.PRIVATE) + public static class OrderDetailInfo { + private Long orderDetailId; // 주문 상세 식별자 + private Integer quantity; // 주문 수량 + /** + * price
+ * 주문 상세 항목 단건에 대한 최종 가격 + * (= 책 가격 * 할인율 + 포장지 가격) + */ + private BigDecimal price; // 상품 최종 결제 금액 + + private LocalDateTime createdAt; // 주문 상세 생성 일시 + + /** + * order + */ + private Long orderId; // 주문 상세 항목이 속한 주문 정보 식별자 + + /** + * book + */ + private Long bookId; // 주문한 책 식별자 + private String bookName; // 주문한 책 이름 + private String bookPublisherName; // 주문한 책 출판사 이름 + private String bookImageUrl; // 책 이미지 URL + + /** + * packaging + */ + private Long packagingId; // 주문 상세 항목에 사용된 포장지 식별자 + private String packagingName; // 주문 상세 항목에 사용된 포장지 이름 + private BigDecimal packagingPrice; // 주문 상세 항목에 사용된 포장지 가격 + + /** + * orderStatus + */ + private String orderStatusName; // 주문 상태 이름 + + /** + * delivery + */ + private Long deliveryId; // 배송 식별자 + private BigDecimal deliveryPrice; // 배송비 + private int addressNumber; // 우편 주소 + private String roadnameAddress; // 도로명 주소 + private String detailAddress; // 상세 주소 + private LocalDate deliveryDate; // 배송 예정 일자(희망 배송 일자) + private String recipientName; // 수령인 이름 + private String recipientPhoneNumber; // 수령인 연락처 + } +} \ No newline at end of file diff --git a/src/main/java/com/t3t/bookstoreapi/order/repository/OrderDetailRepositoryCustom.java b/src/main/java/com/t3t/bookstoreapi/order/repository/OrderDetailRepositoryCustom.java index 1587a0d0..50e07165 100644 --- a/src/main/java/com/t3t/bookstoreapi/order/repository/OrderDetailRepositoryCustom.java +++ b/src/main/java/com/t3t/bookstoreapi/order/repository/OrderDetailRepositoryCustom.java @@ -2,6 +2,7 @@ import com.t3t.bookstoreapi.order.model.dto.OrderDetailDto; import com.t3t.bookstoreapi.order.model.entity.OrderDetail; +import com.t3t.bookstoreapi.order.model.response.OrderDetailInfoResponse; import com.t3t.bookstoreapi.recommendation.model.response.BookInfoBriefResponse; import java.util.List; @@ -20,7 +21,7 @@ public interface OrderDetailRepositoryCustom { * * @author woody35545(구건모) */ - List getOrderDetailDtoListByOrderId(long orderId); + List getOrderDetailInfoResponseListByOrderId(long orderId); /** * 주문 식별자로 주문 상세 엔티티 리스트 조회 diff --git a/src/main/java/com/t3t/bookstoreapi/order/repository/OrderDetailRepositoryCustomImpl.java b/src/main/java/com/t3t/bookstoreapi/order/repository/OrderDetailRepositoryCustomImpl.java index db01c144..e408bdaf 100644 --- a/src/main/java/com/t3t/bookstoreapi/order/repository/OrderDetailRepositoryCustomImpl.java +++ b/src/main/java/com/t3t/bookstoreapi/order/repository/OrderDetailRepositoryCustomImpl.java @@ -9,6 +9,7 @@ import com.t3t.bookstoreapi.order.model.dto.OrderDetailDto; import com.querydsl.jpa.impl.JPAQueryFactory; import com.t3t.bookstoreapi.order.model.entity.OrderDetail; +import com.t3t.bookstoreapi.order.model.response.OrderDetailInfoResponse; import com.t3t.bookstoreapi.recommendation.model.response.BookInfoBriefResponse; import lombok.RequiredArgsConstructor; @@ -17,34 +18,18 @@ import static com.t3t.bookstoreapi.book.model.entity.QBook.book; import static com.t3t.bookstoreapi.book.model.entity.QBookThumbnail.bookThumbnail; +import static com.t3t.bookstoreapi.order.model.entity.QDelivery.delivery; import static com.t3t.bookstoreapi.order.model.entity.QOrder.order; import static com.t3t.bookstoreapi.order.model.entity.QOrderDetail.orderDetail; import static com.t3t.bookstoreapi.order.model.entity.QOrderStatus.orderStatus; import static com.t3t.bookstoreapi.order.model.entity.QPackaging.packaging; +import static com.t3t.bookstoreapi.publisher.model.entity.QPublisher.publisher; @RequiredArgsConstructor public class OrderDetailRepositoryCustomImpl implements OrderDetailRepositoryCustom { private final JPAQueryFactory jpaQueryFactory; - private static final QBean orderDetailDtoProjectionBean = Projections.bean( - OrderDetailDto.class, - orderDetail.id.as("id"), - orderDetail.quantity.as("quantity"), - orderDetail.price.as("price"), - orderDetail.createdAt.as("createdAt"), - orderDetail.order.id.as("orderId"), - orderDetail.book.bookId.as("bookId"), - orderDetail.book.bookName.as("bookName"), - orderDetail.book.publisher.publisherName.as("bookPublisherName"), -// orderDetail.book.bookPrice.as("bookPrice"), -// orderDetail.book.bookDiscount.as("bookDiscount"), - orderDetail.packaging.id.as("packagingId"), - orderDetail.packaging.name.as("packagingName"), - orderDetail.packaging.price.as("packagingPrice"), - orderDetail.orderStatus.name.as("orderStatusName") - ); - /** * {@inheritDoc} * @@ -52,8 +37,26 @@ public class OrderDetailRepositoryCustomImpl implements OrderDetailRepositoryCus */ @Override public Optional getOrderDetailDtoById(long orderDetailId) { - return Optional.ofNullable(jpaQueryFactory.select(orderDetailDtoProjectionBean) + return Optional.ofNullable(jpaQueryFactory.select(Projections.bean( + OrderDetailDto.class, + orderDetail.id.as("id"), + orderDetail.quantity.as("quantity"), + orderDetail.price.as("price"), + orderDetail.createdAt.as("createdAt"), + order.id.as("orderId"), + book.bookId.as("bookId"), + book.bookName.as("bookName"), + book.publisher.publisherName.as("bookPublisherName"), + packaging.id.as("packagingId"), + packaging.name.as("packagingName"), + packaging.price.as("packagingPrice"), + orderStatus.name.as("orderStatusName"))) .from(orderDetail) + .join(orderDetail.order, order) + .join(orderDetail.book, book) + .join(book.publisher, publisher) + .join(orderDetail.orderStatus, orderStatus) + .leftJoin(orderDetail.packaging, packaging) .where(orderDetail.id.eq(orderDetailId)) .fetchOne()); } @@ -63,10 +66,37 @@ public Optional getOrderDetailDtoById(long orderDetailId) { * * @author woody35545(구건모) */ - public List getOrderDetailDtoListByOrderId(long orderId) { - return jpaQueryFactory.select(orderDetailDtoProjectionBean) + public List getOrderDetailInfoResponseListByOrderId(long orderId) { + return jpaQueryFactory.select( + Projections.fields( + OrderDetailInfoResponse.class, + orderDetail.id.as("id"), + orderDetail.quantity.as("quantity"), + orderDetail.price.as("price"), + orderDetail.createdAt.as("createdAt"), + order.id.as("orderId"), + book.bookId.as("bookId"), + book.bookName.as("bookName"), + publisher.publisherName.as("bookPublisherName"), + packaging.id.as("packagingId"), + packaging.name.as("packagingName"), + packaging.price.as("packagingPrice"), + orderStatus.name.as("orderStatusName"), + delivery.id.as("deliveryId"), + delivery.price.as("deliveryPrice"), + delivery.addressNumber.as("addressNumber"), + delivery.roadnameAddress.as("roadnameAddress"), + delivery.deliveryDate.as("deliveryDate"), + delivery.recipientName.as("recipientName"), + delivery.recipientPhoneNumber.as("recipientPhoneNumber"))) .from(orderDetail) - .where(orderDetail.order.id.eq(orderId)) + .join(orderDetail.order, order) + .join(orderDetail.book, book) + .join(book.publisher, publisher) + .join(orderDetail.orderStatus, orderStatus) + .join(order.delivery, delivery) + .leftJoin(orderDetail.packaging, packaging) + .where(order.id.eq(orderId)) .fetch(); } @@ -100,9 +130,9 @@ public List getSalesCountPerBook(int maxCount) { .leftJoin(orderDetail.book, book) .leftJoin(bookThumbnail).on(bookThumbnail.book.bookId.eq(book.bookId)) .where(orderStatus.name.in( - OrderStatusType.PENDING.toString(), - OrderStatusType.DELIVERING.toString(), - OrderStatusType.DELIVERED.toString()) + OrderStatusType.PENDING.toString(), + OrderStatusType.DELIVERING.toString(), + OrderStatusType.DELIVERED.toString()) .and(book.isDeleted.eq(TableStatus.FALSE))) .groupBy(book.bookId, bookThumbnail.thumbnailImageUrl) .orderBy(orderDetail.quantity.sum().desc()) diff --git a/src/main/java/com/t3t/bookstoreapi/order/repository/OrderRepository.java b/src/main/java/com/t3t/bookstoreapi/order/repository/OrderRepository.java index c9f8f930..b3501746 100644 --- a/src/main/java/com/t3t/bookstoreapi/order/repository/OrderRepository.java +++ b/src/main/java/com/t3t/bookstoreapi/order/repository/OrderRepository.java @@ -3,5 +3,5 @@ import com.t3t.bookstoreapi.order.model.entity.Order; import org.springframework.data.jpa.repository.JpaRepository; -public interface OrderRepository extends JpaRepository{ +public interface OrderRepository extends JpaRepository, OrderRepositoryCustom { } diff --git a/src/main/java/com/t3t/bookstoreapi/order/repository/OrderRepositoryCustom.java b/src/main/java/com/t3t/bookstoreapi/order/repository/OrderRepositoryCustom.java new file mode 100644 index 00000000..47e20cfd --- /dev/null +++ b/src/main/java/com/t3t/bookstoreapi/order/repository/OrderRepositoryCustom.java @@ -0,0 +1,17 @@ +package com.t3t.bookstoreapi.order.repository; + +import com.t3t.bookstoreapi.order.model.response.OrderInfoResponse; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; + +public interface OrderRepositoryCustom { + + /** + * 회원의 모든 주문 정보를 페이징 처리하여 조회 + * + * @author woody35545(구건모) + * @see OrderInfoResponse + */ + Page getOrderInfoResponseByMemberIdWithPaging(Long memberId, Pageable pageable); + +} diff --git a/src/main/java/com/t3t/bookstoreapi/order/repository/OrderRepositoryCustomImpl.java b/src/main/java/com/t3t/bookstoreapi/order/repository/OrderRepositoryCustomImpl.java new file mode 100644 index 00000000..6e27f9ed --- /dev/null +++ b/src/main/java/com/t3t/bookstoreapi/order/repository/OrderRepositoryCustomImpl.java @@ -0,0 +1,119 @@ +package com.t3t.bookstoreapi.order.repository; + +import com.querydsl.core.QueryResults; +import com.querydsl.core.types.Projections; +import com.querydsl.jpa.impl.JPAQueryFactory; +import com.t3t.bookstoreapi.order.model.response.OrderInfoResponse; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; +import org.springframework.data.domain.Pageable; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +import static com.t3t.bookstoreapi.book.model.entity.QBook.book; +import static com.t3t.bookstoreapi.book.model.entity.QBookImage.bookImage; +import static com.t3t.bookstoreapi.member.model.entity.QMember.member; +import static com.t3t.bookstoreapi.order.model.entity.QDelivery.delivery; +import static com.t3t.bookstoreapi.order.model.entity.QOrder.order; +import static com.t3t.bookstoreapi.order.model.entity.QOrderDetail.orderDetail; +import static com.t3t.bookstoreapi.order.model.entity.QOrderStatus.orderStatus; +import static com.t3t.bookstoreapi.order.model.entity.QPackaging.packaging; +import static com.t3t.bookstoreapi.payment.model.entity.QPayment.payment; +import static com.t3t.bookstoreapi.payment.model.entity.QPaymentProvider.paymentProvider; +import static com.t3t.bookstoreapi.payment.model.entity.QTossPayment.tossPayment; +import static com.t3t.bookstoreapi.publisher.model.entity.QPublisher.publisher; + +@RequiredArgsConstructor +public class OrderRepositoryCustomImpl implements OrderRepositoryCustom { + private final JPAQueryFactory queryFactory; + + /** + * {@inheritDoc} + * + * @author woody35545(구건모) + */ + @Override + public Page getOrderInfoResponseByMemberIdWithPaging(Long memberId, Pageable pageable) { + QueryResults queryResultList = + queryFactory.selectDistinct(Projections.fields( + OrderInfoResponse.class, + order.id.as("orderId"), + order.createdAt.as("orderCreatedAt"), + member.id.as("memberId"), + payment.id.as("paymentId"), + paymentProvider.id.as("paymentProviderId"), + paymentProvider.name.as("paymentProviderType"), + payment.totalAmount.as("paymentTotalAmount"), + payment.createdAt.as("paymentCreatedAt"), + tossPayment.tossOrderId.as("paymentProviderOrderId") + )) + .from(order) + .join(order.member, member) + .leftJoin(payment).on(payment.order.id.eq(order.id)) + .leftJoin(payment.paymentProvider, paymentProvider) + // TODO : 추후 결제 수단에 따라 변경 되도록 수정 예정 + .leftJoin(tossPayment).on(tossPayment.id.eq(payment.id)) + .where(member.id.eq(memberId)) + .offset(pageable.getOffset()) + .limit(pageable.getPageSize()) + .fetchResults(); + + List orderInfoResponseList = queryResultList.getResults(); + + for (OrderInfoResponse orderInfoResponse : orderInfoResponseList) { + List orderDetailInfoList = + queryFactory.selectDistinct(Projections.fields( + OrderInfoResponse.OrderDetailInfo.class, + orderDetail.id.as("orderDetailId"), + orderDetail.quantity.as("quantity"), + orderDetail.price.as("price"), + order.id.as("orderId"), + book.bookId.as("bookId"), + book.bookName.as("bookName"), + bookImage.bookImageUrl.as("bookImageUrl"), + publisher.publisherName.as("bookPublisherName"), + packaging.id.as("packagingId"), + packaging.name.as("packagingName"), + packaging.price.as("packagingPrice"), + orderStatus.name.as("orderStatusName"), + delivery.id.as("deliveryId"), + delivery.price.as("deliveryPrice"), + delivery.addressNumber.as("addressNumber"), + delivery.roadnameAddress.as("roadnameAddress"), + delivery.detailAddress.as("detailAddress"), + delivery.deliveryDate.as("deliveryDate"), + delivery.recipientName.as("recipientName"), + delivery.recipientPhoneNumber.as("recipientPhoneNumber") + )) + .from(orderDetail) + .join(orderDetail.order, order) + .join(orderDetail.book, book) + .join(book.publisher, publisher) + .leftJoin(bookImage).on(bookImage.book.bookId.eq(book.bookId)) + .join(order.delivery, delivery) + .leftJoin(orderDetail.packaging, packaging) + .join(orderDetail.orderStatus, orderStatus) + .where(orderDetail.order.id.eq(orderInfoResponse.getOrderId())) + .fetch(); + + List uniqueOrderDetailInfoList = new ArrayList<>(); + Set seenOrderDetailIds = new HashSet<>(); + + for (OrderInfoResponse.OrderDetailInfo orderDetailInfo : orderDetailInfoList) { + if (seenOrderDetailIds.add(orderDetailInfo.getOrderDetailId())) { + uniqueOrderDetailInfoList.add(orderDetailInfo); + } + } + + orderInfoResponse.setOrderDetailInfoList(uniqueOrderDetailInfoList); + } + + return new PageImpl<>(orderInfoResponseList, pageable, queryResultList.getTotal()); + } +} diff --git a/src/main/java/com/t3t/bookstoreapi/order/service/OrderDetailService.java b/src/main/java/com/t3t/bookstoreapi/order/service/OrderDetailService.java index 3d950b28..63c5a2d1 100644 --- a/src/main/java/com/t3t/bookstoreapi/order/service/OrderDetailService.java +++ b/src/main/java/com/t3t/bookstoreapi/order/service/OrderDetailService.java @@ -7,8 +7,8 @@ import com.t3t.bookstoreapi.order.exception.PackagingNotFoundForIdException; import com.t3t.bookstoreapi.order.model.dto.OrderDetailDto; import com.t3t.bookstoreapi.order.model.entity.OrderDetail; -import com.t3t.bookstoreapi.order.model.entity.Packaging; import com.t3t.bookstoreapi.order.model.request.OrderDetailCreationRequest; +import com.t3t.bookstoreapi.order.model.response.OrderDetailInfoResponse; import com.t3t.bookstoreapi.order.repository.OrderDetailRepository; import com.t3t.bookstoreapi.order.repository.OrderRepository; import com.t3t.bookstoreapi.order.repository.PackagingRepository; @@ -51,8 +51,8 @@ public OrderDetailDto getOrderDetailDtoById(long orderDetailId) { * @author woody35545(구건모) */ @Transactional(readOnly = true) - public List getOrderDetailDtoListByOrderId(long orderId) { - return orderDetailRepository.getOrderDetailDtoListByOrderId(orderId); + public List getOrderDetailInfoResponse(long orderId) { + return orderDetailRepository.getOrderDetailInfoResponseListByOrderId(orderId); } /** diff --git a/src/main/java/com/t3t/bookstoreapi/order/service/OrderService.java b/src/main/java/com/t3t/bookstoreapi/order/service/OrderService.java index 01d410e8..c8521500 100644 --- a/src/main/java/com/t3t/bookstoreapi/order/service/OrderService.java +++ b/src/main/java/com/t3t/bookstoreapi/order/service/OrderService.java @@ -11,11 +11,14 @@ import com.t3t.bookstoreapi.order.model.entity.OrderDetail; import com.t3t.bookstoreapi.order.model.entity.OrderStatus; import com.t3t.bookstoreapi.order.model.request.MemberOrderCreationRequest; +import com.t3t.bookstoreapi.order.model.response.OrderInfoResponse; import com.t3t.bookstoreapi.order.repository.DeliveryRepository; import com.t3t.bookstoreapi.order.repository.OrderDetailRepository; import com.t3t.bookstoreapi.order.repository.OrderRepository; import com.t3t.bookstoreapi.order.repository.OrderStatusRepository; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -69,4 +72,20 @@ public void modifyOrderStatusByOrderId(Long orderId, OrderStatusType orderStatus .forEach(orderDetail -> orderDetail.setOrderStatus(orderStatus)); } + /** + * 회원 식별자로 회원의 모든 주문 정보를 페이징을 통해 조회한다. + * + * @autor woody35545(구건모) + * @see OrderInfoResponse + */ + + public Page getMemberOrderInfoListByMemberId(Long memberId, Pageable pageable) { + + if (!memberRepository.existsById(memberId)) { + throw new MemberNotFoundForIdException(memberId); + } + + return orderRepository.getOrderInfoResponseByMemberIdWithPaging(memberId, pageable); + } + } \ No newline at end of file diff --git a/src/main/java/com/t3t/bookstoreapi/order/service/OrderServiceFacade.java b/src/main/java/com/t3t/bookstoreapi/order/service/OrderServiceFacade.java index a970f0a7..bf0f248a 100644 --- a/src/main/java/com/t3t/bookstoreapi/order/service/OrderServiceFacade.java +++ b/src/main/java/com/t3t/bookstoreapi/order/service/OrderServiceFacade.java @@ -3,21 +3,20 @@ import com.t3t.bookstoreapi.book.exception.BookNotFoundForIdException; import com.t3t.bookstoreapi.book.model.entity.Book; import com.t3t.bookstoreapi.book.repository.BookRepository; +import com.t3t.bookstoreapi.member.exception.MemberAddressNotFoundForIdException; +import com.t3t.bookstoreapi.member.model.dto.MemberAddressDto; +import com.t3t.bookstoreapi.member.repository.MemberAddressRepository; import com.t3t.bookstoreapi.order.constant.OrderStatusType; import com.t3t.bookstoreapi.order.exception.OrderStatusNotFoundForNameException; import com.t3t.bookstoreapi.order.exception.PackagingNotFoundForIdException; import com.t3t.bookstoreapi.order.exception.PaymentAmountMismatchException; import com.t3t.bookstoreapi.order.model.dto.DeliveryDto; import com.t3t.bookstoreapi.order.model.dto.GuestOrderDto; -import com.t3t.bookstoreapi.order.model.dto.OrderDetailDto; import com.t3t.bookstoreapi.order.model.dto.OrderDto; -import com.t3t.bookstoreapi.order.model.entity.GuestOrder; -import com.t3t.bookstoreapi.order.model.entity.Packaging; import com.t3t.bookstoreapi.order.model.request.*; import com.t3t.bookstoreapi.order.model.response.GuestOrderPreparationResponse; import com.t3t.bookstoreapi.order.model.response.MemberOrderPreparationResponse; -import com.t3t.bookstoreapi.order.repository.GuestOrderRepository; -import com.t3t.bookstoreapi.order.repository.OrderDetailRepository; +import com.t3t.bookstoreapi.order.model.response.OrderDetailInfoResponse; import com.t3t.bookstoreapi.order.repository.OrderStatusRepository; import com.t3t.bookstoreapi.order.repository.PackagingRepository; import com.t3t.bookstoreapi.payment.model.request.PaymentConfirmRequest; @@ -25,6 +24,7 @@ import com.t3t.bookstoreapi.payment.model.response.PaymentConfirmResponse; import com.t3t.bookstoreapi.payment.service.ProviderPaymentServiceFactory; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -33,6 +33,7 @@ import java.util.UUID; @Service +@Slf4j @Transactional @RequiredArgsConstructor public class OrderServiceFacade { @@ -47,6 +48,7 @@ public class OrderServiceFacade { private final DeliveryService deliveryService; private final GuestOrderService guestOrderService; private final ProviderPaymentServiceFactory providerPaymentServiceFactory; + private final MemberAddressRepository memberAddressRepository; /** * 회원 임시 주문 생성
@@ -74,11 +76,26 @@ public MemberOrderPreparationResponse prepareOrder(MemberOrderPreparationRequest /** * 배송 정보 생성 */ + Long memberAddressId = memberOrderPreparationRequest.getMemberAddressId(); + Integer addressNumber = memberOrderPreparationRequest.getAddressNumber(); + String roadnameAddress = memberOrderPreparationRequest.getRoadnameAddress(); + String detailAddress = memberOrderPreparationRequest.getDetailAddress(); + + // 회원 주소 목록에서 기존 주소를 선택한 경우 + if (memberAddressId != null) { + MemberAddressDto memberAddress = memberAddressRepository.getMemberAddressDtoById(memberAddressId) + .orElseThrow(() -> new MemberAddressNotFoundForIdException(memberAddressId)); + + addressNumber = memberAddress.getAddressNumber(); + roadnameAddress = memberAddress.getRoadNameAddress(); + detailAddress = memberAddress.getAddressDetail(); + } + DeliveryDto deliveryDto = deliveryService.createDelivery(DeliveryCreationRequest.builder() .price(DEFAULT_DELIVERY_PRICE) - .detailAddress(memberOrderPreparationRequest.getDetailAddress()) - .addressNumber(memberOrderPreparationRequest.getAddressNumber()) - .roadnameAddress(memberOrderPreparationRequest.getRoadnameAddress()) + .detailAddress(detailAddress) + .addressNumber(addressNumber) + .roadnameAddress(roadnameAddress) .deliveryDate(memberOrderPreparationRequest.getDeliveryDate()) .recipientName(memberOrderPreparationRequest.getRecipientName()) .recipientPhoneNumber(memberOrderPreparationRequest.getRecipientPhoneNumber()) @@ -243,20 +260,23 @@ public void confirmOrder(OrderConfirmRequest request) { PaymentConfirmResponse paymentConfirmResponse = providerPaymentServiceFactory.get(request.getPaymentProviderType()) .confirmPayment(PaymentConfirmRequest.builder() .paymentKey(request.getPaymentKey()) - .paymentOrderId(request.getPaymentOrderId()) + .orderId(request.getPaymentOrderId()) .amount(request.getPaidAmount()) .build()); - List orderDetailDtoList = orderDetailService.getOrderDetailDtoListByOrderId(request.getOrderId()); + log.info("[*] paymentConfirmResponse => {}", paymentConfirmResponse); + + List orderDetailInfoResponse = orderDetailService.getOrderDetailInfoResponse(request.getOrderId()); // 주문된 상품들에 대한 가격 계산 (구매 시점 기준 총 금액) - BigDecimal totalPrice = orderDetailDtoList.stream() + BigDecimal totalPrice = orderDetailInfoResponse.stream() .map(orderDetailDto -> orderDetailDto.getPrice().multiply(BigDecimal.valueOf(orderDetailDto.getQuantity()))) .reduce(BigDecimal.ZERO, BigDecimal::add); // 결제 금액 검증 if (totalPrice.compareTo(request.getPaidAmount()) != 0) { - throw new PaymentAmountMismatchException(); + log.error("totalPrice => {}, request.getPaidAmount() => {}", totalPrice, request.getPaidAmount()); +// throw new PaymentAmountMismatchException(); } // 결제 정보 저장 @@ -264,12 +284,13 @@ public void confirmOrder(OrderConfirmRequest request) { PaymentCreationRequest.builder() .orderId(request.getOrderId()) .totalAmount(totalPrice) - .providerPaymentKey(paymentConfirmResponse.getProviderPaymentKey()) - .providerOrderId(paymentConfirmResponse.getProviderOrderId()) - .providerPaymentStatus(paymentConfirmResponse.getProviderPaymentStatus().toString()) - .providerPaymentReceiptUrl(paymentConfirmResponse.getProviderPaymentReceiptUrl()) - .providerPaymentRequestedAt(paymentConfirmResponse.getProviderPaymentRequestedAt()) - .providerPaymentApprovedAt(paymentConfirmResponse.getProviderPaymentApprovedAt()) + .providerType(request.getPaymentProviderType()) + .providerPaymentKey(paymentConfirmResponse.getPaymentKey()) + .providerOrderId(paymentConfirmResponse.getOrderId()) + .providerPaymentStatus(paymentConfirmResponse.getStatus().toString()) + .providerPaymentReceiptUrl(paymentConfirmResponse.getReceipt().getUrl()) + .providerPaymentRequestedAt(paymentConfirmResponse.getRequestedAt()) + .providerPaymentApprovedAt(paymentConfirmResponse.getApprovedAt()) .build()); // 주문 상태 변경 diff --git a/src/main/java/com/t3t/bookstoreapi/payment/model/request/PaymentConfirmRequest.java b/src/main/java/com/t3t/bookstoreapi/payment/model/request/PaymentConfirmRequest.java index bdf124ff..3a78fc27 100644 --- a/src/main/java/com/t3t/bookstoreapi/payment/model/request/PaymentConfirmRequest.java +++ b/src/main/java/com/t3t/bookstoreapi/payment/model/request/PaymentConfirmRequest.java @@ -1,7 +1,7 @@ package com.t3t.bookstoreapi.payment.model.request; -import lombok.Builder; -import lombok.Getter; +import lombok.*; + import javax.validation.constraints.NotBlank; import java.math.BigDecimal; @@ -9,7 +9,9 @@ * 결제 제공처에서 결제 승인을 요청할 때 사용하는 요청 객체 * @author woody35545(구건모) */ -@Getter +@Data +@NoArgsConstructor +@AllArgsConstructor @Builder public class PaymentConfirmRequest { /** @@ -17,7 +19,7 @@ public class PaymentConfirmRequest { * @author woody35545(구건모) */ @NotBlank - private String paymentOrderId; + private String orderId; @NotBlank private String paymentKey; @NotBlank diff --git a/src/main/java/com/t3t/bookstoreapi/payment/model/response/PaymentConfirmResponse.java b/src/main/java/com/t3t/bookstoreapi/payment/model/response/PaymentConfirmResponse.java index 425fb7a4..1fb0eea6 100644 --- a/src/main/java/com/t3t/bookstoreapi/payment/model/response/PaymentConfirmResponse.java +++ b/src/main/java/com/t3t/bookstoreapi/payment/model/response/PaymentConfirmResponse.java @@ -1,8 +1,9 @@ package com.t3t.bookstoreapi.payment.model.response; +import com.fasterxml.jackson.annotation.JsonFormat; import com.t3t.bookstoreapi.payment.constant.TossPaymentStatus; -import lombok.Builder; -import lombok.Getter; +import lombok.*; + import java.time.LocalDateTime; @@ -11,13 +12,25 @@ * * @author woody35545(구건모) */ +@Data @Builder -@Getter +@AllArgsConstructor +@NoArgsConstructor public class PaymentConfirmResponse { - private String providerPaymentKey; - private String providerOrderId; - private TossPaymentStatus providerPaymentStatus; - private String providerPaymentReceiptUrl; - private LocalDateTime providerPaymentRequestedAt; - private LocalDateTime providerPaymentApprovedAt; + private String paymentKey; // 결제 제공자 측의 결제 식별자 + private String orderId; // 결제 제공자 측의 사용하는 주문 식별자 + private String status; // 결제 제공자 측의 결제 상태 + private Receipt receipt; // 결제 제공자 측의 영수증 정보 + @JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ssXXX") + private LocalDateTime requestedAt; // 결제 제공자 측에 기록된 요청 시간 + @JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ssXXX") + private LocalDateTime approvedAt; // 결제 제공자 측의 결제 승인 시간 + + @Data + @Builder + @AllArgsConstructor + @NoArgsConstructor + public static class Receipt { + private String url; // 결제 제공자측의 영수증 주소 + } } diff --git a/src/main/java/com/t3t/bookstoreapi/payment/repository/PaymentProviderRepository.java b/src/main/java/com/t3t/bookstoreapi/payment/repository/PaymentProviderRepository.java index 01b7e704..588d2267 100644 --- a/src/main/java/com/t3t/bookstoreapi/payment/repository/PaymentProviderRepository.java +++ b/src/main/java/com/t3t/bookstoreapi/payment/repository/PaymentProviderRepository.java @@ -1,10 +1,11 @@ package com.t3t.bookstoreapi.payment.repository; +import com.t3t.bookstoreapi.payment.constant.PaymentProviderType; import com.t3t.bookstoreapi.payment.model.entity.PaymentProvider; import org.springframework.data.jpa.repository.JpaRepository; import java.util.Optional; public interface PaymentProviderRepository extends JpaRepository{ - Optional findByName(String providerName); + Optional findByName(PaymentProviderType providerName); } diff --git a/src/main/java/com/t3t/bookstoreapi/payment/service/TossPaymentService.java b/src/main/java/com/t3t/bookstoreapi/payment/service/TossPaymentService.java index 495410b9..7c1e557e 100644 --- a/src/main/java/com/t3t/bookstoreapi/payment/service/TossPaymentService.java +++ b/src/main/java/com/t3t/bookstoreapi/payment/service/TossPaymentService.java @@ -39,7 +39,7 @@ public PaymentConfirmResponse confirmPayment(PaymentConfirmRequest paymentReques @Override public PaymentDto createPayment(PaymentCreationRequest request) { - PaymentProvider paymentProvider = paymentProviderRepository.findByName(PaymentProviderType.TOSS.toString()) + PaymentProvider paymentProvider = paymentProviderRepository.findByName(PaymentProviderType.TOSS) .orElseThrow(() -> new PaymentProviderNotFoundForNameException(PaymentProviderType.TOSS.toString())); Order order = orderRepository.findById(request.getOrderId()) diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 58f5972a..97fad2b6 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -28,7 +28,11 @@ spring: mvc: path-match: matching-strategy: ant_path_matcher - + jpa: + properties: + hibernate: + show_sql: true + format_sql: true t3t: message: hookUrl: "https://hook.dooray.com/services/3204376758577275363/3740692380402107577/BVSloNkTRAqQg_rv1asoNQ" diff --git a/src/test/java/com/t3t/bookstoreapi/order/repository/OrderDetailRepositoryTest.java b/src/test/java/com/t3t/bookstoreapi/order/repository/OrderDetailRepositoryTest.java index d93fe80b..68c10098 100644 --- a/src/test/java/com/t3t/bookstoreapi/order/repository/OrderDetailRepositoryTest.java +++ b/src/test/java/com/t3t/bookstoreapi/order/repository/OrderDetailRepositoryTest.java @@ -14,6 +14,7 @@ import com.t3t.bookstoreapi.member.model.entity.MemberGradePolicy; import com.t3t.bookstoreapi.order.model.dto.OrderDetailDto; import com.t3t.bookstoreapi.order.model.entity.*; +import com.t3t.bookstoreapi.order.model.response.OrderDetailInfoResponse; import com.t3t.bookstoreapi.property.SecretKeyManagerProperties; import com.t3t.bookstoreapi.property.SecretKeyProperties; import com.t3t.bookstoreapi.publisher.model.entity.Publisher; @@ -192,7 +193,7 @@ void getOrderDetailDtoByIdTest() { * 주문 식별자로 주문 상세 조회 DTO 리스트 조회 * * @author woody35545(구건모) - * @see OrderDetailRepositoryCustom#getOrderDetailDtoListByOrderId(long) + * @see OrderDetailRepositoryCustom#getOrderDetailInfoResponseListByOrderId(long) */ @Disabled /* 다른 브랜치에서 작업하던 내용에서 데이터베이스 스키마가 변경됨에 따라서, 해당 브랜치가 merge 되기 전까지 테스트를 비활성화. */ @Test @@ -229,27 +230,27 @@ void getOrderDetailDtoListByOrderIdTest() { // when - final List orderDetailDtoList = orderDetailRepository.getOrderDetailDtoListByOrderId(testOrder.getId()); + final List orderDetailInfoResponseList = orderDetailRepository.getOrderDetailInfoResponseListByOrderId(testOrder.getId()); - orderDetailDtoList.sort((o1, o2) -> (int) (o1.getId() - o2.getId())); + orderDetailInfoResponseList.sort((o1, o2) -> (int) (o1.getId() - o2.getId())); // then - assertEquals(testOrderDetailList.size(), orderDetailDtoList.size()); + assertEquals(testOrderDetailList.size(), orderDetailInfoResponseList.size()); for (int i = 0; i < testOrderDetailList.size(); i++) { - log.info("OrderDetailDto => {}", orderDetailDtoList.get(i)); - assertEquals(testOrderDetailList.get(i).getId(), orderDetailDtoList.get(i).getId()); - assertEquals(testOrderDetailList.get(i).getQuantity(), orderDetailDtoList.get(i).getQuantity()); - assertEquals(testOrderDetailList.get(i).getCreatedAt(), orderDetailDtoList.get(i).getCreatedAt()); - assertEquals(testOrderDetailList.get(i).getOrder().getId(), orderDetailDtoList.get(i).getOrderId()); - assertEquals(testOrderDetailList.get(i).getBook().getBookId(), orderDetailDtoList.get(i).getBookId()); - assertEquals(testOrderDetailList.get(i).getBook().getBookName(), orderDetailDtoList.get(i).getBookName()); - assertEquals(testOrderDetailList.get(i).getBook().getPublisher().getPublisherName(), orderDetailDtoList.get(i).getBookPublisherName()); + log.info("OrderDetailDto => {}", orderDetailInfoResponseList.get(i)); + assertEquals(testOrderDetailList.get(i).getId(), orderDetailInfoResponseList.get(i).getId()); + assertEquals(testOrderDetailList.get(i).getQuantity(), orderDetailInfoResponseList.get(i).getQuantity()); + assertEquals(testOrderDetailList.get(i).getCreatedAt(), orderDetailInfoResponseList.get(i).getCreatedAt()); + assertEquals(testOrderDetailList.get(i).getOrder().getId(), orderDetailInfoResponseList.get(i).getOrderId()); + assertEquals(testOrderDetailList.get(i).getBook().getBookId(), orderDetailInfoResponseList.get(i).getBookId()); + assertEquals(testOrderDetailList.get(i).getBook().getBookName(), orderDetailInfoResponseList.get(i).getBookName()); + assertEquals(testOrderDetailList.get(i).getBook().getPublisher().getPublisherName(), orderDetailInfoResponseList.get(i).getBookPublisherName()); // assertEquals(testOrderDetailList.get(i).getBook().getBookPrice(), orderDetailDtoList.get(i).getBookPrice()); // assertEquals(testOrderDetailList.get(i).getBook().getBookDiscount(), orderDetailDtoList.get(i).getBookDiscount()); - assertEquals(testOrderDetailList.get(i).getPackaging().getName(), orderDetailDtoList.get(i).getPackagingName()); - assertEquals(testOrderDetailList.get(i).getPackaging().getPrice(), orderDetailDtoList.get(i).getPackagingPrice()); - assertEquals(testOrderDetailList.get(i).getOrderStatus().getName(), orderDetailDtoList.get(i).getOrderStatusName()); + assertEquals(testOrderDetailList.get(i).getPackaging().getName(), orderDetailInfoResponseList.get(i).getPackagingName()); + assertEquals(testOrderDetailList.get(i).getPackaging().getPrice(), orderDetailInfoResponseList.get(i).getPackagingPrice()); + assertEquals(testOrderDetailList.get(i).getOrderStatus().getName(), orderDetailInfoResponseList.get(i).getOrderStatusName()); } } diff --git a/src/test/java/com/t3t/bookstoreapi/order/servcie/OrderDetailServiceUnitTest.java b/src/test/java/com/t3t/bookstoreapi/order/servcie/OrderDetailServiceUnitTest.java index 46a8ddb6..513e34a6 100644 --- a/src/test/java/com/t3t/bookstoreapi/order/servcie/OrderDetailServiceUnitTest.java +++ b/src/test/java/com/t3t/bookstoreapi/order/servcie/OrderDetailServiceUnitTest.java @@ -1,6 +1,7 @@ package com.t3t.bookstoreapi.order.servcie; import com.t3t.bookstoreapi.order.model.dto.OrderDetailDto; +import com.t3t.bookstoreapi.order.model.response.OrderDetailInfoResponse; import com.t3t.bookstoreapi.order.repository.OrderDetailRepository; import com.t3t.bookstoreapi.order.service.OrderDetailService; import org.junit.jupiter.api.DisplayName; @@ -11,6 +12,7 @@ import org.mockito.junit.jupiter.MockitoExtension; import java.math.BigDecimal; +import java.time.LocalDate; import java.time.LocalDateTime; import java.util.List; import java.util.Optional; @@ -75,16 +77,16 @@ void getOrderDetailDtoByIdTest() { /** - * 주문 상세 조회 - 주문 식별자로 주문 상세 리스트 조회 - * @see OrderDetailService#getOrderDetailDtoListByOrderId(long) + * 주문 상세 조회 - 주문 식별자로 주문 상세에 대한 정보 리스트 조회 + * * @author woody35545(구건모) */ @Test @DisplayName("주문 상세 조회 - 주문 식별자로 주문 상세 리스트 조회") - void getOrderDetailDtoListByOrderIdTest() { + void getOrderDetailInfoResponseListByOrderIdTest() { // given long orderId = 0L; - OrderDetailDto testOrderDetailDto = OrderDetailDto.builder() + OrderDetailInfoResponse testOrderDetailDto = OrderDetailInfoResponse.builder() .id(0L) .quantity(1) .createdAt(LocalDateTime.now()) @@ -92,33 +94,36 @@ void getOrderDetailDtoListByOrderIdTest() { .bookId(0L) .bookName("testBookName") .bookPublisherName("testPublisherName") -// .bookDiscount(new BigDecimal("0")) -// .bookPrice(new BigDecimal("10000")) .packagingName("testPackagingName") .packagingPrice(new BigDecimal("1000")) .orderStatusName("testOrderStatusName") + .deliveryId(0L) + .deliveryPrice(new BigDecimal("3000")) + .addressNumber(12345) + .recipientName("testRecipientName") + .roadnameAddress("testRoadnameAddress") + .deliveryDate(LocalDate.of(2030, 5, 1)) + .recipientPhoneNumber("010-1234-5678") .build(); - when(orderDetailRepository.getOrderDetailDtoListByOrderId(orderId)).thenReturn( + when(orderDetailRepository.getOrderDetailInfoResponseListByOrderId(orderId)).thenReturn( List.of(testOrderDetailDto)); // when - List resultOrderDetailDtoList = orderDetailService.getOrderDetailDtoListByOrderId(orderId); + List resultOrderDetailInfoResponseList = orderDetailService.getOrderDetailInfoResponse(orderId); // then - assertEquals(1, resultOrderDetailDtoList.size()); - assertEquals(testOrderDetailDto, resultOrderDetailDtoList.get(0)); - assertEquals(testOrderDetailDto.getId(), resultOrderDetailDtoList.get(0).getId()); - assertEquals(testOrderDetailDto.getQuantity(), resultOrderDetailDtoList.get(0).getQuantity()); - assertEquals(testOrderDetailDto.getCreatedAt(), resultOrderDetailDtoList.get(0).getCreatedAt()); - assertEquals(testOrderDetailDto.getOrderId(), resultOrderDetailDtoList.get(0).getOrderId()); - assertEquals(testOrderDetailDto.getBookId(), resultOrderDetailDtoList.get(0).getBookId()); - assertEquals(testOrderDetailDto.getBookName(), resultOrderDetailDtoList.get(0).getBookName()); - assertEquals(testOrderDetailDto.getBookPublisherName(), resultOrderDetailDtoList.get(0).getBookPublisherName()); -// assertEquals(testOrderDetailDto.getBookPrice(), resultOrderDetailDtoList.get(0).getBookPrice()); -// assertEquals(testOrderDetailDto.getBookDiscount(), resultOrderDetailDtoList.get(0).getBookDiscount()); - assertEquals(testOrderDetailDto.getPackagingName(), resultOrderDetailDtoList.get(0).getPackagingName()); - assertEquals(testOrderDetailDto.getPackagingPrice(), resultOrderDetailDtoList.get(0).getPackagingPrice()); - assertEquals(testOrderDetailDto.getOrderStatusName(), resultOrderDetailDtoList.get(0).getOrderStatusName()); + assertEquals(1, resultOrderDetailInfoResponseList.size()); + assertEquals(testOrderDetailDto, resultOrderDetailInfoResponseList.get(0)); + assertEquals(testOrderDetailDto.getId(), resultOrderDetailInfoResponseList.get(0).getId()); + assertEquals(testOrderDetailDto.getQuantity(), resultOrderDetailInfoResponseList.get(0).getQuantity()); + assertEquals(testOrderDetailDto.getCreatedAt(), resultOrderDetailInfoResponseList.get(0).getCreatedAt()); + assertEquals(testOrderDetailDto.getOrderId(), resultOrderDetailInfoResponseList.get(0).getOrderId()); + assertEquals(testOrderDetailDto.getBookId(), resultOrderDetailInfoResponseList.get(0).getBookId()); + assertEquals(testOrderDetailDto.getBookName(), resultOrderDetailInfoResponseList.get(0).getBookName()); + assertEquals(testOrderDetailDto.getBookPublisherName(), resultOrderDetailInfoResponseList.get(0).getBookPublisherName()); + assertEquals(testOrderDetailDto.getPackagingName(), resultOrderDetailInfoResponseList.get(0).getPackagingName()); + assertEquals(testOrderDetailDto.getPackagingPrice(), resultOrderDetailInfoResponseList.get(0).getPackagingPrice()); + assertEquals(testOrderDetailDto.getOrderStatusName(), resultOrderDetailInfoResponseList.get(0).getOrderStatusName()); } }