From 09bf1f94518b50d4c3968512ead9c830fafbd262 Mon Sep 17 00:00:00 2001 From: subin Date: Tue, 2 Jul 2024 00:23:11 +0900 Subject: [PATCH 01/18] =?UTF-8?q?refactor:=20=EC=A3=BC=EB=AC=B8=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EC=88=98=EC=A0=95(OrderDetailList?= =?UTF-8?q?=EC=99=80=20Member,=20Address,=20ProductLine=EC=9D=98=20?= =?UTF-8?q?=ED=95=84=EB=93=9C=EA=B0=92=20=EB=8F=99=EC=8B=9C=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../order/dto/reponse/QOrderResponse.java | 21 +++++++++++++++++++ .../orderDetail/dto/QOrderDetailDTO.java | 21 +++++++++++++++++++ .../repository/order/JpaOrderRepository.java | 1 + .../repository/order/OrderRepository.java | 1 + .../OrderEntityRepositoryCustomImpl.java | 2 ++ .../clothstar/order/service/OrderService.java | 3 +++ 6 files changed, 49 insertions(+) create mode 100644 src/main/generated/org/store/clothstar/order/dto/reponse/QOrderResponse.java create mode 100644 src/main/generated/org/store/clothstar/orderDetail/dto/QOrderDetailDTO.java diff --git a/src/main/generated/org/store/clothstar/order/dto/reponse/QOrderResponse.java b/src/main/generated/org/store/clothstar/order/dto/reponse/QOrderResponse.java new file mode 100644 index 00000000..a41b13b0 --- /dev/null +++ b/src/main/generated/org/store/clothstar/order/dto/reponse/QOrderResponse.java @@ -0,0 +1,21 @@ +package org.store.clothstar.order.dto.reponse; + +import com.querydsl.core.types.dsl.*; + +import com.querydsl.core.types.ConstructorExpression; +import javax.annotation.processing.Generated; + +/** + * org.store.clothstar.order.dto.reponse.QOrderResponse is a Querydsl Projection type for OrderResponse + */ +@Generated("com.querydsl.codegen.DefaultProjectionSerializer") +public class QOrderResponse extends ConstructorExpression { + + private static final long serialVersionUID = -1258133913L; + + public QOrderResponse(com.querydsl.core.types.Expression orderEntity, com.querydsl.core.types.Expression orderDetailEntity, com.querydsl.core.types.Expression memberEntity, com.querydsl.core.types.Expression addressEntity, com.querydsl.core.types.Expression productLineEntity) { + super(OrderResponse.class, new Class[]{org.store.clothstar.order.entity.OrderEntity.class, org.store.clothstar.orderDetail.entity.OrderDetailEntity.class, org.store.clothstar.member.entity.MemberEntity.class, org.store.clothstar.member.entity.AddressEntity.class, org.store.clothstar.productLine.entity.ProductLineEntity.class}, orderEntity, orderDetailEntity, memberEntity, addressEntity, productLineEntity); + } + +} + diff --git a/src/main/generated/org/store/clothstar/orderDetail/dto/QOrderDetailDTO.java b/src/main/generated/org/store/clothstar/orderDetail/dto/QOrderDetailDTO.java new file mode 100644 index 00000000..bc407ada --- /dev/null +++ b/src/main/generated/org/store/clothstar/orderDetail/dto/QOrderDetailDTO.java @@ -0,0 +1,21 @@ +package org.store.clothstar.orderDetail.dto; + +import com.querydsl.core.types.dsl.*; + +import com.querydsl.core.types.ConstructorExpression; +import javax.annotation.processing.Generated; + +/** + * org.store.clothstar.orderDetail.dto.QOrderDetailDTO is a Querydsl Projection type for OrderDetailDTO + */ +@Generated("com.querydsl.codegen.DefaultProjectionSerializer") +public class QOrderDetailDTO extends ConstructorExpression { + + private static final long serialVersionUID = -767891785L; + + public QOrderDetailDTO(com.querydsl.core.types.Expression orderDetailEntity) { + super(OrderDetailDTO.class, new Class[]{org.store.clothstar.orderDetail.entity.OrderDetailEntity.class}, orderDetailEntity); + } + +} + diff --git a/src/main/java/org/store/clothstar/order/repository/order/JpaOrderRepository.java b/src/main/java/org/store/clothstar/order/repository/order/JpaOrderRepository.java index 7edc26d8..7046060c 100644 --- a/src/main/java/org/store/clothstar/order/repository/order/JpaOrderRepository.java +++ b/src/main/java/org/store/clothstar/order/repository/order/JpaOrderRepository.java @@ -5,6 +5,7 @@ import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.transaction.annotation.Transactional; +import org.store.clothstar.order.dto.reponse.OrderResponse; import org.store.clothstar.order.entity.OrderEntity; import org.store.clothstar.order.repository.orderSeller.OrderEntityRepositoryCustom; diff --git a/src/main/java/org/store/clothstar/order/repository/order/OrderRepository.java b/src/main/java/org/store/clothstar/order/repository/order/OrderRepository.java index ca187a8b..1eac0d8e 100644 --- a/src/main/java/org/store/clothstar/order/repository/order/OrderRepository.java +++ b/src/main/java/org/store/clothstar/order/repository/order/OrderRepository.java @@ -3,6 +3,7 @@ import org.store.clothstar.order.dto.reponse.OrderResponse; import org.store.clothstar.order.entity.OrderEntity; +import java.util.List; import java.util.Optional; public interface OrderRepository { diff --git a/src/main/java/org/store/clothstar/order/repository/orderSeller/OrderEntityRepositoryCustomImpl.java b/src/main/java/org/store/clothstar/order/repository/orderSeller/OrderEntityRepositoryCustomImpl.java index 0312eb97..cfe15a2c 100644 --- a/src/main/java/org/store/clothstar/order/repository/orderSeller/OrderEntityRepositoryCustomImpl.java +++ b/src/main/java/org/store/clothstar/order/repository/orderSeller/OrderEntityRepositoryCustomImpl.java @@ -16,6 +16,8 @@ import org.store.clothstar.productLine.entity.QProductLineEntity; import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; @Repository @RequiredArgsConstructor diff --git a/src/main/java/org/store/clothstar/order/service/OrderService.java b/src/main/java/org/store/clothstar/order/service/OrderService.java index 0f39d5b4..209f5b64 100644 --- a/src/main/java/org/store/clothstar/order/service/OrderService.java +++ b/src/main/java/org/store/clothstar/order/service/OrderService.java @@ -1,6 +1,7 @@ package org.store.clothstar.order.service; import lombok.extern.slf4j.Slf4j; +import org.hibernate.query.Order; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; @@ -17,6 +18,8 @@ import org.store.clothstar.order.type.Status; import org.store.clothstar.orderDetail.service.OrderDetailService; +import java.util.Optional; + @Slf4j @Service public class OrderService { From aedd3b350423e182b005f44a7c5aa69cb9b13bb2 Mon Sep 17 00:00:00 2001 From: subin Date: Wed, 3 Jul 2024 04:05:07 +0900 Subject: [PATCH 02/18] =?UTF-8?q?feature:=20=ED=8E=98=EC=9D=B4=EC=A7=95=20?= =?UTF-8?q?-=20findAll()=20=EC=9D=B4=EC=9A=A9,=20orderDetailList=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20=EC=A0=84.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/config/SecurityConfiguration.java | 2 + .../order/controller/OrderController.java | 30 ++++++- .../order/dto/reponse/OrderPageResponse.java | 78 +++++++++++++++++++ .../order/dto/reponse/OrderResponse.java | 15 ++-- .../repository/order/JpaOrderRepository.java | 7 ++ .../repository/order/OrderRepository.java | 9 ++- .../clothstar/order/service/OrderService.java | 14 ++++ 7 files changed, 141 insertions(+), 14 deletions(-) create mode 100644 src/main/java/org/store/clothstar/order/dto/reponse/OrderPageResponse.java diff --git a/src/main/java/org/store/clothstar/common/config/SecurityConfiguration.java b/src/main/java/org/store/clothstar/common/config/SecurityConfiguration.java index d1b1b236..bb974fdb 100644 --- a/src/main/java/org/store/clothstar/common/config/SecurityConfiguration.java +++ b/src/main/java/org/store/clothstar/common/config/SecurityConfiguration.java @@ -56,6 +56,8 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { , "/v1/members/login", "/signup", "/v1/members/email/**", "/v1/access", "/v1/categories/**", "/v1/products/**", "/v1/productLines/**", "/v2/productLines/**", "/v1/orderdetails", "/v1/orders", "membersPagingOffset", "membersPagingSlice", + "/v1/orderdetails", "/v1/orders", "/v2/orders", "/v3/orders", "/v1/orders/list", + "/v1/orders/list","/ordersPagingOffset","/ordersPagingSlice","/v2/orders/list", "/v1/seller/orders/**", "/v1/seller/orders", "/v1/orders/**", "/swagger-resources/**", "/swagger-ui/**", "/v3/api-docs/**", "/v1/members/auth/**" ).permitAll() diff --git a/src/main/java/org/store/clothstar/order/controller/OrderController.java b/src/main/java/org/store/clothstar/order/controller/OrderController.java index 6fe7b1f7..24459599 100644 --- a/src/main/java/org/store/clothstar/order/controller/OrderController.java +++ b/src/main/java/org/store/clothstar/order/controller/OrderController.java @@ -3,11 +3,17 @@ import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Slice; +import org.springframework.data.web.PageableDefault; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import org.store.clothstar.common.dto.MessageDTO; +import org.store.clothstar.member.dto.response.MemberResponse; +import org.store.clothstar.order.dto.reponse.OrderPageResponse; import org.store.clothstar.order.dto.reponse.OrderResponse; import org.store.clothstar.order.dto.request.OrderRequestWrapper; import org.store.clothstar.order.service.OrderApplicationService; @@ -21,21 +27,37 @@ @Tag(name = "Order", description = "주문(Order) 정보 관리에 대한 API 입니다.") @RestController @RequiredArgsConstructor -@RequestMapping("/v1/orders") +//@RequestMapping("/v1/orders") public class OrderController { private final OrderService orderService; private final OrderApplicationService orderApplicationService; @Operation(summary = "단일 주문 조회", description = "단일 주문의 정보를 조회한다.") - @GetMapping("/{orderId}") + @GetMapping("/v1/orders/{orderId}") public ResponseEntity getOrder(@Validated @PathVariable Long orderId) { OrderResponse orderResponse = orderService.getOrder(orderId); return ResponseEntity.ok(orderResponse); } + @Operation(summary = "전체 주문 조회 offset 페이징", description = "전체 주문 리스트를 offset 페이징 형식으로 가져온다.") + @GetMapping("/v1/orders/list") + public ResponseEntity> getAllOrderOffsetPaging( + @PageableDefault(size = 15) Pageable pageable) { + Page orderPages = orderService.getAllOrderOffsetPaging(pageable); + return ResponseEntity.ok(orderPages); + } + + @Operation(summary = "전체 주문 조회 slice 페이징", description = "전체 주문 리스트를 slice 페이징 형식으로 가져온다.") + @GetMapping("/v2/orders/list") + public ResponseEntity> getAllOrderSlicePaging( + @PageableDefault(size = 15) Pageable pageable) { + Slice orderPages = orderService.getAllOrderSlicePaging(pageable); + return ResponseEntity.ok(orderPages); + } + @Operation(summary = "주문 생성", description = "단일 주문을 생성한다.") - @PostMapping + @PostMapping("/v1/orders") public ResponseEntity saveOrder(@RequestBody @Validated OrderRequestWrapper orderRequestWrapper) { Long orderId = orderApplicationService.saveOrderWithTransaction(orderRequestWrapper); URI location = URIBuilder.buildURI(orderId); @@ -43,7 +65,7 @@ public ResponseEntity saveOrder(@RequestBody @Validated OrderRequestWrapper } @Operation(summary = "구매 확정", description = "구매자가 구매 확정 시, 주문상태가 '구매확정'으로 변경된다.") - @PatchMapping("/{orderId}") + @PatchMapping("/v1/orders/{orderId}") public ResponseEntity deliveredToConfirmOrder(@PathVariable Long orderId) { orderService.deliveredToConfirmOrder(orderId); return ResponseEntity.ok(new MessageDTO(HttpStatus.OK.value(), "주문이 정상적으로 구매 확정 되었습니다.")); diff --git a/src/main/java/org/store/clothstar/order/dto/reponse/OrderPageResponse.java b/src/main/java/org/store/clothstar/order/dto/reponse/OrderPageResponse.java new file mode 100644 index 00000000..0ff8163e --- /dev/null +++ b/src/main/java/org/store/clothstar/order/dto/reponse/OrderPageResponse.java @@ -0,0 +1,78 @@ +package org.store.clothstar.order.dto.reponse; + +import com.querydsl.core.annotations.QueryProjection; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import org.store.clothstar.member.entity.AddressEntity; +import org.store.clothstar.member.entity.MemberEntity; +import org.store.clothstar.order.entity.OrderEntity; +import org.store.clothstar.order.type.PaymentMethod; +import org.store.clothstar.order.type.Status; +import org.store.clothstar.orderDetail.dto.OrderDetailDTO; +import org.store.clothstar.orderDetail.entity.OrderDetailEntity; +import org.store.clothstar.productLine.entity.ProductLineEntity; + +import java.time.LocalDate; +import java.util.ArrayList; +import java.util.List; + +@Getter +@Builder +@AllArgsConstructor +@NoArgsConstructor +@Schema(description = "주문 페이지 조회용 Response") +public class OrderPageResponse { + @Schema(description = "주문 id", example = "1") + private Long orderId; + + @Schema(description = "주문자 이름", example = "수빈") + private String ordererName; + + @Schema(description = "주문 생성 날짜", example = "2024-05-15") + private LocalDate createdAt; + + @Schema(description = "주문 상태", example = "WAITING") + private Status status; + + //address + private String receiverName; + private String addressBasic; + private String addressDetail; + private String telNo; + private String deliveryRequest; + + @Schema(description = "결제 수단", example = "CARD") + private PaymentMethod paymentMethod; + + @Schema(description = "총 배송비", example = "3000") + private int totalShippingPrice; + + @Schema(description = "총 상품 금액", example = "15000") + private int totalProductsPrice; + + @Schema(description = "총 결제 금액", example = "18000") + private int totalPaymentPrice; + + private List orderDetails; + + public static OrderPageResponse from(OrderEntity orderEntity) { + return OrderPageResponse.builder() + .orderId(orderEntity.getOrderId()) + .ordererName(orderEntity.getMember().getName()) + .createdAt(orderEntity.getCreatedAt().toLocalDate()) + .status(orderEntity.getStatus()) + .totalShippingPrice(orderEntity.getTotalShippingPrice()) + .totalProductsPrice(orderEntity.getTotalProductsPrice()) + .paymentMethod(orderEntity.getPaymentMethod()) + .totalPaymentPrice(orderEntity.getTotalPaymentPrice()) + .telNo(orderEntity.getAddress().getTelNo()) + .deliveryRequest(orderEntity.getAddress().getDeliveryRequest()) + .receiverName(orderEntity.getAddress().getReceiverName()) + .addressBasic(orderEntity.getAddress().getAddressBasic()) + .addressDetail(orderEntity.getAddress().getAddressDetail()) + .build(); + } +} diff --git a/src/main/java/org/store/clothstar/order/dto/reponse/OrderResponse.java b/src/main/java/org/store/clothstar/order/dto/reponse/OrderResponse.java index b7304229..5ad1e325 100644 --- a/src/main/java/org/store/clothstar/order/dto/reponse/OrderResponse.java +++ b/src/main/java/org/store/clothstar/order/dto/reponse/OrderResponse.java @@ -60,15 +60,6 @@ public class OrderResponse { @Builder.Default private List orderDetailList = new ArrayList<>(); - public OrderResponse(OrderEntity orderEntity, OrderDetailEntity orderDetailEntity, MemberEntity memberEntity, AddressEntity addressEntity, - ProductLineEntity productLineEntity, List orderDetailList) { - this(orderEntity, - orderDetailEntity, - memberEntity, addressEntity, productLineEntity); - this.orderDetailList = orderDetailList != null ? orderDetailList : new ArrayList<>(); - } - - @QueryProjection public OrderResponse(OrderEntity orderEntity, OrderDetailEntity orderDetailEntity, @@ -100,6 +91,12 @@ public static OrderResponse fromOrderEntity(OrderEntity orderEntity) { .totalProductsPrice(orderEntity.getTotalProductsPrice()) .paymentMethod(orderEntity.getPaymentMethod()) .totalPaymentPrice(orderEntity.getTotalPaymentPrice()) + .telNo(orderEntity.getAddress().getTelNo()) + .deliveryRequest(orderEntity.getAddress().getDeliveryRequest()) + .receiverName(orderEntity.getAddress().getReceiverName()) + .addressBasic(orderEntity.getAddress().getAddressBasic()) + .addressDetail(orderEntity.getAddress().getAddressDetail()) +// .orderDetailList(orderEntity.getOrderDetails().) .build(); } diff --git a/src/main/java/org/store/clothstar/order/repository/order/JpaOrderRepository.java b/src/main/java/org/store/clothstar/order/repository/order/JpaOrderRepository.java index 7046060c..c557e282 100644 --- a/src/main/java/org/store/clothstar/order/repository/order/JpaOrderRepository.java +++ b/src/main/java/org/store/clothstar/order/repository/order/JpaOrderRepository.java @@ -1,5 +1,8 @@ package org.store.clothstar.order.repository.order; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Slice; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; @@ -11,6 +14,10 @@ public interface JpaOrderRepository extends JpaRepository, OrderRepository, OrderEntityRepositoryCustom { + @Query(value = "SELECT o FROM orders o", + countQuery = "select count(o) from orders o") + Slice findAllSlicePaging(Pageable pageable); + @Transactional @Modifying @Query("UPDATE orders o SET o.status ='CONFIRM' WHERE o.orderId = :orderId") diff --git a/src/main/java/org/store/clothstar/order/repository/order/OrderRepository.java b/src/main/java/org/store/clothstar/order/repository/order/OrderRepository.java index 1eac0d8e..6c9a9931 100644 --- a/src/main/java/org/store/clothstar/order/repository/order/OrderRepository.java +++ b/src/main/java/org/store/clothstar/order/repository/order/OrderRepository.java @@ -1,5 +1,9 @@ package org.store.clothstar.order.repository.order; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Slice; +import org.store.clothstar.member.entity.MemberEntity; import org.store.clothstar.order.dto.reponse.OrderResponse; import org.store.clothstar.order.entity.OrderEntity; @@ -12,8 +16,11 @@ public interface OrderRepository { OrderResponse findOrderWithDetails(Long orderId); + Page findAll(Pageable pageable); + + Slice findAllSlicePaging(Pageable pageable); + OrderEntity save(OrderEntity orderEntity); void deliveredToConfirmOrder(Long orderId); - } diff --git a/src/main/java/org/store/clothstar/order/service/OrderService.java b/src/main/java/org/store/clothstar/order/service/OrderService.java index 209f5b64..4af524fb 100644 --- a/src/main/java/org/store/clothstar/order/service/OrderService.java +++ b/src/main/java/org/store/clothstar/order/service/OrderService.java @@ -3,6 +3,9 @@ import lombok.extern.slf4j.Slf4j; import org.hibernate.query.Order; import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Slice; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -11,6 +14,7 @@ import org.store.clothstar.member.entity.MemberEntity; import org.store.clothstar.member.repository.AddressRepository; import org.store.clothstar.member.repository.MemberRepository; +import org.store.clothstar.order.dto.reponse.OrderPageResponse; import org.store.clothstar.order.dto.reponse.OrderResponse; import org.store.clothstar.order.dto.request.CreateOrderRequest; import org.store.clothstar.order.entity.OrderEntity; @@ -45,6 +49,16 @@ public OrderResponse getOrder(Long orderId) { return orderRepository.findOrderWithDetails(orderId); } + public Page getAllOrderOffsetPaging(Pageable pageable) { + return orderRepository.findAll(pageable) + .map(OrderPageResponse::from); + } + + public Slice getAllOrderSlicePaging(Pageable pageable) { + return orderRepository.findAllSlicePaging(pageable) + .map(OrderPageResponse::from); + } + @Transactional public Long saveOrder(CreateOrderRequest createOrderRequest) { From 1fe22b9459721c67c882c3e19c94020625890678 Mon Sep 17 00:00:00 2001 From: subin Date: Wed, 3 Jul 2024 05:23:01 +0900 Subject: [PATCH 03/18] =?UTF-8?q?feature:=20=ED=8E=98=EC=9D=B4=EC=A7=95=20?= =?UTF-8?q?-=20Offset,=20Slice=20=EB=B0=A9=EC=8B=9D=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EA=B5=AC=EB=B6=84,=20orderDetailList=20=EC=B6=94=EA=B0=80.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../order/controller/OrderController.java | 8 +- .../order/controller/OrderViewController.java | 17 +++ .../repository/order/JpaOrderRepository.java | 4 - .../repository/order/OrderRepository.java | 4 +- .../OrderEntityRepositoryCustom.java | 9 ++ .../OrderEntityRepositoryCustomImpl.java | 102 +++++++++++++- .../clothstar/order/service/OrderService.java | 10 +- src/main/resources/sql/orders.sql | 3 + .../resources/templates/orderOffsetList.html | 131 ++++++++++++++++++ .../resources/templates/orderSliceList.html | 86 ++++++++++++ 10 files changed, 354 insertions(+), 20 deletions(-) create mode 100644 src/main/java/org/store/clothstar/order/controller/OrderViewController.java create mode 100644 src/main/resources/templates/orderOffsetList.html create mode 100644 src/main/resources/templates/orderSliceList.html diff --git a/src/main/java/org/store/clothstar/order/controller/OrderController.java b/src/main/java/org/store/clothstar/order/controller/OrderController.java index 24459599..d5c4ae48 100644 --- a/src/main/java/org/store/clothstar/order/controller/OrderController.java +++ b/src/main/java/org/store/clothstar/order/controller/OrderController.java @@ -42,17 +42,17 @@ public ResponseEntity getOrder(@Validated @PathVariable Long orde @Operation(summary = "전체 주문 조회 offset 페이징", description = "전체 주문 리스트를 offset 페이징 형식으로 가져온다.") @GetMapping("/v1/orders/list") - public ResponseEntity> getAllOrderOffsetPaging( + public ResponseEntity> getAllOrderOffsetPaging( @PageableDefault(size = 15) Pageable pageable) { - Page orderPages = orderService.getAllOrderOffsetPaging(pageable); + Page orderPages = orderService.getAllOrderOffsetPaging(pageable); return ResponseEntity.ok(orderPages); } @Operation(summary = "전체 주문 조회 slice 페이징", description = "전체 주문 리스트를 slice 페이징 형식으로 가져온다.") @GetMapping("/v2/orders/list") - public ResponseEntity> getAllOrderSlicePaging( + public ResponseEntity> getAllOrderSlicePaging( @PageableDefault(size = 15) Pageable pageable) { - Slice orderPages = orderService.getAllOrderSlicePaging(pageable); + Slice orderPages = orderService.getAllOrderSlicePaging(pageable); return ResponseEntity.ok(orderPages); } diff --git a/src/main/java/org/store/clothstar/order/controller/OrderViewController.java b/src/main/java/org/store/clothstar/order/controller/OrderViewController.java new file mode 100644 index 00000000..7e18047c --- /dev/null +++ b/src/main/java/org/store/clothstar/order/controller/OrderViewController.java @@ -0,0 +1,17 @@ +package org.store.clothstar.order.controller; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; + +@Controller +public class OrderViewController { + @GetMapping("/ordersPagingOffset") + public String ordersPagingOffset() { + return "orderOffsetList"; + } + + @GetMapping("/ordersPagingSlice") + public String ordersPagingSlice() { + return "orderSliceList"; + } +} diff --git a/src/main/java/org/store/clothstar/order/repository/order/JpaOrderRepository.java b/src/main/java/org/store/clothstar/order/repository/order/JpaOrderRepository.java index c557e282..c0a81703 100644 --- a/src/main/java/org/store/clothstar/order/repository/order/JpaOrderRepository.java +++ b/src/main/java/org/store/clothstar/order/repository/order/JpaOrderRepository.java @@ -14,10 +14,6 @@ public interface JpaOrderRepository extends JpaRepository, OrderRepository, OrderEntityRepositoryCustom { - @Query(value = "SELECT o FROM orders o", - countQuery = "select count(o) from orders o") - Slice findAllSlicePaging(Pageable pageable); - @Transactional @Modifying @Query("UPDATE orders o SET o.status ='CONFIRM' WHERE o.orderId = :orderId") diff --git a/src/main/java/org/store/clothstar/order/repository/order/OrderRepository.java b/src/main/java/org/store/clothstar/order/repository/order/OrderRepository.java index 6c9a9931..a7f962c5 100644 --- a/src/main/java/org/store/clothstar/order/repository/order/OrderRepository.java +++ b/src/main/java/org/store/clothstar/order/repository/order/OrderRepository.java @@ -16,9 +16,9 @@ public interface OrderRepository { OrderResponse findOrderWithDetails(Long orderId); - Page findAll(Pageable pageable); + Page findAllOffsetPaging(Pageable pageable); - Slice findAllSlicePaging(Pageable pageable); + Slice findAllSlicePaging(Pageable pageable); OrderEntity save(OrderEntity orderEntity); diff --git a/src/main/java/org/store/clothstar/order/repository/orderSeller/OrderEntityRepositoryCustom.java b/src/main/java/org/store/clothstar/order/repository/orderSeller/OrderEntityRepositoryCustom.java index 802b0665..8711a2e5 100644 --- a/src/main/java/org/store/clothstar/order/repository/orderSeller/OrderEntityRepositoryCustom.java +++ b/src/main/java/org/store/clothstar/order/repository/orderSeller/OrderEntityRepositoryCustom.java @@ -1,12 +1,21 @@ package org.store.clothstar.order.repository.orderSeller; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Slice; import org.store.clothstar.order.dto.reponse.OrderResponse; import org.store.clothstar.order.entity.OrderEntity; import java.util.List; public interface OrderEntityRepositoryCustom { + //Order 관련 메서드 OrderResponse findOrderWithDetails(Long orderId); + Page findAllOffsetPaging(Pageable pageable); + + Slice findAllSlicePaging(Pageable pageable); + + //OrderSeller 관련 메서드 List findWaitingOrders(); } diff --git a/src/main/java/org/store/clothstar/order/repository/orderSeller/OrderEntityRepositoryCustomImpl.java b/src/main/java/org/store/clothstar/order/repository/orderSeller/OrderEntityRepositoryCustomImpl.java index cfe15a2c..53d27181 100644 --- a/src/main/java/org/store/clothstar/order/repository/orderSeller/OrderEntityRepositoryCustomImpl.java +++ b/src/main/java/org/store/clothstar/order/repository/orderSeller/OrderEntityRepositoryCustomImpl.java @@ -1,12 +1,15 @@ package org.store.clothstar.order.repository.orderSeller; +import com.querydsl.jpa.impl.JPAQuery; import com.querydsl.jpa.impl.JPAQueryFactory; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.*; import org.springframework.stereotype.Repository; import org.store.clothstar.member.entity.QAddressEntity; import org.store.clothstar.member.entity.QMemberEntity; import org.store.clothstar.order.dto.reponse.OrderResponse; import org.store.clothstar.order.dto.reponse.QOrderResponse; +import org.store.clothstar.order.entity.OrderEntity; import org.store.clothstar.order.entity.QOrderEntity; import org.store.clothstar.order.type.Status; import org.store.clothstar.orderDetail.dto.OrderDetailDTO; @@ -32,12 +35,103 @@ public class OrderEntityRepositoryCustomImpl implements OrderEntityRepositoryCus QProductEntity qProductEntity = QProductEntity.productEntity; QProductLineEntity qProductLineEntity = QProductLineEntity.productLineEntity; + @Override + public Page findAllOffsetPaging(Pageable pageable){ + JPAQuery query = jpaQueryFactory + .select(new QOrderResponse( + qOrderEntity, + qOrderDetailEntity, + qMemberEntity, + qAddressEntity, + qProductLineEntity)) + .from(qOrderEntity) + .innerJoin(qOrderEntity.member, qMemberEntity) + .innerJoin(qOrderEntity.address, qAddressEntity) + .innerJoin(qOrderEntity.orderDetails, qOrderDetailEntity) + .innerJoin(qOrderDetailEntity.product, qProductEntity) + .innerJoin(qProductEntity.productLine, qProductLineEntity) + .where(qOrderEntity.status.eq(Status.WAITING)) + .groupBy(qOrderEntity.orderId); + + // 페이징 적용 + long total = query.fetchCount(); // 전체 레코드 수 + List results = query + .offset(pageable.getOffset()) + .limit(pageable.getPageSize()) + .fetch(); + + // 추가 데이터 처리 + if (results != null) { + results.forEach(result -> { + List orderDetailList = jpaQueryFactory + .select(new QOrderDetailDTO( + qOrderDetailEntity + )) + .from(qOrderDetailEntity) + .where(qOrderDetailEntity.order.orderId.eq(result.getOrderId())) + .fetch(); + + result.setterOrderDetailList(orderDetailList); // setter 메서드 이름 수정 + }); + } + + // Page 객체로 변환하여 반환 + return new PageImpl<>(results, pageable, total); + } + + + @Override + public Slice findAllSlicePaging(Pageable pageable) { + JPAQuery query = jpaQueryFactory + .select(new QOrderResponse( + qOrderEntity, + qOrderDetailEntity, + qMemberEntity, + qAddressEntity, + qProductLineEntity)) + .from(qOrderEntity) + .innerJoin(qOrderEntity.member, qMemberEntity) + .innerJoin(qOrderEntity.address, qAddressEntity) + .innerJoin(qOrderEntity.orderDetails, qOrderDetailEntity) + .innerJoin(qOrderDetailEntity.product, qProductEntity) + .innerJoin(qProductEntity.productLine, qProductLineEntity) + .where(qOrderEntity.status.eq(Status.WAITING)) + .groupBy(qOrderEntity.orderId); + + // 페이징 적용 + List results = query + .offset(pageable.getOffset()) + .limit(pageable.getPageSize() + 1) // 페이지 크기보다 1개 더 가져옴 + .fetch(); + + // 추가 데이터 처리 + if (results != null && !results.isEmpty()) { + results.forEach(result -> { + List orderDetailList = jpaQueryFactory + .select(new QOrderDetailDTO( + qOrderDetailEntity + )) + .from(qOrderDetailEntity) + .where(qOrderDetailEntity.order.orderId.eq(result.getOrderId())) + .fetch(); + + result.setterOrderDetailList(orderDetailList); // setter 메서드 이름 수정 + }); + } + + boolean hasNext = false; + if (results.size() > pageable.getPageSize()) { + results.remove(results.size() - 1); // 마지막 요소 제거 + hasNext = true; + } + + return new SliceImpl<>(results, pageable, hasNext); + } + + + @Override public List findWaitingOrders() { -// return jpaQueryFactory.select(qOrderEntity) -// .from(qOrderEntity) -// .where(qOrderEntity.status.eq(Status.WAITING)) -// .fetch(); List results = jpaQueryFactory .select(new QOrderResponse( qOrderEntity, diff --git a/src/main/java/org/store/clothstar/order/service/OrderService.java b/src/main/java/org/store/clothstar/order/service/OrderService.java index 4af524fb..53ca3c9d 100644 --- a/src/main/java/org/store/clothstar/order/service/OrderService.java +++ b/src/main/java/org/store/clothstar/order/service/OrderService.java @@ -49,14 +49,12 @@ public OrderResponse getOrder(Long orderId) { return orderRepository.findOrderWithDetails(orderId); } - public Page getAllOrderOffsetPaging(Pageable pageable) { - return orderRepository.findAll(pageable) - .map(OrderPageResponse::from); + public Page getAllOrderOffsetPaging(Pageable pageable) { + return orderRepository.findAllOffsetPaging(pageable); } - public Slice getAllOrderSlicePaging(Pageable pageable) { - return orderRepository.findAllSlicePaging(pageable) - .map(OrderPageResponse::from); + public Slice getAllOrderSlicePaging(Pageable pageable) { + return orderRepository.findAllSlicePaging(pageable); } @Transactional diff --git a/src/main/resources/sql/orders.sql b/src/main/resources/sql/orders.sql index 9c43e9bd..506220a2 100644 --- a/src/main/resources/sql/orders.sql +++ b/src/main/resources/sql/orders.sql @@ -30,6 +30,9 @@ where oe1_0.order_id = 202406297932955; select oe1_0.order_id,oe1_0.address_id,oe1_0.created_at,oe1_0.member_id,oe1_0.payment_method,oe1_0.status,oe1_0.total_payment_price,oe1_0.total_products_price,oe1_0.total_shipping_price,od1_0.order_detail_id,od1_0.brand_name,od1_0.fixed_price,od1_0.name,od1_0.onekind_total_price,od1_0.option_name,od1_0.product_id,od1_0.product_line_id,od1_0.quantity,od1_0.stock,m1_0.member_id,m1_0.created_at,m1_0.deleted_at,m1_0.email,m1_0.grade,m1_0.name,m1_0.password,m1_0.point,m1_0.role,m1_0.tel_no,m1_0.total_payment_price,m1_0.updated_at,a1_0.address_id,a1_0.address_basic,a1_0.address_detail,a1_0.default_address,a1_0.delivery_request,a1_0.member_id,a1_0.receiver_name,a1_0.tel_no,a1_0.zip_no,pl1_0.product_line_id,pl1_0.category_id,pl1_0.content,pl1_0.created_at,pl1_0.deleted_at,pl1_0.modified_at,pl1_0.name,pl1_0.price,pl1_0.sale_count,pl1_0.member_id,pl1_0.status,pl1_0.total_stock from orders oe1_0 join member m1_0 on m1_0.member_id=oe1_0.member_id join address a1_0 on a1_0.address_id=oe1_0.address_id join order_detail od1_0 on oe1_0.order_id=od1_0.order_id join product p1_0 on p1_0.product_id=od1_0.product_id join product_line pl1_0 on pl1_0.product_line_id=p1_0.product_line_id where oe1_0.order_id=202406297932955 group by oe1_0.order_id; +select ae1_0.address_id,ae1_0.address_basic,ae1_0.address_detail,ae1_0.default_address,ae1_0.delivery_request,m1_0.member_id,m1_0.created_at,m1_0.deleted_at,m1_0.email,m1_0.grade,m1_0.name,m1_0.password,m1_0.point,m1_0.role,m1_0.tel_no,m1_0.total_payment_price,m1_0.updated_at,ae1_0.receiver_name,ae1_0.tel_no,ae1_0.zip_no from address ae1_0 left join member m1_0 on m1_0.member_id=ae1_0.member_id where ae1_0.address_id=8; + +select ode1_0.order_detail_id,ode1_0.brand_name,ode1_0.fixed_price,ode1_0.name,ode1_0.onekind_total_price,ode1_0.option_name,ode1_0.order_id,ode1_0.product_id,ode1_0.product_line_id,ode1_0.quantity,ode1_0.stock from order_detail ode1_0 where ode1_0.order_id=202407037765571; select * diff --git a/src/main/resources/templates/orderOffsetList.html b/src/main/resources/templates/orderOffsetList.html new file mode 100644 index 00000000..ce644fcb --- /dev/null +++ b/src/main/resources/templates/orderOffsetList.html @@ -0,0 +1,131 @@ + + + + Orders List + + + + +
+

Orders List

+ + + + + + + + + + + + + +
IDStatusCreated AtBrand NamesOption Names
+ +
+ + + + diff --git a/src/main/resources/templates/orderSliceList.html b/src/main/resources/templates/orderSliceList.html new file mode 100644 index 00000000..71e1b832 --- /dev/null +++ b/src/main/resources/templates/orderSliceList.html @@ -0,0 +1,86 @@ + + + + Orders List + + + + +
+

Orders List

+ + + + + + + + + + + + + +
IDStatusCreated AtBrand NamesOption Names
+
+ + + + + From 5a46af72dfc73fc9b06f8c4627ea920f910e5bff Mon Sep 17 00:00:00 2001 From: subin Date: Wed, 3 Jul 2024 10:59:44 +0900 Subject: [PATCH 04/18] =?UTF-8?q?refactor:=20restoreProductStock()=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 반복문 -> forEach를 이용하여 수정 --- .../clothstar/product/service/ProductService.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/store/clothstar/product/service/ProductService.java b/src/main/java/org/store/clothstar/product/service/ProductService.java index fb5c8deb..d6ed3ce5 100644 --- a/src/main/java/org/store/clothstar/product/service/ProductService.java +++ b/src/main/java/org/store/clothstar/product/service/ProductService.java @@ -75,14 +75,11 @@ public void deleteProduct(Long productId) { } @Transactional - public void restoreProductStock( - List orderDetailList - ) { - ProductEntity productEntity; - for (OrderDetailEntity orderDetailEntity : orderDetailList) { - productEntity = productJPARepository.findById(orderDetailEntity.getProduct().getProductId()) + public void restoreProductStock(List orderDetailList) { + orderDetailList.forEach(orderDetailEntity -> { + ProductEntity productEntity = productJPARepository.findById(orderDetailEntity.getProduct().getProductId()) .orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "상품 정보를 찾을 수 없습니다.")); productEntity.restoreStock(orderDetailEntity.getQuantity()); - } + }); } } From cef8e8c4b500efdb17d92279ec79234e7d8fe72d Mon Sep 17 00:00:00 2001 From: subin Date: Wed, 3 Jul 2024 13:57:28 +0900 Subject: [PATCH 05/18] =?UTF-8?q?test:=20=ED=8E=98=EC=9D=B4=EC=A7=95=20?= =?UTF-8?q?=EA=B4=80=EB=A0=A8=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../order/service/OrderServiceTest.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/test/java/org/store/clothstar/order/service/OrderServiceTest.java b/src/test/java/org/store/clothstar/order/service/OrderServiceTest.java index 51a95979..9a9b5bc8 100644 --- a/src/test/java/org/store/clothstar/order/service/OrderServiceTest.java +++ b/src/test/java/org/store/clothstar/order/service/OrderServiceTest.java @@ -6,6 +6,9 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Slice; import org.springframework.web.server.ResponseStatusException; import org.store.clothstar.member.domain.Address; import org.store.clothstar.member.domain.Member; @@ -59,6 +62,33 @@ void getOrder_test() { assertThat(orderResponse.getOrderId()).isEqualTo(orderId); } + @Test + @DisplayName("getAllOrderOffsetPaging: Offset 페이징 - 메서드 호출 테스트") + void getAllOrderOffsetPaging_verify_test() { + //given + Pageable pageable = mock(Pageable.class); + + //when + orderService.getAllOrderOffsetPaging(pageable); + + //then + then(orderRepository).should(times(1)).findAllOffsetPaging(pageable); + } + + @Test + @DisplayName("getAllOrderSlicePaging: Slice 페이징 - 메서드 호출 테스트") + void getAllOrderSlicePaging_verify_test() { + //given + Pageable pageable = mock(Pageable.class); + + //when + orderService.getAllOrderSlicePaging(pageable); + + //then + then(orderRepository).should(times(1)).findAllSlicePaging(pageable); + } + + @Test @DisplayName("saveOrder: 주문 생성 - 메서드 호출 테스트") void saveOrder_verify_test() { From 51d08df2438fd19d1cc490f5ed34f2f9ded20bc1 Mon Sep 17 00:00:00 2001 From: subin Date: Thu, 4 Jul 2024 02:30:20 +0900 Subject: [PATCH 06/18] =?UTF-8?q?refactor:=20ProductService=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/store/clothstar/product/service/ProductService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/store/clothstar/product/service/ProductService.java b/src/main/java/org/store/clothstar/product/service/ProductService.java index d6ed3ce5..4cf44587 100644 --- a/src/main/java/org/store/clothstar/product/service/ProductService.java +++ b/src/main/java/org/store/clothstar/product/service/ProductService.java @@ -77,7 +77,7 @@ public void deleteProduct(Long productId) { @Transactional public void restoreProductStock(List orderDetailList) { orderDetailList.forEach(orderDetailEntity -> { - ProductEntity productEntity = productJPARepository.findById(orderDetailEntity.getProduct().getProductId()) + ProductEntity productEntity = productRepository.findById(orderDetailEntity.getProduct().getProductId()) .orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "상품 정보를 찾을 수 없습니다.")); productEntity.restoreStock(orderDetailEntity.getQuantity()); }); From 21e0834859715aeb0f1e01a7ccf4efc27467d65d Mon Sep 17 00:00:00 2001 From: subin Date: Sat, 6 Jul 2024 13:57:12 +0900 Subject: [PATCH 07/18] =?UTF-8?q?refactor:=20=ED=8E=98=EC=9D=B4=EC=A7=95?= =?UTF-8?q?=20api=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - /v1/orders/list -> /v1/orders/offset --- .../org/store/clothstar/order/controller/OrderController.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/store/clothstar/order/controller/OrderController.java b/src/main/java/org/store/clothstar/order/controller/OrderController.java index d5c4ae48..61668511 100644 --- a/src/main/java/org/store/clothstar/order/controller/OrderController.java +++ b/src/main/java/org/store/clothstar/order/controller/OrderController.java @@ -41,7 +41,7 @@ public ResponseEntity getOrder(@Validated @PathVariable Long orde } @Operation(summary = "전체 주문 조회 offset 페이징", description = "전체 주문 리스트를 offset 페이징 형식으로 가져온다.") - @GetMapping("/v1/orders/list") + @GetMapping("/v1/orders/offset") public ResponseEntity> getAllOrderOffsetPaging( @PageableDefault(size = 15) Pageable pageable) { Page orderPages = orderService.getAllOrderOffsetPaging(pageable); @@ -49,7 +49,7 @@ public ResponseEntity> getAllOrderOffsetPaging( } @Operation(summary = "전체 주문 조회 slice 페이징", description = "전체 주문 리스트를 slice 페이징 형식으로 가져온다.") - @GetMapping("/v2/orders/list") + @GetMapping("/v1/orders/slice") public ResponseEntity> getAllOrderSlicePaging( @PageableDefault(size = 15) Pageable pageable) { Slice orderPages = orderService.getAllOrderSlicePaging(pageable); From 72dc1ce5c6db140d1409669139d7e8750c328d97 Mon Sep 17 00:00:00 2001 From: subin Date: Sat, 6 Jul 2024 14:01:22 +0900 Subject: [PATCH 08/18] =?UTF-8?q?refactor:=20OrderPageResponse=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../order/controller/OrderController.java | 14 ++-- .../order/dto/reponse/OrderPageResponse.java | 78 ------------------- .../clothstar/order/service/OrderService.java | 1 - 3 files changed, 6 insertions(+), 87 deletions(-) delete mode 100644 src/main/java/org/store/clothstar/order/dto/reponse/OrderPageResponse.java diff --git a/src/main/java/org/store/clothstar/order/controller/OrderController.java b/src/main/java/org/store/clothstar/order/controller/OrderController.java index 61668511..621510b3 100644 --- a/src/main/java/org/store/clothstar/order/controller/OrderController.java +++ b/src/main/java/org/store/clothstar/order/controller/OrderController.java @@ -12,8 +12,6 @@ import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import org.store.clothstar.common.dto.MessageDTO; -import org.store.clothstar.member.dto.response.MemberResponse; -import org.store.clothstar.order.dto.reponse.OrderPageResponse; import org.store.clothstar.order.dto.reponse.OrderResponse; import org.store.clothstar.order.dto.request.OrderRequestWrapper; import org.store.clothstar.order.service.OrderApplicationService; @@ -27,21 +25,21 @@ @Tag(name = "Order", description = "주문(Order) 정보 관리에 대한 API 입니다.") @RestController @RequiredArgsConstructor -//@RequestMapping("/v1/orders") +@RequestMapping("/v1/orders") public class OrderController { private final OrderService orderService; private final OrderApplicationService orderApplicationService; @Operation(summary = "단일 주문 조회", description = "단일 주문의 정보를 조회한다.") - @GetMapping("/v1/orders/{orderId}") + @GetMapping("/{orderId}") public ResponseEntity getOrder(@Validated @PathVariable Long orderId) { OrderResponse orderResponse = orderService.getOrder(orderId); return ResponseEntity.ok(orderResponse); } @Operation(summary = "전체 주문 조회 offset 페이징", description = "전체 주문 리스트를 offset 페이징 형식으로 가져온다.") - @GetMapping("/v1/orders/offset") + @GetMapping("/offset") public ResponseEntity> getAllOrderOffsetPaging( @PageableDefault(size = 15) Pageable pageable) { Page orderPages = orderService.getAllOrderOffsetPaging(pageable); @@ -49,7 +47,7 @@ public ResponseEntity> getAllOrderOffsetPaging( } @Operation(summary = "전체 주문 조회 slice 페이징", description = "전체 주문 리스트를 slice 페이징 형식으로 가져온다.") - @GetMapping("/v1/orders/slice") + @GetMapping("/slice") public ResponseEntity> getAllOrderSlicePaging( @PageableDefault(size = 15) Pageable pageable) { Slice orderPages = orderService.getAllOrderSlicePaging(pageable); @@ -57,7 +55,7 @@ public ResponseEntity> getAllOrderSlicePaging( } @Operation(summary = "주문 생성", description = "단일 주문을 생성한다.") - @PostMapping("/v1/orders") + @PostMapping() public ResponseEntity saveOrder(@RequestBody @Validated OrderRequestWrapper orderRequestWrapper) { Long orderId = orderApplicationService.saveOrderWithTransaction(orderRequestWrapper); URI location = URIBuilder.buildURI(orderId); @@ -65,7 +63,7 @@ public ResponseEntity saveOrder(@RequestBody @Validated OrderRequestWrapper } @Operation(summary = "구매 확정", description = "구매자가 구매 확정 시, 주문상태가 '구매확정'으로 변경된다.") - @PatchMapping("/v1/orders/{orderId}") + @PatchMapping("{orderId}") public ResponseEntity deliveredToConfirmOrder(@PathVariable Long orderId) { orderService.deliveredToConfirmOrder(orderId); return ResponseEntity.ok(new MessageDTO(HttpStatus.OK.value(), "주문이 정상적으로 구매 확정 되었습니다.")); diff --git a/src/main/java/org/store/clothstar/order/dto/reponse/OrderPageResponse.java b/src/main/java/org/store/clothstar/order/dto/reponse/OrderPageResponse.java deleted file mode 100644 index 0ff8163e..00000000 --- a/src/main/java/org/store/clothstar/order/dto/reponse/OrderPageResponse.java +++ /dev/null @@ -1,78 +0,0 @@ -package org.store.clothstar.order.dto.reponse; - -import com.querydsl.core.annotations.QueryProjection; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; -import org.store.clothstar.member.entity.AddressEntity; -import org.store.clothstar.member.entity.MemberEntity; -import org.store.clothstar.order.entity.OrderEntity; -import org.store.clothstar.order.type.PaymentMethod; -import org.store.clothstar.order.type.Status; -import org.store.clothstar.orderDetail.dto.OrderDetailDTO; -import org.store.clothstar.orderDetail.entity.OrderDetailEntity; -import org.store.clothstar.productLine.entity.ProductLineEntity; - -import java.time.LocalDate; -import java.util.ArrayList; -import java.util.List; - -@Getter -@Builder -@AllArgsConstructor -@NoArgsConstructor -@Schema(description = "주문 페이지 조회용 Response") -public class OrderPageResponse { - @Schema(description = "주문 id", example = "1") - private Long orderId; - - @Schema(description = "주문자 이름", example = "수빈") - private String ordererName; - - @Schema(description = "주문 생성 날짜", example = "2024-05-15") - private LocalDate createdAt; - - @Schema(description = "주문 상태", example = "WAITING") - private Status status; - - //address - private String receiverName; - private String addressBasic; - private String addressDetail; - private String telNo; - private String deliveryRequest; - - @Schema(description = "결제 수단", example = "CARD") - private PaymentMethod paymentMethod; - - @Schema(description = "총 배송비", example = "3000") - private int totalShippingPrice; - - @Schema(description = "총 상품 금액", example = "15000") - private int totalProductsPrice; - - @Schema(description = "총 결제 금액", example = "18000") - private int totalPaymentPrice; - - private List orderDetails; - - public static OrderPageResponse from(OrderEntity orderEntity) { - return OrderPageResponse.builder() - .orderId(orderEntity.getOrderId()) - .ordererName(orderEntity.getMember().getName()) - .createdAt(orderEntity.getCreatedAt().toLocalDate()) - .status(orderEntity.getStatus()) - .totalShippingPrice(orderEntity.getTotalShippingPrice()) - .totalProductsPrice(orderEntity.getTotalProductsPrice()) - .paymentMethod(orderEntity.getPaymentMethod()) - .totalPaymentPrice(orderEntity.getTotalPaymentPrice()) - .telNo(orderEntity.getAddress().getTelNo()) - .deliveryRequest(orderEntity.getAddress().getDeliveryRequest()) - .receiverName(orderEntity.getAddress().getReceiverName()) - .addressBasic(orderEntity.getAddress().getAddressBasic()) - .addressDetail(orderEntity.getAddress().getAddressDetail()) - .build(); - } -} diff --git a/src/main/java/org/store/clothstar/order/service/OrderService.java b/src/main/java/org/store/clothstar/order/service/OrderService.java index 53ca3c9d..18eb0a23 100644 --- a/src/main/java/org/store/clothstar/order/service/OrderService.java +++ b/src/main/java/org/store/clothstar/order/service/OrderService.java @@ -14,7 +14,6 @@ import org.store.clothstar.member.entity.MemberEntity; import org.store.clothstar.member.repository.AddressRepository; import org.store.clothstar.member.repository.MemberRepository; -import org.store.clothstar.order.dto.reponse.OrderPageResponse; import org.store.clothstar.order.dto.reponse.OrderResponse; import org.store.clothstar.order.dto.request.CreateOrderRequest; import org.store.clothstar.order.entity.OrderEntity; From f608a5e7dfe876679c83d197cc4dc5b676b88d8b Mon Sep 17 00:00:00 2001 From: subin Date: Sat, 6 Jul 2024 22:25:16 +0900 Subject: [PATCH 09/18] =?UTF-8?q?refactor:=20order=5Fdetail.sql/OrderDetai?= =?UTF-8?q?l/OrderDetailDTO=20=ED=95=84=EB=93=9C=20=EA=B4=80=EB=A0=A8=20?= =?UTF-8?q?=EC=88=98=EC=A0=95,=20=EC=82=AC=EC=9A=A9=ED=95=98=EC=A7=80=20?= =?UTF-8?q?=EC=95=8A=EB=8A=94=20=EC=A3=BC=EC=84=9D=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - order_detail 테이블에서 필요없는 칼럼 삭제(name,stock,option_name,brand_name) - getProduct() 이용해서 product 관련 필드 가져오기로 수정 - getProductLine() 이용해서 productLine 관련 필드 가져오기로 수정 - 주문조회 메서드에서 Validated 삭제 --- .../clothstar/order/controller/OrderController.java | 4 +--- .../clothstar/order/dto/reponse/OrderResponse.java | 3 +-- .../store/clothstar/order/entity/OrderEntity.java | 13 +------------ .../order/repository/order/JpaOrderRepository.java | 1 - .../order/repository/order/OrderRepository.java | 1 - .../orderSeller/OrderEntityRepositoryCustom.java | 1 - .../OrderEntityRepositoryCustomImpl.java | 1 - .../orderSeller/OrderSellerRepository.java | 1 - .../clothstar/order/service/OrderSellerService.java | 1 - .../orderDetail/entity/OrderDetailEntity.java | 4 ---- .../orderDetail/service/OrderDetailService.java | 2 +- src/main/resources/sql/order_detail.sql | 4 ---- src/main/resources/sql/orders.sql | 2 +- 13 files changed, 5 insertions(+), 33 deletions(-) diff --git a/src/main/java/org/store/clothstar/order/controller/OrderController.java b/src/main/java/org/store/clothstar/order/controller/OrderController.java index 621510b3..8f698420 100644 --- a/src/main/java/org/store/clothstar/order/controller/OrderController.java +++ b/src/main/java/org/store/clothstar/order/controller/OrderController.java @@ -20,8 +20,6 @@ import java.net.URI; - - @Tag(name = "Order", description = "주문(Order) 정보 관리에 대한 API 입니다.") @RestController @RequiredArgsConstructor @@ -33,7 +31,7 @@ public class OrderController { @Operation(summary = "단일 주문 조회", description = "단일 주문의 정보를 조회한다.") @GetMapping("/{orderId}") - public ResponseEntity getOrder(@Validated @PathVariable Long orderId) { + public ResponseEntity getOrder(@PathVariable Long orderId) { OrderResponse orderResponse = orderService.getOrder(orderId); return ResponseEntity.ok(orderResponse); } diff --git a/src/main/java/org/store/clothstar/order/dto/reponse/OrderResponse.java b/src/main/java/org/store/clothstar/order/dto/reponse/OrderResponse.java index 5ad1e325..74f4c6a7 100644 --- a/src/main/java/org/store/clothstar/order/dto/reponse/OrderResponse.java +++ b/src/main/java/org/store/clothstar/order/dto/reponse/OrderResponse.java @@ -81,7 +81,7 @@ public OrderResponse(OrderEntity orderEntity, this.orderDetailList = new ArrayList<>(); } - public static OrderResponse fromOrderEntity(OrderEntity orderEntity) { + public static OrderResponse from(OrderEntity orderEntity) { return OrderResponse.builder() .orderId(orderEntity.getOrderId()) .ordererName(orderEntity.getMember().getName()) @@ -96,7 +96,6 @@ public static OrderResponse fromOrderEntity(OrderEntity orderEntity) { .receiverName(orderEntity.getAddress().getReceiverName()) .addressBasic(orderEntity.getAddress().getAddressBasic()) .addressDetail(orderEntity.getAddress().getAddressDetail()) -// .orderDetailList(orderEntity.getOrderDetails().) .build(); } diff --git a/src/main/java/org/store/clothstar/order/entity/OrderEntity.java b/src/main/java/org/store/clothstar/order/entity/OrderEntity.java index dd0799e9..3167d95a 100644 --- a/src/main/java/org/store/clothstar/order/entity/OrderEntity.java +++ b/src/main/java/org/store/clothstar/order/entity/OrderEntity.java @@ -53,19 +53,8 @@ public class OrderEntity { @OneToOne @JoinColumn(name = "address_id") private AddressEntity address; -// -// @ManyToOne -// private OrderDetailEntity orderDetail; - public void setTotalProductsPrice(int totalProductsPrice) { - this.totalProductsPrice = totalProductsPrice; - } - - public void setTotalPaymentPrice(int totalPaymentPrice) { - this.totalPaymentPrice = totalPaymentPrice; - } - - public void updatePrices(int totalProductsPrice, int totalPaymentPrice) { + public void updatePrices(int totalProductsPrice, int totalPaymentPrice) { this.totalProductsPrice = totalProductsPrice; this.totalPaymentPrice = totalPaymentPrice; } diff --git a/src/main/java/org/store/clothstar/order/repository/order/JpaOrderRepository.java b/src/main/java/org/store/clothstar/order/repository/order/JpaOrderRepository.java index c0a81703..bb318c32 100644 --- a/src/main/java/org/store/clothstar/order/repository/order/JpaOrderRepository.java +++ b/src/main/java/org/store/clothstar/order/repository/order/JpaOrderRepository.java @@ -8,7 +8,6 @@ import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.transaction.annotation.Transactional; -import org.store.clothstar.order.dto.reponse.OrderResponse; import org.store.clothstar.order.entity.OrderEntity; import org.store.clothstar.order.repository.orderSeller.OrderEntityRepositoryCustom; diff --git a/src/main/java/org/store/clothstar/order/repository/order/OrderRepository.java b/src/main/java/org/store/clothstar/order/repository/order/OrderRepository.java index a7f962c5..22a6d082 100644 --- a/src/main/java/org/store/clothstar/order/repository/order/OrderRepository.java +++ b/src/main/java/org/store/clothstar/order/repository/order/OrderRepository.java @@ -3,7 +3,6 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Slice; -import org.store.clothstar.member.entity.MemberEntity; import org.store.clothstar.order.dto.reponse.OrderResponse; import org.store.clothstar.order.entity.OrderEntity; diff --git a/src/main/java/org/store/clothstar/order/repository/orderSeller/OrderEntityRepositoryCustom.java b/src/main/java/org/store/clothstar/order/repository/orderSeller/OrderEntityRepositoryCustom.java index 8711a2e5..286d9663 100644 --- a/src/main/java/org/store/clothstar/order/repository/orderSeller/OrderEntityRepositoryCustom.java +++ b/src/main/java/org/store/clothstar/order/repository/orderSeller/OrderEntityRepositoryCustom.java @@ -4,7 +4,6 @@ import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Slice; import org.store.clothstar.order.dto.reponse.OrderResponse; -import org.store.clothstar.order.entity.OrderEntity; import java.util.List; diff --git a/src/main/java/org/store/clothstar/order/repository/orderSeller/OrderEntityRepositoryCustomImpl.java b/src/main/java/org/store/clothstar/order/repository/orderSeller/OrderEntityRepositoryCustomImpl.java index 53d27181..3ddb5660 100644 --- a/src/main/java/org/store/clothstar/order/repository/orderSeller/OrderEntityRepositoryCustomImpl.java +++ b/src/main/java/org/store/clothstar/order/repository/orderSeller/OrderEntityRepositoryCustomImpl.java @@ -9,7 +9,6 @@ import org.store.clothstar.member.entity.QMemberEntity; import org.store.clothstar.order.dto.reponse.OrderResponse; import org.store.clothstar.order.dto.reponse.QOrderResponse; -import org.store.clothstar.order.entity.OrderEntity; import org.store.clothstar.order.entity.QOrderEntity; import org.store.clothstar.order.type.Status; import org.store.clothstar.orderDetail.dto.OrderDetailDTO; diff --git a/src/main/java/org/store/clothstar/order/repository/orderSeller/OrderSellerRepository.java b/src/main/java/org/store/clothstar/order/repository/orderSeller/OrderSellerRepository.java index ec464df0..7a4ad82f 100644 --- a/src/main/java/org/store/clothstar/order/repository/orderSeller/OrderSellerRepository.java +++ b/src/main/java/org/store/clothstar/order/repository/orderSeller/OrderSellerRepository.java @@ -1,7 +1,6 @@ package org.store.clothstar.order.repository.orderSeller; import org.store.clothstar.order.dto.reponse.OrderResponse; -import org.store.clothstar.order.entity.OrderEntity; import java.util.List; diff --git a/src/main/java/org/store/clothstar/order/service/OrderSellerService.java b/src/main/java/org/store/clothstar/order/service/OrderSellerService.java index e314ad38..4dd16939 100644 --- a/src/main/java/org/store/clothstar/order/service/OrderSellerService.java +++ b/src/main/java/org/store/clothstar/order/service/OrderSellerService.java @@ -7,7 +7,6 @@ import org.springframework.web.server.ResponseStatusException; import org.store.clothstar.common.dto.MessageDTO; import org.store.clothstar.order.dto.reponse.OrderResponse; -import org.store.clothstar.order.entity.OrderEntity; import org.store.clothstar.order.repository.order.OrderRepository; import org.store.clothstar.order.repository.orderSeller.OrderSellerRepository; import org.store.clothstar.order.type.Status; diff --git a/src/main/java/org/store/clothstar/orderDetail/entity/OrderDetailEntity.java b/src/main/java/org/store/clothstar/orderDetail/entity/OrderDetailEntity.java index 155e620d..c6ca0cdb 100644 --- a/src/main/java/org/store/clothstar/orderDetail/entity/OrderDetailEntity.java +++ b/src/main/java/org/store/clothstar/orderDetail/entity/OrderDetailEntity.java @@ -38,8 +38,4 @@ public class OrderDetailEntity { @ManyToOne @JoinColumn(name = "product_id") private ProductEntity product; -// -// public updateOrderDetails(){ -// -// } } \ No newline at end of file diff --git a/src/main/java/org/store/clothstar/orderDetail/service/OrderDetailService.java b/src/main/java/org/store/clothstar/orderDetail/service/OrderDetailService.java index ab6b6990..adc1d491 100644 --- a/src/main/java/org/store/clothstar/orderDetail/service/OrderDetailService.java +++ b/src/main/java/org/store/clothstar/orderDetail/service/OrderDetailService.java @@ -8,6 +8,7 @@ import org.springframework.web.server.ResponseStatusException; import org.store.clothstar.order.entity.OrderEntity; import org.store.clothstar.order.repository.order.OrderRepository; +import org.store.clothstar.order.type.Status; import org.store.clothstar.orderDetail.dto.request.AddOrderDetailRequest; import org.store.clothstar.orderDetail.dto.request.CreateOrderDetailRequest; import org.store.clothstar.orderDetail.entity.OrderDetailEntity; @@ -70,7 +71,6 @@ public void saveOrderDetailWithOrder(CreateOrderDetailRequest createOrderDetailR orderEntity.getTotalProductsPrice() + orderEntity.getTotalShippingPrice() + orderDetailEntity.getOneKindTotalPrice(); orderEntity.updatePrices(newTotalProductsPrice, newTotalPaymentPrice); -// orderDetailRepository.updateOrderPrices(orderEntity); // 주문 수량만큼 상품 재고 차감 updateProductStock(productEntity,orderDetailEntity.getQuantity()); diff --git a/src/main/resources/sql/order_detail.sql b/src/main/resources/sql/order_detail.sql index 415e113d..0e6405dd 100644 --- a/src/main/resources/sql/order_detail.sql +++ b/src/main/resources/sql/order_detail.sql @@ -9,10 +9,6 @@ CREATE TABLE `order_detail` `quantity` int NOT NULL, `fixed_price` int NOT NULL, `onekind_total_price` int NOT NULL, - `name` VARCHAR(255) NOT NULL, - `stock` VARCHAR(255) NOT NULL, - `option_name` VARCHAR(255) NOT NULL, - `brand_name` VARCHAR(255) NOT NULL, PRIMARY KEY (`order_detail_id`) ); diff --git a/src/main/resources/sql/orders.sql b/src/main/resources/sql/orders.sql index 506220a2..69ce220e 100644 --- a/src/main/resources/sql/orders.sql +++ b/src/main/resources/sql/orders.sql @@ -81,7 +81,7 @@ select distinct oe1_0.order_id,oe1_0.address_id,oe1_0.created_at,oe1_0.member_id drop index FK_member_TO_orders_1 on orders; DELETE -FROM orders where total_products_price=10000; +FROM orders where member_id=1; INSERT INTO orders (order_id, member_id, address_id, created_at, status, total_shipping_price, total_products_price, payment_method, total_payment_price) From 48f0a1e16c56ef8308a3caa1678bfd17a68bb765 Mon Sep 17 00:00:00 2001 From: subin Date: Sun, 7 Jul 2024 00:02:45 +0900 Subject: [PATCH 10/18] =?UTF-8?q?refactor:=20OrderResponse=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EB=B0=B0=EC=86=A1=EC=A7=80=20=EA=B4=80=EB=A0=A8=20?= =?UTF-8?q?=ED=95=84=EB=93=9C=20=EA=B0=9D=EC=B2=B4=EB=A1=9C=20=EB=B0=98?= =?UTF-8?q?=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../order/dto/reponse/AddressDTO.java | 29 +++++++++++++++++ .../order/dto/reponse/OrderResponse.java | 32 +++++++++---------- 2 files changed, 45 insertions(+), 16 deletions(-) create mode 100644 src/main/java/org/store/clothstar/order/dto/reponse/AddressDTO.java diff --git a/src/main/java/org/store/clothstar/order/dto/reponse/AddressDTO.java b/src/main/java/org/store/clothstar/order/dto/reponse/AddressDTO.java new file mode 100644 index 00000000..e7aa741b --- /dev/null +++ b/src/main/java/org/store/clothstar/order/dto/reponse/AddressDTO.java @@ -0,0 +1,29 @@ +package org.store.clothstar.order.dto.reponse; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@Builder +@AllArgsConstructor +@NoArgsConstructor +@Schema(description = "배송지 정보") +public class AddressDTO { + @Schema(description = "수령인 이름", example = "수빈") + private String receiverName; + + @Schema(description = "기본 주소", example = "서울시 강남구") + private String addressBasic; + + @Schema(description = "상세 주소", example = "123-456") + private String addressDetail; + + @Schema(description = "전화번호", example = "010-1234-5678") + private String telNo; + + @Schema(description = "배송 요청 사항", example = "문 앞에 놓아주세요.") + private String deliveryRequest; +} diff --git a/src/main/java/org/store/clothstar/order/dto/reponse/OrderResponse.java b/src/main/java/org/store/clothstar/order/dto/reponse/OrderResponse.java index 74f4c6a7..1109ad15 100644 --- a/src/main/java/org/store/clothstar/order/dto/reponse/OrderResponse.java +++ b/src/main/java/org/store/clothstar/order/dto/reponse/OrderResponse.java @@ -38,12 +38,8 @@ public class OrderResponse { @Schema(description = "주문 상태", example = "WAITING") private Status status; - //address - private String receiverName; - private String addressBasic; - private String addressDetail; - private String telNo; - private String deliveryRequest; + @Schema(description = "주소 정보") + private AddressDTO address; @Schema(description = "결제 수단", example = "CARD") private PaymentMethod paymentMethod; @@ -73,11 +69,13 @@ public OrderResponse(OrderEntity orderEntity, this.totalProductsPrice = orderEntity.getTotalProductsPrice(); this.paymentMethod = orderEntity.getPaymentMethod(); this.totalPaymentPrice = orderEntity.getTotalPaymentPrice(); - this.receiverName = addressEntity.getReceiverName(); - this.addressBasic = addressEntity.getAddressBasic(); - this.addressDetail = addressEntity.getAddressDetail(); - this.telNo = addressEntity.getTelNo(); - this.deliveryRequest = addressEntity.getDeliveryRequest(); + this.address = AddressDTO.builder() + .receiverName(addressEntity.getReceiverName()) + .addressBasic(addressEntity.getAddressBasic()) + .addressDetail(addressEntity.getAddressDetail()) + .telNo(addressEntity.getTelNo()) + .deliveryRequest(addressEntity.getDeliveryRequest()) + .build(); this.orderDetailList = new ArrayList<>(); } @@ -91,11 +89,13 @@ public static OrderResponse from(OrderEntity orderEntity) { .totalProductsPrice(orderEntity.getTotalProductsPrice()) .paymentMethod(orderEntity.getPaymentMethod()) .totalPaymentPrice(orderEntity.getTotalPaymentPrice()) - .telNo(orderEntity.getAddress().getTelNo()) - .deliveryRequest(orderEntity.getAddress().getDeliveryRequest()) - .receiverName(orderEntity.getAddress().getReceiverName()) - .addressBasic(orderEntity.getAddress().getAddressBasic()) - .addressDetail(orderEntity.getAddress().getAddressDetail()) + .address(AddressDTO.builder() + .receiverName(orderEntity.getAddress().getReceiverName()) + .addressBasic(orderEntity.getAddress().getAddressBasic()) + .addressDetail(orderEntity.getAddress().getAddressDetail()) + .telNo(orderEntity.getAddress().getTelNo()) + .deliveryRequest(orderEntity.getAddress().getDeliveryRequest()) + .build()) .build(); } From 7260289fa36397208d14394044e7a060fd804bcc Mon Sep 17 00:00:00 2001 From: subin Date: Sun, 7 Jul 2024 00:41:41 +0900 Subject: [PATCH 11/18] =?UTF-8?q?feature:=20BaseEntity=20=EC=A0=81?= =?UTF-8?q?=EC=9A=A9=20-=20OrderEntity,=20OrderDetailEntity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../order/dto/request/CreateOrderRequest.java | 1 - .../store/clothstar/order/entity/OrderEntity.java | 12 ++++++++---- .../orderDetail/entity/OrderDetailEntity.java | 3 ++- src/main/resources/sql/order_detail.sql | 6 ++++++ src/main/resources/sql/orders.sql | 5 ++++- 5 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/store/clothstar/order/dto/request/CreateOrderRequest.java b/src/main/java/org/store/clothstar/order/dto/request/CreateOrderRequest.java index f067393e..3873da4c 100644 --- a/src/main/java/org/store/clothstar/order/dto/request/CreateOrderRequest.java +++ b/src/main/java/org/store/clothstar/order/dto/request/CreateOrderRequest.java @@ -40,7 +40,6 @@ public OrderEntity toOrderEntity(MemberEntity memberEntity, AddressEntity addres .orderId(GenerateOrderId.generateOrderId()) .member(memberEntity) .address(addressEntity) - .createdAt(LocalDateTime.now()) .status(Status.WAITING) .totalShippingPrice(3000) .totalProductsPrice(0) diff --git a/src/main/java/org/store/clothstar/order/entity/OrderEntity.java b/src/main/java/org/store/clothstar/order/entity/OrderEntity.java index 3167d95a..311b7e16 100644 --- a/src/main/java/org/store/clothstar/order/entity/OrderEntity.java +++ b/src/main/java/org/store/clothstar/order/entity/OrderEntity.java @@ -5,6 +5,7 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import org.store.clothstar.common.entity.BaseEntity; import org.store.clothstar.member.entity.AddressEntity; import org.store.clothstar.member.entity.MemberEntity; import org.store.clothstar.order.type.PaymentMethod; @@ -19,16 +20,16 @@ @Getter @Builder @Entity(name = "orders") -public class OrderEntity { +public class OrderEntity extends BaseEntity { @Id private Long orderId; @OneToMany(mappedBy = "order", cascade = CascadeType.ALL, orphanRemoval = true) private List orderDetails; - @Temporal(TemporalType.TIMESTAMP) - @Column(name = "created_at") - private LocalDateTime createdAt; +// @Temporal(TemporalType.TIMESTAMP) +// @Column(name = "created_at") +// private LocalDateTime createdAt; @Enumerated(EnumType.STRING) private Status status; @@ -59,4 +60,7 @@ public void updatePrices(int totalProductsPrice, int totalPaymentPrice) { this.totalPaymentPrice = totalPaymentPrice; } + public void updateDeletedAt() { + this.deletedAt = LocalDateTime.now(); + } } diff --git a/src/main/java/org/store/clothstar/orderDetail/entity/OrderDetailEntity.java b/src/main/java/org/store/clothstar/orderDetail/entity/OrderDetailEntity.java index c6ca0cdb..df5b4b78 100644 --- a/src/main/java/org/store/clothstar/orderDetail/entity/OrderDetailEntity.java +++ b/src/main/java/org/store/clothstar/orderDetail/entity/OrderDetailEntity.java @@ -5,6 +5,7 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import org.store.clothstar.common.entity.BaseEntity; import org.store.clothstar.order.entity.OrderEntity; import org.store.clothstar.product.entity.ProductEntity; import org.store.clothstar.productLine.entity.ProductLineEntity; @@ -14,7 +15,7 @@ @NoArgsConstructor @Builder @Entity(name = "order_detail") -public class OrderDetailEntity { +public class OrderDetailEntity extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long orderDetailId; diff --git a/src/main/resources/sql/order_detail.sql b/src/main/resources/sql/order_detail.sql index 0e6405dd..802bbaf4 100644 --- a/src/main/resources/sql/order_detail.sql +++ b/src/main/resources/sql/order_detail.sql @@ -9,10 +9,16 @@ CREATE TABLE `order_detail` `quantity` int NOT NULL, `fixed_price` int NOT NULL, `onekind_total_price` int NOT NULL, + `created_at` timestamp NOT NULL, + `updated_at` timestamp NULL, + `deleted_at` timestamp NULL, PRIMARY KEY (`order_detail_id`) ); +ALTER TABLE order_detail MODIFY COLUMN created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP; + + select * from order_detail; diff --git a/src/main/resources/sql/orders.sql b/src/main/resources/sql/orders.sql index 69ce220e..28ef2be3 100644 --- a/src/main/resources/sql/orders.sql +++ b/src/main/resources/sql/orders.sql @@ -5,16 +5,19 @@ CREATE TABLE orders `order_id` bigint NOT NULL, `member_id` bigint NOT NULL, `address_id` bigint NOT NULL, - `created_at` timestamp NOT NULL, `status` varchar(255) NOT NULL, `total_shipping_price` int NOT NULL, `total_products_price` int NOT NULL, `payment_method` varchar(255) NOT NULL, `total_payment_price` int NOT NULL, + `created_at` timestamp NOT NULL, + `updated_at` timestamp NULL, + `deleted_at` timestamp NULL, PRIMARY KEY (`order_id`) ); + ALTER TABLE orders DROP PRIMARY KEY; From 4489102eac13e53199f722a44e3c84ada75b262e Mon Sep 17 00:00:00 2001 From: subin Date: Sun, 7 Jul 2024 01:38:43 +0900 Subject: [PATCH 12/18] =?UTF-8?q?feature:=20=EC=82=AD=EC=A0=9C=20API=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20-=20OrderController,=20=EB=B0=98=ED=99=98?= =?UTF-8?q?=EA=B0=92=EC=9D=84=20MessageDTO,saveResponseDTO=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../order/controller/OrderController.java | 14 +++++++++++--- .../store/clothstar/order/entity/OrderEntity.java | 6 +----- .../clothstar/order/service/OrderService.java | 12 ++++++++++++ .../orderDetail/entity/OrderDetailEntity.java | 6 ++++++ 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/store/clothstar/order/controller/OrderController.java b/src/main/java/org/store/clothstar/order/controller/OrderController.java index 8f698420..90edbf9c 100644 --- a/src/main/java/org/store/clothstar/order/controller/OrderController.java +++ b/src/main/java/org/store/clothstar/order/controller/OrderController.java @@ -12,6 +12,7 @@ import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import org.store.clothstar.common.dto.MessageDTO; +import org.store.clothstar.common.dto.SaveResponseDTO; import org.store.clothstar.order.dto.reponse.OrderResponse; import org.store.clothstar.order.dto.request.OrderRequestWrapper; import org.store.clothstar.order.service.OrderApplicationService; @@ -54,10 +55,10 @@ public ResponseEntity> getAllOrderSlicePaging( @Operation(summary = "주문 생성", description = "단일 주문을 생성한다.") @PostMapping() - public ResponseEntity saveOrder(@RequestBody @Validated OrderRequestWrapper orderRequestWrapper) { + public ResponseEntity saveOrder(@RequestBody @Validated OrderRequestWrapper orderRequestWrapper) { Long orderId = orderApplicationService.saveOrderWithTransaction(orderRequestWrapper); - URI location = URIBuilder.buildURI(orderId); - return ResponseEntity.created(location).build(); + return ResponseEntity.ok(new SaveResponseDTO( + orderId, HttpStatus.OK.value(), "주문이 정상적으로 생성되었습니다.")); } @Operation(summary = "구매 확정", description = "구매자가 구매 확정 시, 주문상태가 '구매확정'으로 변경된다.") @@ -66,6 +67,13 @@ public ResponseEntity deliveredToConfirmOrder(@PathVariable Long ord orderService.deliveredToConfirmOrder(orderId); return ResponseEntity.ok(new MessageDTO(HttpStatus.OK.value(), "주문이 정상적으로 구매 확정 되었습니다.")); } + + @Operation(summary = "주문 삭제", description = "주문 삭제시간을 현재시간으로 업데이트 한다.") + @DeleteMapping("{orderId}") + public ResponseEntity deleteOrder(@PathVariable Long orderId) { + orderService.updateDeleteAt(orderId); + return ResponseEntity.ok(new MessageDTO(HttpStatus.OK.value(), "주문이 정상적으로 삭제되었습니다.")); + } } diff --git a/src/main/java/org/store/clothstar/order/entity/OrderEntity.java b/src/main/java/org/store/clothstar/order/entity/OrderEntity.java index 311b7e16..d06acb1e 100644 --- a/src/main/java/org/store/clothstar/order/entity/OrderEntity.java +++ b/src/main/java/org/store/clothstar/order/entity/OrderEntity.java @@ -26,11 +26,7 @@ public class OrderEntity extends BaseEntity { @OneToMany(mappedBy = "order", cascade = CascadeType.ALL, orphanRemoval = true) private List orderDetails; - -// @Temporal(TemporalType.TIMESTAMP) -// @Column(name = "created_at") -// private LocalDateTime createdAt; - + @Enumerated(EnumType.STRING) private Status status; diff --git a/src/main/java/org/store/clothstar/order/service/OrderService.java b/src/main/java/org/store/clothstar/order/service/OrderService.java index 18eb0a23..bc9ce056 100644 --- a/src/main/java/org/store/clothstar/order/service/OrderService.java +++ b/src/main/java/org/store/clothstar/order/service/OrderService.java @@ -83,4 +83,16 @@ public void deliveredToConfirmOrder(Long orderId) { orderRepository.deliveredToConfirmOrder(orderId); } + + @Transactional + public void updateDeleteAt(Long orderId) { + OrderEntity orderEntity = orderRepository.findById(orderId) + .orElseThrow(() -> new IllegalArgumentException("주문 번호를 찾을 수 없습니다.")); + + if(orderEntity.getDeletedAt() != null){ + throw new IllegalArgumentException("이미 삭제된 주문입니다."); + } + + orderEntity.updateDeletedAt(); + } } diff --git a/src/main/java/org/store/clothstar/orderDetail/entity/OrderDetailEntity.java b/src/main/java/org/store/clothstar/orderDetail/entity/OrderDetailEntity.java index df5b4b78..11162552 100644 --- a/src/main/java/org/store/clothstar/orderDetail/entity/OrderDetailEntity.java +++ b/src/main/java/org/store/clothstar/orderDetail/entity/OrderDetailEntity.java @@ -10,6 +10,8 @@ import org.store.clothstar.product.entity.ProductEntity; import org.store.clothstar.productLine.entity.ProductLineEntity; +import java.time.LocalDateTime; + @Getter @AllArgsConstructor @NoArgsConstructor @@ -39,4 +41,8 @@ public class OrderDetailEntity extends BaseEntity { @ManyToOne @JoinColumn(name = "product_id") private ProductEntity product; + + public void updateDeletedAt() { + this.deletedAt = LocalDateTime.now(); + } } \ No newline at end of file From 250dcd78f2e2fa0403cf09aa8307a27fc282e597 Mon Sep 17 00:00:00 2001 From: subin Date: Sun, 7 Jul 2024 02:17:27 +0900 Subject: [PATCH 13/18] =?UTF-8?q?feature:=20=EC=A3=BC=EB=AC=B8=EC=83=81?= =?UTF-8?q?=EC=84=B8=20=EC=82=AD=EC=A0=9C=20API=20=EC=B6=94=EA=B0=80,=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=20=EC=8B=9C=20=ED=95=B4=EB=8B=B9=20=EC=A3=BC?= =?UTF-8?q?=EB=AC=B8=EC=83=81=EC=84=B8=20=EC=83=81=ED=92=88=20=EC=9E=AC?= =?UTF-8?q?=EA=B3=A0=20=EB=A1=A4=EB=B0=B1=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - OrderDetailController에서 반환값을 MessageDTO,saveResponseDTO로 변경 - 관련 테스트코드 오류 수정 --- .../common/config/SecurityConfiguration.java | 2 +- .../order/controller/OrderController.java | 5 +--- .../order/dto/request/CreateOrderRequest.java | 2 -- .../clothstar/order/service/OrderService.java | 2 -- .../controller/OrderDetailController.java | 24 ++++++++++------- .../repository/OrderDetailRepository.java | 2 ++ .../service/OrderDetailService.java | 26 ++++++++++++++++--- .../product/service/ProductService.java | 8 +++++- .../service/OrderDetailServiceTest.java | 2 +- 9 files changed, 48 insertions(+), 25 deletions(-) diff --git a/src/main/java/org/store/clothstar/common/config/SecurityConfiguration.java b/src/main/java/org/store/clothstar/common/config/SecurityConfiguration.java index bb974fdb..f841407f 100644 --- a/src/main/java/org/store/clothstar/common/config/SecurityConfiguration.java +++ b/src/main/java/org/store/clothstar/common/config/SecurityConfiguration.java @@ -58,7 +58,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { "/v1/orderdetails", "/v1/orders", "membersPagingOffset", "membersPagingSlice", "/v1/orderdetails", "/v1/orders", "/v2/orders", "/v3/orders", "/v1/orders/list", "/v1/orders/list","/ordersPagingOffset","/ordersPagingSlice","/v2/orders/list", - "/v1/seller/orders/**", "/v1/seller/orders", "/v1/orders/**", + "/v1/seller/orders/**", "/v1/seller/orders", "/v1/orders/**", "/v1/orderdetails/**", "/swagger-resources/**", "/swagger-ui/**", "/v3/api-docs/**", "/v1/members/auth/**" ).permitAll() .requestMatchers(HttpMethod.POST, "/v1/members").permitAll() diff --git a/src/main/java/org/store/clothstar/order/controller/OrderController.java b/src/main/java/org/store/clothstar/order/controller/OrderController.java index 90edbf9c..46aeda3d 100644 --- a/src/main/java/org/store/clothstar/order/controller/OrderController.java +++ b/src/main/java/org/store/clothstar/order/controller/OrderController.java @@ -17,9 +17,6 @@ import org.store.clothstar.order.dto.request.OrderRequestWrapper; import org.store.clothstar.order.service.OrderApplicationService; import org.store.clothstar.order.service.OrderService; -import org.store.clothstar.order.utils.URIBuilder; - -import java.net.URI; @Tag(name = "Order", description = "주문(Order) 정보 관리에 대한 API 입니다.") @RestController @@ -54,7 +51,7 @@ public ResponseEntity> getAllOrderSlicePaging( } @Operation(summary = "주문 생성", description = "단일 주문을 생성한다.") - @PostMapping() + @PostMapping public ResponseEntity saveOrder(@RequestBody @Validated OrderRequestWrapper orderRequestWrapper) { Long orderId = orderApplicationService.saveOrderWithTransaction(orderRequestWrapper); return ResponseEntity.ok(new SaveResponseDTO( diff --git a/src/main/java/org/store/clothstar/order/dto/request/CreateOrderRequest.java b/src/main/java/org/store/clothstar/order/dto/request/CreateOrderRequest.java index 3873da4c..6b068849 100644 --- a/src/main/java/org/store/clothstar/order/dto/request/CreateOrderRequest.java +++ b/src/main/java/org/store/clothstar/order/dto/request/CreateOrderRequest.java @@ -13,8 +13,6 @@ import org.store.clothstar.order.type.Status; import org.store.clothstar.order.utils.GenerateOrderId; -import java.time.LocalDateTime; - @Getter @Builder @NoArgsConstructor diff --git a/src/main/java/org/store/clothstar/order/service/OrderService.java b/src/main/java/org/store/clothstar/order/service/OrderService.java index bc9ce056..7221e331 100644 --- a/src/main/java/org/store/clothstar/order/service/OrderService.java +++ b/src/main/java/org/store/clothstar/order/service/OrderService.java @@ -21,8 +21,6 @@ import org.store.clothstar.order.type.Status; import org.store.clothstar.orderDetail.service.OrderDetailService; -import java.util.Optional; - @Slf4j @Service public class OrderService { diff --git a/src/main/java/org/store/clothstar/orderDetail/controller/OrderDetailController.java b/src/main/java/org/store/clothstar/orderDetail/controller/OrderDetailController.java index ed250551..68de9814 100644 --- a/src/main/java/org/store/clothstar/orderDetail/controller/OrderDetailController.java +++ b/src/main/java/org/store/clothstar/orderDetail/controller/OrderDetailController.java @@ -3,18 +3,15 @@ import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; -import org.store.clothstar.order.utils.URIBuilder; +import org.springframework.web.bind.annotation.*; +import org.store.clothstar.common.dto.MessageDTO; +import org.store.clothstar.common.dto.SaveResponseDTO; import org.store.clothstar.orderDetail.dto.request.AddOrderDetailRequest; import org.store.clothstar.orderDetail.service.OrderDetailService; -import java.net.URI; - @Tag(name = "OrderDetail", description = "주문 내 개별 상품에 대한 옵션, 수량 등을 나타내는, 주문상세(OrderDetail) 정보 관리에 대한 API 입니다.") @RestController @RequiredArgsConstructor @@ -25,9 +22,16 @@ public class OrderDetailController { @Operation(summary = "주문상세 추가 저장", description = "개별 상품에 대한 주문상세(상품명, 가격, 개수...)를 특정 주문에 추가 저장한다.") @PostMapping - public ResponseEntity addOrderDetail(@RequestBody @Validated AddOrderDetailRequest addOrderDetailRequest) { + public ResponseEntity addOrderDetail(@RequestBody @Validated AddOrderDetailRequest addOrderDetailRequest) { Long orderDetailId = orderdetailService.addOrderDetail(addOrderDetailRequest); - URI location = URIBuilder.buildURI(orderDetailId); - return ResponseEntity.created(location).build(); + return ResponseEntity.ok(new SaveResponseDTO( + orderDetailId, HttpStatus.OK.value(), "주문상세가 정상적으로 생성되었습니다.")); + } + + @Operation(summary = "주문상세 삭제", description = "주문상세 삭제시간을 현재시간으로 업데이트 한다.") + @DeleteMapping("{orderDetailId}") + public ResponseEntity deleteOrderDetail(@PathVariable Long orderDetailId) { + orderdetailService.updateDeleteAt(orderDetailId); + return ResponseEntity.ok(new MessageDTO(HttpStatus.OK.value(), "주문상세가 정상적으로 삭제되었습니다.")); } } diff --git a/src/main/java/org/store/clothstar/orderDetail/repository/OrderDetailRepository.java b/src/main/java/org/store/clothstar/orderDetail/repository/OrderDetailRepository.java index 35dd642e..3ff066b2 100644 --- a/src/main/java/org/store/clothstar/orderDetail/repository/OrderDetailRepository.java +++ b/src/main/java/org/store/clothstar/orderDetail/repository/OrderDetailRepository.java @@ -3,8 +3,10 @@ import org.store.clothstar.orderDetail.entity.OrderDetailEntity; import java.util.List; +import java.util.Optional; public interface OrderDetailRepository { + Optional findById(Long orderDetailId); OrderDetailEntity save(OrderDetailEntity orderdetailEntity); diff --git a/src/main/java/org/store/clothstar/orderDetail/service/OrderDetailService.java b/src/main/java/org/store/clothstar/orderDetail/service/OrderDetailService.java index adc1d491..95322d55 100644 --- a/src/main/java/org/store/clothstar/orderDetail/service/OrderDetailService.java +++ b/src/main/java/org/store/clothstar/orderDetail/service/OrderDetailService.java @@ -8,7 +8,6 @@ import org.springframework.web.server.ResponseStatusException; import org.store.clothstar.order.entity.OrderEntity; import org.store.clothstar.order.repository.order.OrderRepository; -import org.store.clothstar.order.type.Status; import org.store.clothstar.orderDetail.dto.request.AddOrderDetailRequest; import org.store.clothstar.orderDetail.dto.request.CreateOrderDetailRequest; import org.store.clothstar.orderDetail.entity.OrderDetailEntity; @@ -43,7 +42,6 @@ public OrderDetailService( this.productLineJPARepository = productLineJPARepository; } - // 주문 생성시 같이 호출되는 주문 상세 생성 메서드 - 하나의 트랜잭션으로 묶임 @Transactional public void saveOrderDetailWithOrder(CreateOrderDetailRequest createOrderDetailRequest, long orderId) { @@ -108,7 +106,20 @@ public Long addOrderDetail(AddOrderDetailRequest addOrderDetailRequest) { } @Transactional - void updateProductStock(ProductEntity productEntity, int quantity) { + public void updateDeleteAt(Long orderDetailId) { + OrderDetailEntity orderDetailEntity = orderDetailRepository.findById(orderDetailId) + .orElseThrow(() -> new IllegalArgumentException("주문상세 번호를 찾을 수 없습니다.")); + + if(orderDetailEntity.getDeletedAt() != null){ + throw new IllegalArgumentException("이미 삭제된 주문입니다."); + } + + restoreStockByOrderDetail(orderDetailId); + orderDetailEntity.updateDeletedAt(); + } + + @Transactional + public void updateProductStock(ProductEntity productEntity, int quantity) { long updatedStock = productEntity.getStock() - quantity; productEntity.updateStock(updatedStock); } @@ -116,6 +127,13 @@ void updateProductStock(ProductEntity productEntity, int quantity) { @Transactional public void restoreStockByOrder(Long orderId) { List orderDetailList = orderDetailRepository.findOrderDetailListByOrderId(orderId); - productService.restoreProductStock(orderDetailList); + productService.restoreProductStockByOrder(orderDetailList); + } + + @Transactional + public void restoreStockByOrderDetail(Long orderDetailId) { + OrderDetailEntity orderDetailEntity = orderDetailRepository.findById(orderDetailId) + .orElseThrow(() -> new IllegalArgumentException("주문상세 번호를 찾을 수 없습니다.")); + productService.restoreProductStockByOrderDetail(orderDetailEntity); } } diff --git a/src/main/java/org/store/clothstar/product/service/ProductService.java b/src/main/java/org/store/clothstar/product/service/ProductService.java index 4cf44587..1761c09e 100644 --- a/src/main/java/org/store/clothstar/product/service/ProductService.java +++ b/src/main/java/org/store/clothstar/product/service/ProductService.java @@ -75,11 +75,17 @@ public void deleteProduct(Long productId) { } @Transactional - public void restoreProductStock(List orderDetailList) { + public void restoreProductStockByOrder(List orderDetailList) { orderDetailList.forEach(orderDetailEntity -> { ProductEntity productEntity = productRepository.findById(orderDetailEntity.getProduct().getProductId()) .orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "상품 정보를 찾을 수 없습니다.")); productEntity.restoreStock(orderDetailEntity.getQuantity()); }); } + + public void restoreProductStockByOrderDetail(OrderDetailEntity orderDetailEntity) { + ProductEntity productEntity = productRepository.findById(orderDetailEntity.getProduct().getProductId()) + .orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "상품 정보를 찾을 수 없습니다.")); + productEntity.restoreStock(orderDetailEntity.getQuantity()); + } } diff --git a/src/test/java/org/store/clothstar/orderDetail/service/OrderDetailServiceTest.java b/src/test/java/org/store/clothstar/orderDetail/service/OrderDetailServiceTest.java index 67cb0b73..69ec5667 100644 --- a/src/test/java/org/store/clothstar/orderDetail/service/OrderDetailServiceTest.java +++ b/src/test/java/org/store/clothstar/orderDetail/service/OrderDetailServiceTest.java @@ -213,6 +213,6 @@ void restoreStockByOrder_verify_test() { orderDetailService.restoreStockByOrder(orderId); //then - then(productService).should(times(1)).restoreProductStock(orderDetailList); + then(productService).should(times(1)).restoreProductStockByOrder(orderDetailList); } } \ No newline at end of file From f81a55a5c94fd074843b9304eed6ff03acb8d848 Mon Sep 17 00:00:00 2001 From: subin Date: Sun, 7 Jul 2024 02:38:30 +0900 Subject: [PATCH 14/18] =?UTF-8?q?refactor:=20=EC=A3=BC=EB=AC=B8=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=20=EC=8B=9C,=20=ED=95=98=EC=9C=84=20?= =?UTF-8?q?=EC=A3=BC=EB=AC=B8=20=EC=83=81=EC=84=B8=EB=8F=84=20=ED=95=A8?= =?UTF-8?q?=EA=BB=98=20=EC=82=AD=EC=A0=9C=EB=90=98=EB=8A=94=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 삭제의 의미는 deletedAt이 현재 시간으로 바뀌는 것임. --- .../clothstar/order/service/OrderService.java | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/store/clothstar/order/service/OrderService.java b/src/main/java/org/store/clothstar/order/service/OrderService.java index 7221e331..76bf5959 100644 --- a/src/main/java/org/store/clothstar/order/service/OrderService.java +++ b/src/main/java/org/store/clothstar/order/service/OrderService.java @@ -19,7 +19,13 @@ import org.store.clothstar.order.entity.OrderEntity; import org.store.clothstar.order.repository.order.OrderRepository; import org.store.clothstar.order.type.Status; +import org.store.clothstar.orderDetail.entity.OrderDetailEntity; +import org.store.clothstar.orderDetail.repository.JpaOrderDetailRepository; +import org.store.clothstar.orderDetail.repository.OrderDetailRepository; import org.store.clothstar.orderDetail.service.OrderDetailService; +import org.store.clothstar.product.service.ProductService; + +import java.util.List; @Slf4j @Service @@ -28,16 +34,21 @@ public class OrderService { private final OrderRepository orderRepository; private final MemberRepository memberRepository; private final AddressRepository addressRepository; + private final OrderDetailRepository orderDetailRepository; + private final OrderDetailService orderDetailService; public OrderService( @Qualifier("jpaOrderRepository") OrderRepository orderRepository ,@Qualifier("memberJpaRepository") MemberRepository memberRepository ,@Qualifier("addressJpaRepository") AddressRepository addressRepository - , OrderDetailService orderDetailService - ) { + ,OrderDetailService orderDetailService + ,OrderDetailRepository orderDetailRepository +) { this.orderRepository = orderRepository; this.memberRepository = memberRepository; this.addressRepository = addressRepository; + this.orderDetailRepository = orderDetailRepository; + this.orderDetailService = orderDetailService; } @Transactional(readOnly = true) @@ -87,10 +98,13 @@ public void updateDeleteAt(Long orderId) { OrderEntity orderEntity = orderRepository.findById(orderId) .orElseThrow(() -> new IllegalArgumentException("주문 번호를 찾을 수 없습니다.")); + List orderDetailList = orderDetailRepository.findOrderDetailListByOrderId(orderId); + orderDetailList.forEach(OrderDetailEntity::updateDeletedAt); + if(orderEntity.getDeletedAt() != null){ throw new IllegalArgumentException("이미 삭제된 주문입니다."); } orderEntity.updateDeletedAt(); } -} +} \ No newline at end of file From ae5ec0a75fd25706a27d13c7a66972fcd9febad8 Mon Sep 17 00:00:00 2001 From: subin Date: Sun, 7 Jul 2024 02:53:00 +0900 Subject: [PATCH 15/18] =?UTF-8?q?refactor:=20=EC=A3=BC=EB=AC=B8=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EC=8B=9C,=20=EC=82=AD=EC=A0=9C=EB=90=9C?= =?UTF-8?q?=20=EC=A3=BC=EB=AC=B8=20=EC=83=81=EC=84=B8=EB=8A=94=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=EB=90=98=EC=A7=80=20=EC=95=8A=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=ED=95=98=EB=8A=94=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../orderSeller/OrderEntityRepositoryCustomImpl.java | 6 ++++-- .../org/store/clothstar/order/service/OrderService.java | 3 --- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/store/clothstar/order/repository/orderSeller/OrderEntityRepositoryCustomImpl.java b/src/main/java/org/store/clothstar/order/repository/orderSeller/OrderEntityRepositoryCustomImpl.java index 3ddb5660..d6790d25 100644 --- a/src/main/java/org/store/clothstar/order/repository/orderSeller/OrderEntityRepositoryCustomImpl.java +++ b/src/main/java/org/store/clothstar/order/repository/orderSeller/OrderEntityRepositoryCustomImpl.java @@ -155,7 +155,8 @@ public List findWaitingOrders() { qOrderDetailEntity )) .from(qOrderDetailEntity) - .where(qOrderDetailEntity.order.orderId.eq(result.getOrderId())) + .where(qOrderDetailEntity.order.orderId.eq(result.getOrderId()) + .and(qOrderDetailEntity.deletedAt.isNull())) .fetch(); result.setterOrderDetailList(orderDetailList); @@ -190,7 +191,8 @@ public OrderResponse findOrderWithDetails(Long orderId){ qOrderDetailEntity )) .from(qOrderDetailEntity) - .where(qOrderDetailEntity.order.orderId.eq(orderId)) + .where(qOrderDetailEntity.order.orderId.eq(orderId) + .and(qOrderDetailEntity.deletedAt.isNull())) .fetch(); result.setterOrderDetailList(orderDetailList); diff --git a/src/main/java/org/store/clothstar/order/service/OrderService.java b/src/main/java/org/store/clothstar/order/service/OrderService.java index 76bf5959..22bd17e2 100644 --- a/src/main/java/org/store/clothstar/order/service/OrderService.java +++ b/src/main/java/org/store/clothstar/order/service/OrderService.java @@ -20,10 +20,8 @@ import org.store.clothstar.order.repository.order.OrderRepository; import org.store.clothstar.order.type.Status; import org.store.clothstar.orderDetail.entity.OrderDetailEntity; -import org.store.clothstar.orderDetail.repository.JpaOrderDetailRepository; import org.store.clothstar.orderDetail.repository.OrderDetailRepository; import org.store.clothstar.orderDetail.service.OrderDetailService; -import org.store.clothstar.product.service.ProductService; import java.util.List; @@ -53,7 +51,6 @@ public OrderService( @Transactional(readOnly = true) public OrderResponse getOrder(Long orderId) { - return orderRepository.findOrderWithDetails(orderId); } From 8c46e361a593eec4765201839803f2761d1d1dba Mon Sep 17 00:00:00 2001 From: subin Date: Tue, 9 Jul 2024 07:47:11 +0900 Subject: [PATCH 16/18] wip --- .../repository/ProductRepositoryImpl.java | 35 +++++++++++++++++++ .../product/service/ProductService.java | 1 + 2 files changed, 36 insertions(+) create mode 100644 src/main/java/org/store/clothstar/product/repository/ProductRepositoryImpl.java diff --git a/src/main/java/org/store/clothstar/product/repository/ProductRepositoryImpl.java b/src/main/java/org/store/clothstar/product/repository/ProductRepositoryImpl.java new file mode 100644 index 00000000..4562125f --- /dev/null +++ b/src/main/java/org/store/clothstar/product/repository/ProductRepositoryImpl.java @@ -0,0 +1,35 @@ +package org.store.clothstar.product.repository; + +import org.springframework.stereotype.Repository; +import org.store.clothstar.product.domain.Product; + +import java.util.List; +import java.util.Optional; +@Repository +public class ProductRepositoryImpl implements ProductRepository +{ + @Override + public List selectAllProductByProductLineId(Long productId) { + return List.of(); + } + + @Override + public Optional selectByProductId(Long productId) { + return Optional.empty(); + } + + @Override + public int save(Product product) { + return 0; + } + + @Override + public int updateProduct(Product product) { + return 0; + } + + @Override + public int deleteProduct(Long productId) { + return 0; + } +} diff --git a/src/main/java/org/store/clothstar/product/service/ProductService.java b/src/main/java/org/store/clothstar/product/service/ProductService.java index 1761c09e..8b441421 100644 --- a/src/main/java/org/store/clothstar/product/service/ProductService.java +++ b/src/main/java/org/store/clothstar/product/service/ProductService.java @@ -13,6 +13,7 @@ import org.store.clothstar.product.dto.response.ProductResponse; import org.store.clothstar.product.entity.ProductEntity; import org.store.clothstar.product.repository.ProductJPARepository; +import org.store.clothstar.product.repository.ProductRepository; import org.store.clothstar.productLine.entity.ProductLineEntity; import org.store.clothstar.productLine.repository.ProductLineJPARepository; From e6419e5b5147430466ded9748fc86c04c10499eb Mon Sep 17 00:00:00 2001 From: subin Date: Wed, 10 Jul 2024 11:34:25 +0900 Subject: [PATCH 17/18] =?UTF-8?q?refactor=20:=20WAITING=EC=9D=B8=20?= =?UTF-8?q?=EC=A3=BC=EB=AC=B8=EC=97=90=EB=A7=8C=20=EC=A3=BC=EB=AC=B8=20?= =?UTF-8?q?=EC=83=81=EC=84=B8=20=EC=B6=94=EA=B0=80=20=EA=B0=80=EB=8A=A5?= =?UTF-8?q?=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=A1=B0=EA=B1=B4=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../clothstar/orderDetail/service/OrderDetailService.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/org/store/clothstar/orderDetail/service/OrderDetailService.java b/src/main/java/org/store/clothstar/orderDetail/service/OrderDetailService.java index 95322d55..3523c6fb 100644 --- a/src/main/java/org/store/clothstar/orderDetail/service/OrderDetailService.java +++ b/src/main/java/org/store/clothstar/orderDetail/service/OrderDetailService.java @@ -8,6 +8,7 @@ import org.springframework.web.server.ResponseStatusException; import org.store.clothstar.order.entity.OrderEntity; import org.store.clothstar.order.repository.order.OrderRepository; +import org.store.clothstar.order.type.Status; import org.store.clothstar.orderDetail.dto.request.AddOrderDetailRequest; import org.store.clothstar.orderDetail.dto.request.CreateOrderDetailRequest; import org.store.clothstar.orderDetail.entity.OrderDetailEntity; @@ -91,6 +92,10 @@ public Long addOrderDetail(AddOrderDetailRequest addOrderDetailRequest) { throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "주문 개수가 재고보다 더 많습니다."); } + if(!orderEntity.getStatus().equals(Status.WAITING)){ + throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "주문이 이미 처리된 상태에서는 추가 주문이 불가능합니다."); + } + OrderDetailEntity orderDetailEntity = addOrderDetailRequest.toOrderDetailEntity(orderEntity, productLineEntity, productEntity); orderDetailRepository.save(orderDetailEntity); From c3d642443998b064323610973c21af0eec40f0c8 Mon Sep 17 00:00:00 2001 From: subin Date: Wed, 10 Jul 2024 13:49:43 +0900 Subject: [PATCH 18/18] =?UTF-8?q?=20test=20:=20OrderService-updateDeleteAt?= =?UTF-8?q?=20&=20OrderDetailService-updateDeleteAt,=20restoreStockByOrder?= =?UTF-8?q?Detail=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20&=20warning=20=EB=A9=94=EC=84=B8=EC=A7=80?= =?UTF-8?q?=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../clothstar/order/service/OrderService.java | 11 +- .../service/OrderDetailService.java | 6 +- .../order/service/OrderServiceTest.java | 84 ++++++++++-- .../service/OrderDetailServiceTest.java | 123 ++++++++++++++++-- 4 files changed, 193 insertions(+), 31 deletions(-) diff --git a/src/main/java/org/store/clothstar/order/service/OrderService.java b/src/main/java/org/store/clothstar/order/service/OrderService.java index 22bd17e2..f0749402 100644 --- a/src/main/java/org/store/clothstar/order/service/OrderService.java +++ b/src/main/java/org/store/clothstar/order/service/OrderService.java @@ -1,7 +1,6 @@ package org.store.clothstar.order.service; import lombok.extern.slf4j.Slf4j; -import org.hibernate.query.Order; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -93,15 +92,15 @@ public void deliveredToConfirmOrder(Long orderId) { @Transactional public void updateDeleteAt(Long orderId) { OrderEntity orderEntity = orderRepository.findById(orderId) - .orElseThrow(() -> new IllegalArgumentException("주문 번호를 찾을 수 없습니다.")); - - List orderDetailList = orderDetailRepository.findOrderDetailListByOrderId(orderId); - orderDetailList.forEach(OrderDetailEntity::updateDeletedAt); + .orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "주문 번호를 찾을 수 없습니다.")); if(orderEntity.getDeletedAt() != null){ - throw new IllegalArgumentException("이미 삭제된 주문입니다."); + throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "이미 삭제된 주문입니다."); } + List orderDetailList = orderDetailRepository.findOrderDetailListByOrderId(orderId); + orderDetailList.forEach(OrderDetailEntity::updateDeletedAt); + orderEntity.updateDeletedAt(); } } \ No newline at end of file diff --git a/src/main/java/org/store/clothstar/orderDetail/service/OrderDetailService.java b/src/main/java/org/store/clothstar/orderDetail/service/OrderDetailService.java index 3523c6fb..50bb4cf3 100644 --- a/src/main/java/org/store/clothstar/orderDetail/service/OrderDetailService.java +++ b/src/main/java/org/store/clothstar/orderDetail/service/OrderDetailService.java @@ -113,10 +113,10 @@ public Long addOrderDetail(AddOrderDetailRequest addOrderDetailRequest) { @Transactional public void updateDeleteAt(Long orderDetailId) { OrderDetailEntity orderDetailEntity = orderDetailRepository.findById(orderDetailId) - .orElseThrow(() -> new IllegalArgumentException("주문상세 번호를 찾을 수 없습니다.")); + .orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "주문상세 번호를 찾을 수 없습니다.")); if(orderDetailEntity.getDeletedAt() != null){ - throw new IllegalArgumentException("이미 삭제된 주문입니다."); + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "이미 삭제된 주문입니다."); } restoreStockByOrderDetail(orderDetailId); @@ -138,7 +138,7 @@ public void restoreStockByOrder(Long orderId) { @Transactional public void restoreStockByOrderDetail(Long orderDetailId) { OrderDetailEntity orderDetailEntity = orderDetailRepository.findById(orderDetailId) - .orElseThrow(() -> new IllegalArgumentException("주문상세 번호를 찾을 수 없습니다.")); + .orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "주문상세 번호를 찾을 수 없습니다.")); productService.restoreProductStockByOrderDetail(orderDetailEntity); } } diff --git a/src/test/java/org/store/clothstar/order/service/OrderServiceTest.java b/src/test/java/org/store/clothstar/order/service/OrderServiceTest.java index 9a9b5bc8..af9bf271 100644 --- a/src/test/java/org/store/clothstar/order/service/OrderServiceTest.java +++ b/src/test/java/org/store/clothstar/order/service/OrderServiceTest.java @@ -6,9 +6,7 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; -import org.springframework.data.domain.Slice; import org.springframework.web.server.ResponseStatusException; import org.store.clothstar.member.domain.Address; import org.store.clothstar.member.domain.Member; @@ -22,7 +20,11 @@ import org.store.clothstar.order.entity.OrderEntity; import org.store.clothstar.order.repository.order.OrderRepository; import org.store.clothstar.order.type.Status; +import org.store.clothstar.orderDetail.entity.OrderDetailEntity; +import org.store.clothstar.orderDetail.repository.OrderDetailRepository; +import java.time.LocalDateTime; +import java.util.List; import java.util.Optional; import static org.assertj.core.api.Assertions.assertThat; @@ -39,12 +41,18 @@ class OrderServiceTest { @Mock private OrderRepository orderRepository; + @Mock + private OrderDetailRepository orderDetailRepository; + @Mock private MemberRepository memberRepository; @Mock private AddressRepository addressRepository; + @Mock + private OrderDetailEntity orderDetailEntity; + @Test @DisplayName("getOrder: 주문 조회 - 메서드 호출 & 반환값 테스트") void getOrder_test() { @@ -159,9 +167,8 @@ void saveOrder_member_exception_test() { given(memberRepository.findById(1L)).willReturn(Optional.empty()); //when - ResponseStatusException thrown = assertThrows(ResponseStatusException.class, () -> { - orderService.saveOrder(orderRequestWrapper.getCreateOrderRequest()); - }); + ResponseStatusException thrown = assertThrows(ResponseStatusException.class, () -> + orderService.saveOrder(orderRequestWrapper.getCreateOrderRequest())); //then assertEquals("400 BAD_REQUEST \"회원 정보를 찾을 수 없습니다.\"", thrown.getMessage()); @@ -184,9 +191,8 @@ void saveOrder_address_exception_test() { given(addressRepository.findById(2L)).willReturn(Optional.empty()); //when - ResponseStatusException thrown = assertThrows(ResponseStatusException.class, () -> { - orderService.saveOrder(orderRequestWrapper.getCreateOrderRequest()); - }); + ResponseStatusException thrown = assertThrows(ResponseStatusException.class, () -> + orderService.saveOrder(orderRequestWrapper.getCreateOrderRequest())); //then assertEquals("400 BAD_REQUEST \"배송지 정보를 찾을 수 없습니다.\"", thrown.getMessage()); @@ -222,11 +228,67 @@ void deliveredToConfirmOrder_fail_exception_test() { given(orderRepository.findById(orderId)).willReturn(Optional.of(mockOrder)); //when - ResponseStatusException thrown = assertThrows(ResponseStatusException.class, () -> { - orderService.deliveredToConfirmOrder(orderId); - }); + ResponseStatusException thrown = assertThrows(ResponseStatusException.class, () -> + orderService.deliveredToConfirmOrder(orderId)); //then assertEquals("400 BAD_REQUEST \"주문 상태가 '배송완료'가 아니기 때문에 주문확정이 불가능합니다.\"", thrown.getMessage()); } + + @Test + @DisplayName("updateDeleteAt: 주문 삭제 - 메서드 호출 테스트") + void updateDeleteAt_verify_test() { + //given + Long orderId = 1L; + OrderEntity orderEntity = mock(OrderEntity.class); + OrderDetailEntity mockOrderDetail1 = mock(OrderDetailEntity.class); + OrderDetailEntity mockOrderDetail2 = mock(OrderDetailEntity.class); + OrderDetailEntity mockOrderDetail3 = mock(OrderDetailEntity.class); + List orderDetailList = List.of(mockOrderDetail1, mockOrderDetail2, mockOrderDetail3); + given(orderRepository.findById(1L)).willReturn(Optional.of(orderEntity)); + given(orderDetailRepository.findOrderDetailListByOrderId(orderId)).willReturn(orderDetailList); + + //when + orderService.updateDeleteAt(orderId); + + //then + verify(mockOrderDetail1, times(1)).updateDeletedAt(); + verify(mockOrderDetail2, times(1)).updateDeletedAt(); + verify(mockOrderDetail3, times(1)).updateDeletedAt(); + then(orderRepository).should(times(1)).findById(orderId); + then(orderDetailRepository).should().findOrderDetailListByOrderId(orderId); + then(orderEntity).should(times(1)).updateDeletedAt(); + } + + @Test + @DisplayName("updateDeleteAt: 주문 삭제 - orderEntity null 예외처리 테스트") + void updateDeleteAt_orderEntityNull_exception_test() { + //given + Long orderId = 1L; + given(orderRepository.findById(1L)).willReturn(Optional.empty()); + + //when + ResponseStatusException thrown = assertThrows(ResponseStatusException.class, () -> + orderService.updateDeleteAt(orderId)); + + //then + assertEquals("404 NOT_FOUND \"주문 번호를 찾을 수 없습니다.\"", thrown.getMessage()); + } + + @Test + @DisplayName("updateDeleteAt: 주문 삭제 - 이미 삭제된 경우 예외처리 테스트") + void updateDeleteAt_alreadyDelete_exception_test() { + //given + Long orderId = 1L; + OrderEntity orderEntity = mock(OrderEntity.class); + given(orderRepository.findById(1L)).willReturn(Optional.of(orderEntity)); + given(orderEntity.getDeletedAt()).willReturn(LocalDateTime.now()); + + //when + ResponseStatusException thrown = assertThrows(ResponseStatusException.class, () -> + orderService.updateDeleteAt(orderId)); + + //then + assertEquals("400 BAD_REQUEST \"이미 삭제된 주문입니다.\"", thrown.getMessage()); + } } \ No newline at end of file diff --git a/src/test/java/org/store/clothstar/orderDetail/service/OrderDetailServiceTest.java b/src/test/java/org/store/clothstar/orderDetail/service/OrderDetailServiceTest.java index 69ec5667..cb156af1 100644 --- a/src/test/java/org/store/clothstar/orderDetail/service/OrderDetailServiceTest.java +++ b/src/test/java/org/store/clothstar/orderDetail/service/OrderDetailServiceTest.java @@ -9,6 +9,7 @@ import org.springframework.web.server.ResponseStatusException; import org.store.clothstar.order.entity.OrderEntity; import org.store.clothstar.order.repository.order.OrderRepository; +import org.store.clothstar.order.type.Status; import org.store.clothstar.orderDetail.dto.request.AddOrderDetailRequest; import org.store.clothstar.orderDetail.dto.request.CreateOrderDetailRequest; import org.store.clothstar.orderDetail.entity.OrderDetailEntity; @@ -19,6 +20,7 @@ import org.store.clothstar.productLine.entity.ProductLineEntity; import org.store.clothstar.productLine.repository.ProductLineJPARepository; +import java.time.LocalDateTime; import java.util.List; import java.util.Optional; @@ -47,6 +49,9 @@ class OrderDetailServiceTest { @Mock private ProductJPARepository productJPARepository; + @Mock + private OrderDetailEntity orderDetailEntity; + @DisplayName("saveOrderDetailWithOrder: 주문상세 생성 - 메서드 호출 테스트") @Test void saveOrderDetailWithOrder_verify_test() { @@ -91,9 +96,8 @@ void saveOrderDetailWithOrder_exception_test() { given(mockProduct.getStock()).willReturn(1L); //when - ResponseStatusException thrown = assertThrows(ResponseStatusException.class, () -> { - orderDetailService.saveOrderDetailWithOrder(mockRequest,orderId); - }); + ResponseStatusException thrown = assertThrows(ResponseStatusException.class, () -> + orderDetailService.saveOrderDetailWithOrder(mockRequest,orderId)); //then assertEquals("400 BAD_REQUEST \"주문 개수가 재고보다 더 많습니다.\"", thrown.getMessage()); @@ -115,9 +119,8 @@ void getOrderDetail_quantityZero_exception_test() { given(mockProduct.getStock()).willReturn(1L); //when - ResponseStatusException thrown = assertThrows(ResponseStatusException.class, () -> { - orderDetailService.addOrderDetail(mockRequest); - }); + ResponseStatusException thrown = assertThrows(ResponseStatusException.class, () -> + orderDetailService.addOrderDetail(mockRequest)); //then assertEquals("400 BAD_REQUEST \"주문 개수가 재고보다 더 많습니다.\"", thrown.getMessage()); @@ -135,6 +138,7 @@ void addOrderDetail_test() { OrderEntity mockOrder = mock(OrderEntity.class); given(mockOrderDetail.getOrderDetailId()).willReturn(1L); + given(mockOrder.getStatus()).willReturn(Status.WAITING); given(orderRepository.findById(mockRequest.getOrderId())).willReturn(Optional.of(mockOrder)); given(productLineJPARepository.findById(mockRequest.getProductLineId())).willReturn(Optional.of(mockProductLine)); given(productJPARepository.findById(mockRequest.getProductId())).willReturn(Optional.of(mockProduct)); @@ -157,6 +161,7 @@ void addOrderDetail_verify_test() { ProductEntity mockProduct = mock(ProductEntity.class); OrderEntity mockOrder = mock(OrderEntity.class); + given(mockOrder.getStatus()).willReturn(Status.WAITING); given(orderRepository.findById(mockRequest.getOrderId())).willReturn(Optional.of(mockOrder)); given(productLineJPARepository.findById(mockRequest.getProductLineId())).willReturn(Optional.of(mockProductLine)); given(productJPARepository.findById(mockRequest.getProductId())).willReturn(Optional.of(mockProduct)); @@ -170,8 +175,6 @@ void addOrderDetail_verify_test() { then(productLineJPARepository).should(times(1)).findById(mockRequest.getProductLineId()); then(productJPARepository).should(times(1)).findById(mockRequest.getProductId()); then(orderDetailRepository).should(times(1)).save(mockOrderDetail); -// then(orderRepository).should(times(1)).updateOrderPrices(mockOrder); -// then(productJPARepository).should(times(1)).updateProduct(mockProduct); } @DisplayName("addOrderDetail: 주문상세 추가 - 주문 유효성 검사 예외처리 테스트") @@ -190,14 +193,82 @@ void addOrderDetail_quantityZero_exception_test() { given(mockProduct.getStock()).willReturn(1L); //when - ResponseStatusException thrown = assertThrows(ResponseStatusException.class, () -> { - orderDetailService.addOrderDetail(mockRequest); - }); + ResponseStatusException thrown = assertThrows(ResponseStatusException.class, () -> + orderDetailService.addOrderDetail(mockRequest)); //then assertEquals("400 BAD_REQUEST \"주문 개수가 재고보다 더 많습니다.\"", thrown.getMessage()); } + @DisplayName("addOrderDetail: 주문상세 추가 - 주문 상태 검사 예외처리 테스트") + @Test + void addOrderDetail_noWAITING_exception_test() { + //given + AddOrderDetailRequest mockRequest = mock(AddOrderDetailRequest.class); + ProductLineEntity mockProductLine = mock(ProductLineEntity.class); + ProductEntity mockProduct = mock(ProductEntity.class); + OrderEntity mockOrder = mock(OrderEntity.class); + + given(mockOrder.getStatus()).willReturn(Status.CANCEL); + given(orderRepository.findById(mockRequest.getOrderId())).willReturn(Optional.of(mockOrder)); + given(productLineJPARepository.findById(mockRequest.getProductLineId())).willReturn(Optional.of(mockProductLine)); + given(productJPARepository.findById(mockRequest.getProductId())).willReturn(Optional.of(mockProduct)); + + //when + ResponseStatusException thrown = assertThrows(ResponseStatusException.class, () -> + orderDetailService.addOrderDetail(mockRequest)); + + //then + assertEquals("400 BAD_REQUEST \"주문이 이미 처리된 상태에서는 추가 주문이 불가능합니다.\"", thrown.getMessage()); + } + + @Test + @DisplayName("updateDeleteAt: 주문 상세 삭제 - 메서드 호출 테스트") + void updateDeleteAt_verify_test() { + //given + long orderDetailId = 1L; + given(orderDetailRepository.findById(orderDetailId)).willReturn(Optional.of(orderDetailEntity)); + + //when + orderDetailService.updateDeleteAt(orderDetailId); + + //then + then(orderDetailRepository).should(times(2)).findById(orderDetailId); + then(productService).should(times(1)).restoreProductStockByOrderDetail(orderDetailEntity); + then(orderDetailEntity).should(times(1)).updateDeletedAt(); + } + + @Test + @DisplayName("updateDeleteAt: 주문 상세 삭제 - OrderDetail null 예외처리 테스트") + void updateDeleteAt_null_exception_test() { + //given + long orderDetailId = 1L; + given(orderDetailRepository.findById(orderDetailId)).willReturn(Optional.empty()); + + //when + ResponseStatusException thrown = assertThrows(ResponseStatusException.class, () -> + orderDetailService.updateDeleteAt(orderDetailId)); + + //then + assertEquals("404 NOT_FOUND \"주문상세 번호를 찾을 수 없습니다.\"", thrown.getMessage()); + } + + @Test + @DisplayName("updateDeleteAt: 주문 상세 삭제 - 이미 삭제된 경우 예외처리 테스트") + void updateDeleteAt_alreadyDelete_exception_test() { + //given + long orderDetailId = 1L; + given(orderDetailRepository.findById(orderDetailId)).willReturn(Optional.of(orderDetailEntity)); + given(orderDetailEntity.getDeletedAt()).willReturn(LocalDateTime.now()); + + //when + ResponseStatusException thrown = assertThrows(ResponseStatusException.class, () -> + orderDetailService.updateDeleteAt(orderDetailId)); + + //then + assertEquals("404 NOT_FOUND \"이미 삭제된 주문입니다.\"", thrown.getMessage()); + } + @Test @DisplayName("restoreStockByOrder: 주문 취소시, 상품 재고 반환 - 메서드 호출 테스트") void restoreStockByOrder_verify_test() { @@ -215,4 +286,34 @@ void restoreStockByOrder_verify_test() { //then then(productService).should(times(1)).restoreProductStockByOrder(orderDetailList); } + + @Test + @DisplayName("restoreStockByOrderDetail: 주문 상세 삭제시, 상품 재고 반환 - 메서드 호출 테스트") + void restoreStockByOrderDetail_verify_test() { + //given + long orderDetailId = 1L; + OrderDetailEntity mockOrderDetail = mock(OrderDetailEntity.class); + given(orderDetailRepository.findById(orderDetailId)).willReturn(Optional.of(mockOrderDetail)); + + //when + orderDetailService.restoreStockByOrderDetail(orderDetailId); + + //then + then(productService).should(times(1)).restoreProductStockByOrderDetail(mockOrderDetail); + } + + @Test + @DisplayName("restoreStockByOrderDetail: 주문 상세 삭제시, 상품 재고 반환 - orderDetail null 예외처리 테스트") + void restoreStockByOrderDetail_null_exception_test() { + //given + long orderDetailId = 1L; + given(orderDetailRepository.findById(orderDetailId)).willReturn(Optional.empty()); + + //when + ResponseStatusException thrown = assertThrows(ResponseStatusException.class, () -> + orderDetailService.restoreStockByOrderDetail(orderDetailId)); + + //then + assertEquals("404 NOT_FOUND \"주문상세 번호를 찾을 수 없습니다.\"", thrown.getMessage()); + } } \ No newline at end of file