From f92cca97c052497eba227328077beff6213b3e85 Mon Sep 17 00:00:00 2001 From: subin Date: Mon, 12 Aug 2024 18:49:00 +0900 Subject: [PATCH 01/10] =?UTF-8?q?feat:=20=EC=A3=BC=EB=AC=B8=EC=83=81?= =?UTF-8?q?=EC=84=B8=20=EC=B6=94=EA=B0=80=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 - OrderUserController에 주문상세 기능 포함 --- .../order/controller/OrderUserController.kt | 36 ++- .../order/service/OrderDetailService.kt | 233 +++++++++--------- .../order/service/OrderUserService.kt | 51 ++++ 3 files changed, 198 insertions(+), 122 deletions(-) diff --git a/src/main/kotlin/org/store/clothstar/order/controller/OrderUserController.kt b/src/main/kotlin/org/store/clothstar/order/controller/OrderUserController.kt index 10479eb..82ce4a3 100644 --- a/src/main/kotlin/org/store/clothstar/order/controller/OrderUserController.kt +++ b/src/main/kotlin/org/store/clothstar/order/controller/OrderUserController.kt @@ -12,6 +12,8 @@ import org.springframework.validation.annotation.Validated import org.springframework.web.bind.annotation.* import org.store.clothstar.common.dto.ErrorResponseDTO import org.store.clothstar.common.dto.MessageDTO +import org.store.clothstar.common.dto.SaveResponseDTO +import org.store.clothstar.order.dto.request.AddOrderDetailRequest import org.store.clothstar.order.dto.request.OrderRequestWrapper import org.store.clothstar.order.dto.response.SaveOrderResponse import org.store.clothstar.order.service.OrderUserService @@ -20,7 +22,7 @@ import org.store.clothstar.order.service.OrderUserService @RestController @RequestMapping("/v1/orders") class OrderUserController( - private val orderService: OrderUserService + private val orderUserService: OrderUserService, ) { // @Operation(summary = "단일 주문 조회", description = "단일 주문의 정보를 조회한다.") // @GetMapping("/{orderId}") @@ -48,11 +50,35 @@ class OrderUserController( ) @PostMapping fun saveOrder(@RequestBody @Validated orderRequestWrapper: OrderRequestWrapper): ResponseEntity { - val orderId: String = orderService.saveOrder(orderRequestWrapper) + val orderId: String = orderUserService.saveOrder(orderRequestWrapper) val saveOrderResponse = SaveOrderResponse(orderId, HttpStatus.OK.value(), "주문이 정상적으로 생성되었습니다.") return ResponseEntity.ok(saveOrderResponse) } + @Operation(summary = "주문상세 추가 저장", description = "개별 상품에 대한 주문상세(상품명, 가격, 개수...)를 특정 주문에 추가 저장한다.") + @ApiResponses( + value = [ + ApiResponse( + responseCode = "200", description = "주문상세가 정상적으로 생성되었습니다.", + content = [Content(schema = Schema(implementation = SaveOrderResponse::class))] + ), + ApiResponse( + responseCode = "404", description = "", + content = [Content(schema = Schema(implementation = ErrorResponseDTO::class))] + ), + ApiResponse( + responseCode = "400", description = "", + content = [Content(schema = Schema(implementation = ErrorResponseDTO::class))] + ), + ] + ) + @PostMapping("/details") + fun addOrderDetail(@RequestBody @Validated addOrderDetailRequest: AddOrderDetailRequest): ResponseEntity { + val orderDetailId = orderUserService.addOrderDetail(addOrderDetailRequest) + val saveResponseDTO = SaveResponseDTO(orderDetailId, HttpStatus.OK.value(), "주문상세가 정상적으로 생성되었습니다.") + return ResponseEntity.ok(saveResponseDTO) + } + @Operation(summary = "구매자 구매 확정", description = "구매자가 주문을 구매확정하면, 주문상태가 '구매확정'으로 변경된다(단, 주문상태가 '배송완료'일 때만 가능).") @ApiResponses( value = [ @@ -72,7 +98,7 @@ class OrderUserController( ) @PatchMapping("{orderId}/complete") fun confirmOrder(@PathVariable orderId: String): ResponseEntity { - orderService.completeOrder(orderId) + orderUserService.completeOrder(orderId) val messageDTO = MessageDTO(HttpStatus.OK.value(), "주문이 정상적으로 구매 확정 되었습니다.") return ResponseEntity.ok(messageDTO) } @@ -99,7 +125,7 @@ class OrderUserController( ) @PatchMapping("{orderId}/cancel") fun cancelOrder(@PathVariable orderId: String): ResponseEntity { - orderService.cancelOrder(orderId) + orderUserService.cancelOrder(orderId) val messageDTO = MessageDTO(HttpStatus.OK.value(), "주문이 정상적으로 취소되었습니다.") return ResponseEntity.ok(messageDTO) } @@ -119,7 +145,7 @@ class OrderUserController( @Operation(summary = "주문 삭제", description = "주문 삭제시간을 현재시간으로 업데이트 한다.") @DeleteMapping("{orderId}") fun deleteOrder(@PathVariable orderId: String): ResponseEntity { - orderService.updateDeleteAt(orderId) + orderUserService.updateDeleteAt(orderId) val messageDTO = MessageDTO(HttpStatus.OK.value(), "주문이 정상적으로 삭제되었습니다.") return ResponseEntity.ok(messageDTO) } diff --git a/src/main/kotlin/org/store/clothstar/order/service/OrderDetailService.kt b/src/main/kotlin/org/store/clothstar/order/service/OrderDetailService.kt index 65e82b6..34857e9 100644 --- a/src/main/kotlin/org/store/clothstar/order/service/OrderDetailService.kt +++ b/src/main/kotlin/org/store/clothstar/order/service/OrderDetailService.kt @@ -1,117 +1,116 @@ -package org.store.clothstar.order.service - -import org.springframework.data.repository.findByIdOrNull -import org.springframework.http.HttpStatus -import org.springframework.stereotype.Service -import org.springframework.transaction.annotation.Transactional -import org.springframework.web.server.ResponseStatusException -import org.store.clothstar.order.domain.vo.Status -import org.store.clothstar.order.dto.request.AddOrderDetailRequest -import org.store.clothstar.order.dto.request.CreateOrderDetailRequest -import org.store.clothstar.order.repository.OrderDetailRepository -import org.store.clothstar.order.repository.OrderRepository -import org.store.clothstar.product.domain.Item -import org.store.clothstar.product.repository.ItemRepository -import org.store.clothstar.product.repository.ProductRepository -import org.store.clothstar.product.service.ItemService - -@Service -class OrderDetailService( - private val orderRepository: OrderRepository, - private val orderDetailRepository: OrderDetailRepository, - private val productRepository: ProductRepository, - private val itemRepository: ItemRepository, - private val itemService: ItemService, -) { - // 주문 생성시 같이 호출되는 주문 상세 생성 메서드 - 하나의 트랜잭션으로 묶임 - @Transactional - fun saveOrderDetailWithOrder(createOrderDetailRequest: CreateOrderDetailRequest, orderId: String) { - val order = orderRepository.findByIdOrNull(orderId) - ?: throw ResponseStatusException(HttpStatus.NOT_FOUND, "주문 정보를 찾을 수 없습니다.") - - val product = productRepository.findByIdOrNull(createOrderDetailRequest.productId) - ?: throw ResponseStatusException(HttpStatus.NOT_FOUND, "상품 옵션 정보를 찾을 수 없습니다.") - - val item = itemRepository.findByIdOrNull(createOrderDetailRequest.itemId) - ?: throw ResponseStatusException(HttpStatus.NOT_FOUND, "상품 정보를 찾을 수 없습니다.") - - // 주문상세 생성 유효성 검사: 주문 수량이 상품 재고보다 클 경우, 주문이 생성되지 않는다. - if (createOrderDetailRequest.quantity > item.stock) { - throw ResponseStatusException(HttpStatus.BAD_REQUEST, "주문 개수가 재고보다 더 많습니다.") - } - - val orderDetail = createOrderDetailRequest.toOrderDetail(order, product, item) - orderDetailRepository.save(orderDetail) - - // 주문 정보 업데이트: 주문 상세 생성에 따른, 총 상품 금액과 총 결제 금액 업데이트 - val newTotalProductsPrice = order.totalPrice.products + orderDetail.price.oneKindTotalPrice - val newTotalPaymentPrice = - order.totalPrice.products + order.totalPrice.shipping + orderDetail.price.oneKindTotalPrice - - order.totalPrice.updatePrices(newTotalProductsPrice, newTotalPaymentPrice) - - // 주문 수량만큼 상품 재고 차감 - updateProductStock(item, orderDetail.quantity) - } - - // 주문 상세 추가 생성 - @Transactional - fun addOrderDetail(addOrderDetailRequest: AddOrderDetailRequest): Long { - val order = orderRepository.findByIdOrNull(addOrderDetailRequest.orderId) - ?: throw ResponseStatusException(HttpStatus.NOT_FOUND, "주문 정보를 찾을 수 없습니다.") - - val product = productRepository.findByIdOrNull(addOrderDetailRequest.productId) - ?: throw ResponseStatusException(HttpStatus.NOT_FOUND, "상품 옵션 정보를 찾을 수 없습니다.") - - val item = itemRepository.findByIdOrNull(addOrderDetailRequest.itemId) - ?: throw ResponseStatusException(HttpStatus.NOT_FOUND, "상품 정보를 찾을 수 없습니다.") - - if (addOrderDetailRequest.quantity > item.stock) { - throw ResponseStatusException(HttpStatus.BAD_REQUEST, "주문 개수가 재고보다 더 많습니다.") - } - - if (order.status != Status.CONFIRMED) { - throw ResponseStatusException(HttpStatus.BAD_REQUEST, "이미 입금된 상태에서는 추가 주문이 불가능합니다.") - } - - val orderDetail = addOrderDetailRequest.toOrderDetail(order, product, item) - orderDetailRepository.save(orderDetail) - - val newTotalProductsPrice = order.totalPrice.products + orderDetail.price.oneKindTotalPrice - val newTotalPaymentPrice = - order.totalPrice.products + order.totalPrice.shipping + orderDetail.price.oneKindTotalPrice - - order.totalPrice.updatePrices(newTotalProductsPrice, newTotalPaymentPrice) - - updateProductStock(item, orderDetail.quantity) - - return orderDetail.orderDetailId!! - } - - @Transactional - fun updateDeleteAt(orderDetailId: Long) { - val orderDetail = orderDetailRepository.findById(orderDetailId) - .orElseThrow { ResponseStatusException(HttpStatus.NOT_FOUND, "주문상세 번호를 찾을 수 없습니다.") } - - if (orderDetail.deletedAt != null) { - throw ResponseStatusException(HttpStatus.NOT_FOUND, "이미 삭제된 주문입니다.") - } - - restoreStockByOrderDetail(orderDetailId) - orderDetail.updateDeletedAt() - } - - @Transactional - fun updateProductStock(item: Item, quantity: Int) { - val updatedStock = item.stock - quantity - item.updateStock(updatedStock) - } - - @Transactional - fun restoreStockByOrderDetail(orderDetailId: Long) { - val orderDetail = orderDetailRepository.findByIdOrNull(orderDetailId) - ?: throw ResponseStatusException(HttpStatus.NOT_FOUND, "주문상세 번호를 찾을 수 없습니다.") - - itemService.restoreProductStockByOrderDetail(orderDetail) - } -} \ No newline at end of file +//package org.store.clothstar.order.service +// +//import org.springframework.data.repository.findByIdOrNull +//import org.springframework.http.HttpStatus +//import org.springframework.stereotype.Service +//import org.springframework.transaction.annotation.Transactional +//import org.springframework.web.server.ResponseStatusException +//import org.store.clothstar.common.error.ErrorCode +//import org.store.clothstar.common.error.exception.order.OrderNotFoundException +//import org.store.clothstar.order.domain.vo.Status +//import org.store.clothstar.order.dto.request.AddOrderDetailRequest +//import org.store.clothstar.order.dto.request.CreateOrderDetailRequest +//import org.store.clothstar.order.repository.OrderDetailRepository +//import org.store.clothstar.order.repository.OrderRepository +//import org.store.clothstar.product.domain.Item +//import org.store.clothstar.product.domain.Product +//import org.store.clothstar.product.repository.ItemRepository +//import org.store.clothstar.product.repository.ProductRepository +//import org.store.clothstar.product.service.ItemService +// +//@Service +//class OrderDetailService( +// private val orderRepository: OrderRepository, +// private val orderDetailRepository: OrderDetailRepository, +// private val productRepository: ProductRepository, +// private val itemRepository: ItemRepository, +// private val itemService: ItemService, +//) { +//// // 주문 생성시 같이 호출되는 주문 상세 생성 메서드 - 하나의 트랜잭션으로 묶임 +//// @Transactional +//// fun saveOrderDetailWithOrder(createOrderDetailRequest: CreateOrderDetailRequest, orderId: String) { +//// val order = orderRepository.findByIdOrNull(orderId) +//// ?: throw ResponseStatusException(HttpStatus.NOT_FOUND, "주문 정보를 찾을 수 없습니다.") +//// +//// val product = productRepository.findByIdOrNull(createOrderDetailRequest.productId) +//// ?: throw ResponseStatusException(HttpStatus.NOT_FOUND, "상품 옵션 정보를 찾을 수 없습니다.") +//// +//// val item = itemRepository.findByIdOrNull(createOrderDetailRequest.itemId) +//// ?: throw ResponseStatusException(HttpStatus.NOT_FOUND, "상품 정보를 찾을 수 없습니다.") +//// +//// // 주문상세 생성 유효성 검사: 주문 수량이 상품 재고보다 클 경우, 주문이 생성되지 않는다. +//// if (createOrderDetailRequest.quantity > item.stock) { +//// throw ResponseStatusException(HttpStatus.BAD_REQUEST, "주문 개수가 재고보다 더 많습니다.") +//// } +//// +//// val orderDetail = createOrderDetailRequest.toOrderDetail(order, product, item) +//// orderDetailRepository.save(orderDetail) +//// +//// // 주문 정보 업데이트: 주문 상세 생성에 따른, 총 상품 금액과 총 결제 금액 업데이트 +//// val newTotalProductsPrice = order.totalPrice.products + orderDetail.price.oneKindTotalPrice +//// val newTotalPaymentPrice = +//// order.totalPrice.products + order.totalPrice.shipping + orderDetail.price.oneKindTotalPrice +//// +//// order.totalPrice.updatePrices(newTotalProductsPrice, newTotalPaymentPrice) +//// +//// // 주문 수량만큼 상품 재고 차감 +//// updateProductStock(item, orderDetail.quantity) +//// } +// +// // 주문 상세 추가 생성( +// @Transactional +// fun addOrderDetail(addOrderDetailRequest: AddOrderDetailRequest): Long { +// val order = orderRepository.findByIdOrNull(addOrderDetailRequest.orderId) +// ?: throw OrderNotFoundException(ErrorCode.NOT_FOUND_ORDER) +// val product: Product = productService.getProductById(addOrderDetailRequest.productId) +// val item: Item = itemService.getItemById(addOrderDetailRequest.itemId) +// +// if (addOrderDetailRequest.quantity > item.stock) { +// throw ResponseStatusException(HttpStatus.BAD_REQUEST, "주문 개수가 재고보다 더 많습니다.") +// } +// +// if (order.status != Status.CONFIRMED) { +// throw ResponseStatusException(HttpStatus.BAD_REQUEST, "이미 입금된 상태에서는 추가 주문이 불가능합니다.") +// } +// +// val orderDetail = addOrderDetailRequest.toOrderDetail(order, product, item) +// orderDetailRepository.save(orderDetail) +// +// val newTotalProductsPrice = order.totalPrice.products + orderDetail.price.oneKindTotalPrice +// val newTotalPaymentPrice = +// order.totalPrice.products + order.totalPrice.shipping + orderDetail.price.oneKindTotalPrice +// +// order.totalPrice.updatePrices(newTotalProductsPrice, newTotalPaymentPrice) +// +// updateProductStock(item, orderDetail.quantity) +// +// return orderDetail.orderDetailId!! +// } +//// +//// @Transactional +//// fun updateDeleteAt(orderDetailId: Long) { +//// val orderDetail = orderDetailRepository.findById(orderDetailId) +//// .orElseThrow { ResponseStatusException(HttpStatus.NOT_FOUND, "주문상세 번호를 찾을 수 없습니다.") } +//// +//// if (orderDetail.deletedAt != null) { +//// throw ResponseStatusException(HttpStatus.NOT_FOUND, "이미 삭제된 주문입니다.") +//// } +//// +//// restoreStockByOrderDetail(orderDetailId) +//// orderDetail.updateDeletedAt() +//// } +// +// @Transactional +// fun updateProductStock(item: Item, quantity: Int) { +// val updatedStock = item.stock - quantity +// item.updateStock(updatedStock) +// } +//// +//// @Transactional +//// fun restoreStockByOrderDetail(orderDetailId: Long) { +//// val orderDetail = orderDetailRepository.findByIdOrNull(orderDetailId) +//// ?: throw ResponseStatusException(HttpStatus.NOT_FOUND, "주문상세 번호를 찾을 수 없습니다.") +//// +//// itemService.restoreProductStockByOrderDetail(orderDetail) +//// } +//} \ No newline at end of file diff --git a/src/main/kotlin/org/store/clothstar/order/service/OrderUserService.kt b/src/main/kotlin/org/store/clothstar/order/service/OrderUserService.kt index 6fc83a5..0dc439d 100644 --- a/src/main/kotlin/org/store/clothstar/order/service/OrderUserService.kt +++ b/src/main/kotlin/org/store/clothstar/order/service/OrderUserService.kt @@ -1,27 +1,78 @@ package org.store.clothstar.order.service import org.springframework.data.repository.findByIdOrNull +import org.springframework.http.HttpStatus import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional +import org.springframework.web.server.ResponseStatusException import org.store.clothstar.common.error.ErrorCode +import org.store.clothstar.common.error.exception.order.InsufficientStockException import org.store.clothstar.common.error.exception.order.OrderNotFoundException +import org.store.clothstar.order.domain.Order import org.store.clothstar.order.domain.vo.Status +import org.store.clothstar.order.dto.request.AddOrderDetailRequest import org.store.clothstar.order.dto.request.OrderRequestWrapper import org.store.clothstar.order.repository.OrderDetailRepository import org.store.clothstar.order.repository.OrderRepository +import org.store.clothstar.order.service.OrderSave.OrderDetailValidater import org.store.clothstar.order.service.OrderSave.OrderSaveFacade +import org.store.clothstar.product.domain.Item +import org.store.clothstar.product.domain.Product +import org.store.clothstar.product.repository.ProductRepository +import org.store.clothstar.product.service.ItemService +import org.store.clothstar.product.service.ProductService @Service class OrderUserService( private val orderSaveFacade: OrderSaveFacade, private val orderRepository: OrderRepository, private val orderDetailRepository: OrderDetailRepository, + private val productService: ProductService, + private val itemService: ItemService, + private val orderDetailValidater: OrderDetailValidater, ) { @Transactional fun saveOrder(orderRequestWrapper: OrderRequestWrapper): String { return orderSaveFacade.saveOrder(orderRequestWrapper) } + // 주문 상세 추가 생성( + @Transactional + fun addOrderDetail(addOrderDetailRequest: AddOrderDetailRequest): Long { + // 요청 DTO와 관련된 order, product, item 불러오기 + val order = orderRepository.findByIdOrNull(addOrderDetailRequest.orderId) + ?: throw OrderNotFoundException(ErrorCode.NOT_FOUND_ORDER) + val product: Product = productService.getProductById(addOrderDetailRequest.productId) + val item: Item = itemService.getItemById(addOrderDetailRequest.itemId) + + if (addOrderDetailRequest.quantity > item.stock) { + throw InsufficientStockException(ErrorCode.INSUFFICIENT_STOCK) + } + + if (order.status != Status.CONFIRMED) { + throw ResponseStatusException(HttpStatus.BAD_REQUEST, "이미 입금된 상태에서는 추가 주문이 불가능합니다.") + } + + val orderDetail = addOrderDetailRequest.toOrderDetail(order, product, item) + orderDetailRepository.save(orderDetail) + + val newTotalProductsPrice = order.totalPrice.products + orderDetail.price.oneKindTotalPrice + val newTotalPaymentPrice = + order.totalPrice.products + order.totalPrice.shipping + orderDetail.price.oneKindTotalPrice + + order.totalPrice.updatePrices(newTotalProductsPrice, newTotalPaymentPrice) + + updateProductStock(item, orderDetail.quantity) + + return orderDetail.orderDetailId!! + } + + @Transactional + fun updateProductStock(item: Item, quantity: Int) { + val updatedStock = item.stock - quantity + item.updateStock(updatedStock) + } + @Transactional fun completeOrder(orderId: String) { val order = orderRepository.findByIdOrNull(orderId) From c7fc6ef0379a65b2a129334b9c8f5d70468b87bf Mon Sep 17 00:00:00 2001 From: subin Date: Mon, 12 Aug 2024 21:52:21 +0900 Subject: [PATCH 02/10] =?UTF-8?q?feat:=20=EB=8B=A8=EC=9D=BC=20=EC=A3=BC?= =?UTF-8?q?=EB=AC=B8=20=EC=A1=B0=ED=9A=8C=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 --- .../order/controller/OrderUserController.kt | 43 ++++++++++++-- .../order/dto/response/OrderResponse.kt | 2 +- .../order/repository/OrderRepository.kt | 23 ++++---- .../order/service/OrderUserService.kt | 58 ++++++++++++++++++- src/main/resources/order.sql | 9 ++- 5 files changed, 116 insertions(+), 19 deletions(-) diff --git a/src/main/kotlin/org/store/clothstar/order/controller/OrderUserController.kt b/src/main/kotlin/org/store/clothstar/order/controller/OrderUserController.kt index 82ce4a3..4925740 100644 --- a/src/main/kotlin/org/store/clothstar/order/controller/OrderUserController.kt +++ b/src/main/kotlin/org/store/clothstar/order/controller/OrderUserController.kt @@ -15,6 +15,7 @@ import org.store.clothstar.common.dto.MessageDTO import org.store.clothstar.common.dto.SaveResponseDTO import org.store.clothstar.order.dto.request.AddOrderDetailRequest import org.store.clothstar.order.dto.request.OrderRequestWrapper +import org.store.clothstar.order.dto.response.OrderResponse import org.store.clothstar.order.dto.response.SaveOrderResponse import org.store.clothstar.order.service.OrderUserService @@ -24,11 +25,43 @@ import org.store.clothstar.order.service.OrderUserService class OrderUserController( private val orderUserService: OrderUserService, ) { -// @Operation(summary = "단일 주문 조회", description = "단일 주문의 정보를 조회한다.") -// @GetMapping("/{orderId}") -// fun getOrder(@PathVariable orderId: String): ResponseEntity { -// val orderResponse: OrderResponse = orderService.getOrder(orderId) -// return ResponseEntity.ok(orderResponse) + @Operation(summary = "단일 주문 조회", description = "단일 주문의 정보를 조회한다.") + @ApiResponses( + value = [ + ApiResponse( + responseCode = "200", description = "", + content = [Content(schema = Schema(implementation = SaveOrderResponse::class))] + ), + ApiResponse( + responseCode = "404", description = "", + content = [Content(schema = Schema(implementation = ErrorResponseDTO::class))] + ), + ApiResponse( + responseCode = "400", description = "", + content = [Content(schema = Schema(implementation = ErrorResponseDTO::class))] + ), + ] + ) + @GetMapping("/{orderId}") + fun getOrder(@PathVariable orderId: String):ResponseEntity { + val orderResponse: OrderResponse = orderUserService.getOrder(orderId); + return ResponseEntity.ok(orderResponse); + } + +// @Operation(summary = "전체 주문 조회 offset 페이징", description = "전체 주문 리스트를 offset 페이징 형식으로 가져온다.") +// @GetMapping("/offset") +// public ResponseEntity> getAllOrderOffsetPaging( +// @PageableDefault(size = 15) Pageable pageable) { +// Page orderPages = orderService.getAllOrderOffsetPaging(pageable); +// return ResponseEntity.ok(orderPages); +// } +// +// @Operation(summary = "전체 주문 조회 slice 페이징", description = "전체 주문 리스트를 slice 페이징 형식으로 가져온다.") +// @GetMapping("/slice") +// public ResponseEntity> getAllOrderSlicePaging( +// @PageableDefault(size = 15) Pageable pageable) { +// Slice orderPages = orderService.getAllOrderSlicePaging(pageable); +// return ResponseEntity.ok(orderPages); // } @Operation(summary = "주문 생성", description = "단일 주문을 생성한다.") diff --git a/src/main/kotlin/org/store/clothstar/order/dto/response/OrderResponse.kt b/src/main/kotlin/org/store/clothstar/order/dto/response/OrderResponse.kt index 9c2e831..f411538 100644 --- a/src/main/kotlin/org/store/clothstar/order/dto/response/OrderResponse.kt +++ b/src/main/kotlin/org/store/clothstar/order/dto/response/OrderResponse.kt @@ -29,7 +29,7 @@ class OrderResponse( val totalPrice: TotalPrice, - var orderDetailList: List = ArrayList(), + var orderDetailList: List = arrayListOf(), ) { fun updateOrderDetailList(orderDetailDTOList: List) { diff --git a/src/main/kotlin/org/store/clothstar/order/repository/OrderRepository.kt b/src/main/kotlin/org/store/clothstar/order/repository/OrderRepository.kt index 7a2cc75..291c13f 100644 --- a/src/main/kotlin/org/store/clothstar/order/repository/OrderRepository.kt +++ b/src/main/kotlin/org/store/clothstar/order/repository/OrderRepository.kt @@ -6,20 +6,21 @@ 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.domain.Order +import java.util.* interface OrderRepository : JpaRepository { + fun findByOrderIdAndDeletedAtIsNull(orderId: String): Order? + @Query("SELECT o FROM orders o WHERE o.status = 'CONFIRMED' AND o.deletedAt is null") fun findConfirmedOrders(): List - @Transactional - @Modifying - @Query("UPDATE orders o SET o.status = 'APPROVE' WHERE o.orderId = :orderId") - fun approveOrder(@Param("orderId") orderId: String) - - @Transactional - @Modifying - @Query("UPDATE orders o SET o.status = 'CANCEL' WHERE o.orderId = :orderId") - fun cancelOrder(@Param("orderId") orderId: String) - - fun findByOrderIdAndDeletedAtIsNull(orderId: String): Order? +// @Transactional +// @Modifying +// @Query("UPDATE orders o SET o.status = 'APPROVE' WHERE o.orderId = :orderId") +// fun approveOrder(@Param("orderId") orderId: String) +// +// @Transactional +// @Modifying +// @Query("UPDATE orders o SET o.status = 'CANCEL' WHERE o.orderId = :orderId") +// fun cancelOrder(@Param("orderId") orderId: String) } \ No newline at end of file diff --git a/src/main/kotlin/org/store/clothstar/order/service/OrderUserService.kt b/src/main/kotlin/org/store/clothstar/order/service/OrderUserService.kt index 0dc439d..d447e07 100644 --- a/src/main/kotlin/org/store/clothstar/order/service/OrderUserService.kt +++ b/src/main/kotlin/org/store/clothstar/order/service/OrderUserService.kt @@ -8,10 +8,19 @@ import org.springframework.web.server.ResponseStatusException import org.store.clothstar.common.error.ErrorCode import org.store.clothstar.common.error.exception.order.InsufficientStockException import org.store.clothstar.common.error.exception.order.OrderNotFoundException +import org.store.clothstar.member.domain.Address +import org.store.clothstar.member.domain.Member +import org.store.clothstar.member.domain.Seller +import org.store.clothstar.member.service.AddressService +import org.store.clothstar.member.service.MemberService +import org.store.clothstar.member.service.SellerService import org.store.clothstar.order.domain.Order +import org.store.clothstar.order.domain.OrderDetail +import org.store.clothstar.order.domain.vo.OrderDetailDTO import org.store.clothstar.order.domain.vo.Status import org.store.clothstar.order.dto.request.AddOrderDetailRequest import org.store.clothstar.order.dto.request.OrderRequestWrapper +import org.store.clothstar.order.dto.response.OrderResponse import org.store.clothstar.order.repository.OrderDetailRepository import org.store.clothstar.order.repository.OrderRepository import org.store.clothstar.order.service.OrderSave.OrderDetailValidater @@ -27,10 +36,57 @@ class OrderUserService( private val orderSaveFacade: OrderSaveFacade, private val orderRepository: OrderRepository, private val orderDetailRepository: OrderDetailRepository, + private val memberService: MemberService, + private val addressService: AddressService, + private val sellerService: SellerService, private val productService: ProductService, private val itemService: ItemService, - private val orderDetailValidater: OrderDetailValidater, ) { + @Transactional(readOnly = true) + fun getOrder (orderId: String): OrderResponse { + // orderId 관련 order, member, address 불러오기 + val order: Order = orderRepository.findByOrderIdAndDeletedAtIsNull(orderId) + ?: throw OrderNotFoundException(ErrorCode.NOT_FOUND_ORDER) + val member: Member = memberService.getMemberByMemberId(order.memberId) + val address: Address = addressService.getAddressById(order.addressId) + val seller: Seller = sellerService.getSellerById(order.memberId) + + // 응답 DTO 생성(주문상세 리스트는 빈 상태) + val orderResponse = OrderResponse.from(order,member,address) + + // 주문으로부터 주문상세 리스트 가져오기 + val orderDetails: List = order.orderDetails + .filter{ it.deletedAt == null } + + // 주문상세 리스트로부터 productId/itemId 리스트 가져오기 + val productIds: List = orderDetails.map{ it.productId } + val itemIds: List = orderDetails.map{ it.itemId } + + // productIds, itemIds로부터 Product/Item 리스트 가져오기 + val products: List = productService.findByProductIdIn(productIds) + val items: List = itemService.findByIdIn(itemIds) + + // Id, Entity를 Map으로 만들기 + val productMap: Map = products.associateBy{ it.productId!! } + val itemMap: Map = items.associateBy{ it.itemId!! } + + // Map으로부터 Id, Entity를 가져오면서 주문상세 DTO 리스트 만들기 + val orderDetailDTOList: List = orderDetails.map{ + val product: Product = productMap[ it.productId ] + ?: throw ResponseStatusException(HttpStatus.NOT_FOUND, "Product not found") + val item: Item = itemMap[ it.itemId ] + ?: throw ResponseStatusException(HttpStatus.NOT_FOUND, "Item not found") + val brandName: String = seller.brandName + OrderDetailDTO.from(it, item, product, brandName) + } + + // 응답 DTO에 주문상세 DTO 리스트 추가 + orderResponse.updateOrderDetailList(orderDetailDTOList) + + // 응답 DTO 반환 + return orderResponse; + } + @Transactional fun saveOrder(orderRequestWrapper: OrderRequestWrapper): String { return orderSaveFacade.saveOrder(orderRequestWrapper) diff --git a/src/main/resources/order.sql b/src/main/resources/order.sql index a9652a1..f68bfbf 100644 --- a/src/main/resources/order.sql +++ b/src/main/resources/order.sql @@ -54,6 +54,9 @@ INSERT INTO product (product_id, created_at, deleted_at, updated_at, category_id name, price, sale_count, sale_status) VALUES (1, CURRENT_TIMESTAMP, NULL, CURRENT_TIMESTAMP, 1, '반팔', 'HIDDEN', 1, '오구반팔', 19900, 1000, 'ON_SALE'); +INSERT INTO seller (member_id, created_at, deleted_at, updated_at, biz_no, brand_name, total_sell_price) +VALUES (12, CURRENT_TIMESTAMP, NULL, CURRENT_TIMESTAMP, 1232-1234, '아디다스',1000); + show create table order_detail; drop table if exists orders; @@ -70,4 +73,8 @@ from item; select * from product; select * -from address; \ No newline at end of file +from address; +select * +from member; +select * +from seller; \ No newline at end of file From 6861d3b71a3425874dd290761168065d5a99cadf Mon Sep 17 00:00:00 2001 From: subin Date: Mon, 12 Aug 2024 22:24:40 +0900 Subject: [PATCH 03/10] =?UTF-8?q?feat:=20=ED=8E=98=EC=9D=B4=EC=A7=95=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=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 --- .../order/controller/OrderUserController.kt | 50 ++++------ .../order/service/OrderUserService.kt | 97 ++++++++++++++++++- 2 files changed, 115 insertions(+), 32 deletions(-) diff --git a/src/main/kotlin/org/store/clothstar/order/controller/OrderUserController.kt b/src/main/kotlin/org/store/clothstar/order/controller/OrderUserController.kt index 4925740..474d3d6 100644 --- a/src/main/kotlin/org/store/clothstar/order/controller/OrderUserController.kt +++ b/src/main/kotlin/org/store/clothstar/order/controller/OrderUserController.kt @@ -6,6 +6,10 @@ import io.swagger.v3.oas.annotations.media.Schema import io.swagger.v3.oas.annotations.responses.ApiResponse import io.swagger.v3.oas.annotations.responses.ApiResponses import io.swagger.v3.oas.annotations.tags.Tag +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 @@ -26,43 +30,27 @@ class OrderUserController( private val orderUserService: OrderUserService, ) { @Operation(summary = "단일 주문 조회", description = "단일 주문의 정보를 조회한다.") - @ApiResponses( - value = [ - ApiResponse( - responseCode = "200", description = "", - content = [Content(schema = Schema(implementation = SaveOrderResponse::class))] - ), - ApiResponse( - responseCode = "404", description = "", - content = [Content(schema = Schema(implementation = ErrorResponseDTO::class))] - ), - ApiResponse( - responseCode = "400", description = "", - content = [Content(schema = Schema(implementation = ErrorResponseDTO::class))] - ), - ] - ) @GetMapping("/{orderId}") fun getOrder(@PathVariable orderId: String):ResponseEntity { val orderResponse: OrderResponse = orderUserService.getOrder(orderId); return ResponseEntity.ok(orderResponse); } -// @Operation(summary = "전체 주문 조회 offset 페이징", description = "전체 주문 리스트를 offset 페이징 형식으로 가져온다.") -// @GetMapping("/offset") -// public ResponseEntity> getAllOrderOffsetPaging( -// @PageableDefault(size = 15) Pageable pageable) { -// Page orderPages = orderService.getAllOrderOffsetPaging(pageable); -// return ResponseEntity.ok(orderPages); -// } -// -// @Operation(summary = "전체 주문 조회 slice 페이징", description = "전체 주문 리스트를 slice 페이징 형식으로 가져온다.") -// @GetMapping("/slice") -// public ResponseEntity> getAllOrderSlicePaging( -// @PageableDefault(size = 15) Pageable pageable) { -// Slice orderPages = orderService.getAllOrderSlicePaging(pageable); -// return ResponseEntity.ok(orderPages); -// } + @Operation(summary = "전체 주문 조회 offset 페이징", description = "전체 주문 리스트를 offset 페이징 형식으로 가져온다.") + @GetMapping("/offset") + fun getAllOrderOffsetPaging( + @PageableDefault(size = 15) pageable: Pageable): ResponseEntity> { + val orderPages: Page = orderUserService.getAllOrderOffsetPaging(pageable) + return ResponseEntity.ok(orderPages) + } + + @Operation(summary = "전체 주문 조회 slice 페이징", description = "전체 주문 리스트를 slice 페이징 형식으로 가져온다.") + @GetMapping("/slice") + fun getAllOrderSlicePaging( + @PageableDefault(size = 15) pageable: Pageable): ResponseEntity> { + val orderPages: Slice = orderUserService.getAllOrderSlicePaging(pageable) + return ResponseEntity.ok(orderPages) + } @Operation(summary = "주문 생성", description = "단일 주문을 생성한다.") @ApiResponses( diff --git a/src/main/kotlin/org/store/clothstar/order/service/OrderUserService.kt b/src/main/kotlin/org/store/clothstar/order/service/OrderUserService.kt index d447e07..91a3bb0 100644 --- a/src/main/kotlin/org/store/clothstar/order/service/OrderUserService.kt +++ b/src/main/kotlin/org/store/clothstar/order/service/OrderUserService.kt @@ -1,5 +1,8 @@ package org.store.clothstar.order.service +import org.springframework.data.domain.Page +import org.springframework.data.domain.Pageable +import org.springframework.data.domain.Slice import org.springframework.data.repository.findByIdOrNull import org.springframework.http.HttpStatus import org.springframework.stereotype.Service @@ -84,7 +87,99 @@ class OrderUserService( orderResponse.updateOrderDetailList(orderDetailDTOList) // 응답 DTO 반환 - return orderResponse; + return orderResponse + } + + fun getAllOrderOffsetPaging(pageable: Pageable): Page { + val orders: Page = orderRepository.findAll(pageable) + + return orders.map{ + // order 관련 member, address 불러오기 + val member: Member = memberService.getMemberByMemberId(it.memberId) + val address: Address = addressService.getAddressById(it.addressId) + val seller: Seller = sellerService.getSellerById(it.memberId) + + // 응답 DTO 생성(주문상세 리스트는 빈 상태) + val orderResponse = OrderResponse.from(it,member,address) + + // 주문으로부터 주문상세 리스트 가져오기 + val orderDetails: List = it.orderDetails + .filter{ it.deletedAt == null } + + // 주문상세 리스트로부터 productId/itemId 리스트 가져오기 + val productIds: List = orderDetails.map{ it.productId } + val itemIds: List = orderDetails.map{ it.itemId } + + // productIds, itemIds로부터 Product/Item 리스트 가져오기 + val products: List = productService.findByProductIdIn(productIds) + val items: List = itemService.findByIdIn(itemIds) + + // Id, Entity를 Map으로 만들기 + val productMap: Map = products.associateBy{ it.productId!! } + val itemMap: Map = items.associateBy{ it.itemId!! } + + // Map으로부터 Id, Entity를 가져오면서 주문상세 DTO 리스트 만들기 + val orderDetailDTOList: List = orderDetails.map{ + val product: Product = productMap[ it.productId ] + ?: throw ResponseStatusException(HttpStatus.NOT_FOUND, "Product not found") + val item: Item = itemMap[ it.itemId ] + ?: throw ResponseStatusException(HttpStatus.NOT_FOUND, "Item not found") + val brandName: String = seller.brandName + OrderDetailDTO.from(it, item, product, brandName) + } + + // 응답 DTO에 주문상세 DTO 리스트 추가 + orderResponse.updateOrderDetailList(orderDetailDTOList) + + // 응답 DTO 반환 + orderResponse + } + } + + fun getAllOrderSlicePaging(pageable: Pageable): Slice { + val orders: Slice = orderRepository.findAll(pageable) + + return orders.map{ + // order 관련 member, address 불러오기 + val member: Member = memberService.getMemberByMemberId(it.memberId) + val address: Address = addressService.getAddressById(it.addressId) + val seller: Seller = sellerService.getSellerById(it.memberId) + + // 응답 DTO 생성(주문상세 리스트는 빈 상태) + val orderResponse = OrderResponse.from(it,member,address) + + // 주문으로부터 주문상세 리스트 가져오기 + val orderDetails: List = it.orderDetails + .filter{ it.deletedAt == null } + + // 주문상세 리스트로부터 productId/itemId 리스트 가져오기 + val productIds: List = orderDetails.map{ it.productId } + val itemIds: List = orderDetails.map{ it.itemId } + + // productIds, itemIds로부터 Product/Item 리스트 가져오기 + val products: List = productService.findByProductIdIn(productIds) + val items: List = itemService.findByIdIn(itemIds) + + // Id, Entity를 Map으로 만들기 + val productMap: Map = products.associateBy{ it.productId!! } + val itemMap: Map = items.associateBy{ it.itemId!! } + + // Map으로부터 Id, Entity를 가져오면서 주문상세 DTO 리스트 만들기 + val orderDetailDTOList: List = orderDetails.map{ + val product: Product = productMap[ it.productId ] + ?: throw ResponseStatusException(HttpStatus.NOT_FOUND, "Product not found") + val item: Item = itemMap[ it.itemId ] + ?: throw ResponseStatusException(HttpStatus.NOT_FOUND, "Item not found") + val brandName: String = seller.brandName + OrderDetailDTO.from(it, item, product, brandName) + } + + // 응답 DTO에 주문상세 DTO 리스트 추가 + orderResponse.updateOrderDetailList(orderDetailDTOList) + + // 응답 DTO 반환 + orderResponse + } } @Transactional From 9674c1ddea736797383bbb17eebe4f8951e2b700 Mon Sep 17 00:00:00 2001 From: subin Date: Mon, 12 Aug 2024 22:51:49 +0900 Subject: [PATCH 04/10] =?UTF-8?q?feat:=20=ED=8C=90=EB=A7=A4=EC=9E=90=20?= =?UTF-8?q?=EC=A3=BC=EB=AC=B8=20=EC=A1=B0=ED=9A=8C=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../order/controller/OrderSellerController.kt | 20 +++--- .../order/repository/OrderRepository.kt | 15 +--- .../order/service/OrderSellerService.kt | 72 +++++++++++-------- .../order/service/OrderUserService.kt | 6 +- 4 files changed, 57 insertions(+), 56 deletions(-) diff --git a/src/main/kotlin/org/store/clothstar/order/controller/OrderSellerController.kt b/src/main/kotlin/org/store/clothstar/order/controller/OrderSellerController.kt index 3ef5894..4cf6e01 100644 --- a/src/main/kotlin/org/store/clothstar/order/controller/OrderSellerController.kt +++ b/src/main/kotlin/org/store/clothstar/order/controller/OrderSellerController.kt @@ -8,12 +8,10 @@ import io.swagger.v3.oas.annotations.responses.ApiResponses import io.swagger.v3.oas.annotations.tags.Tag import org.springframework.http.HttpStatus import org.springframework.http.ResponseEntity -import org.springframework.web.bind.annotation.PatchMapping -import org.springframework.web.bind.annotation.PathVariable -import org.springframework.web.bind.annotation.RequestMapping -import org.springframework.web.bind.annotation.RestController +import org.springframework.web.bind.annotation.* import org.store.clothstar.common.dto.ErrorResponseDTO import org.store.clothstar.common.dto.MessageDTO +import org.store.clothstar.order.dto.response.OrderResponse import org.store.clothstar.order.service.OrderSellerService @Tag(name = "OrderSeller", description = "판매자(OrderSeller)의 주문 정보 관리에 대한 API 입니다.") @@ -22,13 +20,13 @@ import org.store.clothstar.order.service.OrderSellerService class OrderSellerController( private val orderSellerService: OrderSellerService ) { -// -// @Operation(summary = "(판매자) WAITING 주문 리스트 조회", description = "(판매자) 주문상태가 '승인대기'인 주문 리스트를 조회한다.") -// @GetMapping -// fun getWaitingOrder(): ResponseEntity> { -// val orderResponseList: List = orderSellerService.getConfirmedOrder() -// return ResponseEntity.ok(orderResponseList) -// } + + @Operation(summary = "(판매자) WAITING 주문 리스트 조회", description = "(판매자) 주문상태가 '승인대기'인 주문 리스트를 조회한다.") + @GetMapping + fun getWaitingOrder(): ResponseEntity> { + val orderResponseList: List = orderSellerService.getConfirmedOrders() + return ResponseEntity.ok(orderResponseList) + } @Operation(summary = "판매자 주문 승인", description = "판매자가 주문을 출고처리한다.") @ApiResponses( diff --git a/src/main/kotlin/org/store/clothstar/order/repository/OrderRepository.kt b/src/main/kotlin/org/store/clothstar/order/repository/OrderRepository.kt index 291c13f..7202889 100644 --- a/src/main/kotlin/org/store/clothstar/order/repository/OrderRepository.kt +++ b/src/main/kotlin/org/store/clothstar/order/repository/OrderRepository.kt @@ -1,10 +1,7 @@ package org.store.clothstar.order.repository import org.springframework.data.jpa.repository.JpaRepository -import org.springframework.data.jpa.repository.Modifying 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.domain.Order import java.util.* @@ -12,15 +9,5 @@ interface OrderRepository : JpaRepository { fun findByOrderIdAndDeletedAtIsNull(orderId: String): Order? @Query("SELECT o FROM orders o WHERE o.status = 'CONFIRMED' AND o.deletedAt is null") - fun findConfirmedOrders(): List - -// @Transactional -// @Modifying -// @Query("UPDATE orders o SET o.status = 'APPROVE' WHERE o.orderId = :orderId") -// fun approveOrder(@Param("orderId") orderId: String) -// -// @Transactional -// @Modifying -// @Query("UPDATE orders o SET o.status = 'CANCEL' WHERE o.orderId = :orderId") -// fun cancelOrder(@Param("orderId") orderId: String) + fun findConfirmedAndNotDeletedOrders(): List } \ No newline at end of file diff --git a/src/main/kotlin/org/store/clothstar/order/service/OrderSellerService.kt b/src/main/kotlin/org/store/clothstar/order/service/OrderSellerService.kt index 0419a79..2728d39 100644 --- a/src/main/kotlin/org/store/clothstar/order/service/OrderSellerService.kt +++ b/src/main/kotlin/org/store/clothstar/order/service/OrderSellerService.kt @@ -1,13 +1,19 @@ package org.store.clothstar.order.service import org.springframework.data.repository.findByIdOrNull +import org.springframework.http.HttpStatus import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional +import org.springframework.web.server.ResponseStatusException import org.store.clothstar.common.error.ErrorCode import org.store.clothstar.common.error.exception.order.OrderNotFoundException +import org.store.clothstar.member.domain.Address +import org.store.clothstar.member.domain.Member +import org.store.clothstar.member.domain.Seller import org.store.clothstar.member.service.AddressService import org.store.clothstar.member.service.MemberService import org.store.clothstar.member.service.SellerService +import org.store.clothstar.order.domain.Order import org.store.clothstar.order.domain.OrderDetail import org.store.clothstar.order.domain.vo.OrderDetailDTO import org.store.clothstar.order.domain.vo.Status @@ -28,40 +34,50 @@ class OrderSellerService( private val productService: ProductService, ) { @Transactional(readOnly = true) - fun getConfirmedOrder(): List { - val confirmedOrders = orderRepository.findConfirmedOrders() + fun getConfirmedOrders(): List { + val confirmedOrders: List = orderRepository.findConfirmedAndNotDeletedOrders() - return confirmedOrders - .map { order -> - order?.let { - val member = memberService.getMemberByMemberId(order.memberId) - val seller = sellerService.getSellerById(order.memberId) - val address = addressService.getAddressById(order.addressId) - val orderResponse = OrderResponse.from(order, member, address) + return confirmedOrders.map{ + // order 관련 member, address, seller 불러오기 + val member: Member = memberService.getMemberByMemberId(it.memberId) + val address: Address = addressService.getAddressById(it.addressId) + val seller: Seller = sellerService.getSellerById(it.memberId) - val orderDetails = order.orderDetails - .filter { orderDetail -> orderDetail.deletedAt == null } - .toList() - val itemIds = orderDetails.map(OrderDetail::itemId).toList() - val productIds = orderDetails.map(OrderDetail::productId).toList() + // 응답 DTO 생성(주문상세 리스트는 빈 상태) + val orderResponse = OrderResponse.from(it,member,address) - val items = itemService.findByIdIn(itemIds) - val products = productService.findByProductIdIn(productIds) + // 주문으로부터 주문상세 리스트 가져오기 + val orderDetails: List = it.orderDetails + .filter{ it.deletedAt == null } - val itemMap: Map = items.map { it.itemId!! to it }.toMap() - val productMap: Map = products.map { it.productId!! to it }.toMap() + // 주문상세 리스트로부터 productId/itemId 리스트 가져오기 + val productIds: List = orderDetails.map{ it.productId } + val itemIds: List = orderDetails.map{ it.itemId } - val orderDetailDTOList = orderDetails.map { orderDetail: OrderDetail -> - val itemEntity = itemMap[orderDetail.itemId]!! - val productEntity = productMap[orderDetail.productId]!! - val brandName = seller.brandName - OrderDetailDTO.from(orderDetail, itemEntity, productEntity, brandName) - }.toList() + // productIds, itemIds로부터 Product/Item 리스트 가져오기 + val products: List = productService.findByProductIdIn(productIds) + val items: List = itemService.findByIdIn(itemIds) - orderResponse.updateOrderDetailList(orderDetailDTOList) - orderResponse - } ?: throw IllegalArgumentException("오더 리스트가 없습니다.") - }.toList() + // Id, Entity를 Map으로 만들기 + val productMap: Map = products.associateBy{ it.productId!! } + val itemMap: Map = items.associateBy{ it.itemId!! } + + // Map으로부터 Id, Entity를 가져오면서 주문상세 DTO 리스트 만들기 + val orderDetailDTOList: List = orderDetails.map{ + val product: Product = productMap[ it.productId ] + ?: throw ResponseStatusException(HttpStatus.NOT_FOUND, "Product not found") + val item: Item = itemMap[ it.itemId ] + ?: throw ResponseStatusException(HttpStatus.NOT_FOUND, "Item not found") + val brandName: String = seller.brandName + OrderDetailDTO.from(it, item, product, brandName) + } + + // 응답 DTO에 주문상세 DTO 리스트 추가 + orderResponse.updateOrderDetailList(orderDetailDTOList) + + // 응답 DTO 반환 + orderResponse + } } @Transactional diff --git a/src/main/kotlin/org/store/clothstar/order/service/OrderUserService.kt b/src/main/kotlin/org/store/clothstar/order/service/OrderUserService.kt index 91a3bb0..d331380 100644 --- a/src/main/kotlin/org/store/clothstar/order/service/OrderUserService.kt +++ b/src/main/kotlin/org/store/clothstar/order/service/OrderUserService.kt @@ -47,7 +47,7 @@ class OrderUserService( ) { @Transactional(readOnly = true) fun getOrder (orderId: String): OrderResponse { - // orderId 관련 order, member, address 불러오기 + // orderId 관련 order, member, address, seller 불러오기 val order: Order = orderRepository.findByOrderIdAndDeletedAtIsNull(orderId) ?: throw OrderNotFoundException(ErrorCode.NOT_FOUND_ORDER) val member: Member = memberService.getMemberByMemberId(order.memberId) @@ -94,7 +94,7 @@ class OrderUserService( val orders: Page = orderRepository.findAll(pageable) return orders.map{ - // order 관련 member, address 불러오기 + // order 관련 member, address, seller 불러오기 val member: Member = memberService.getMemberByMemberId(it.memberId) val address: Address = addressService.getAddressById(it.addressId) val seller: Seller = sellerService.getSellerById(it.memberId) @@ -140,7 +140,7 @@ class OrderUserService( val orders: Slice = orderRepository.findAll(pageable) return orders.map{ - // order 관련 member, address 불러오기 + // order 관련 member, address, seller 불러오기 val member: Member = memberService.getMemberByMemberId(it.memberId) val address: Address = addressService.getAddressById(it.addressId) val seller: Seller = sellerService.getSellerById(it.memberId) From 4c99b3187c79f3a0a1338db0e0953b40d0d01b1e Mon Sep 17 00:00:00 2001 From: subin Date: Mon, 12 Aug 2024 22:53:56 +0900 Subject: [PATCH 05/10] feat: Optimize Imports & Reformat Code --- .../config/CustomAuthenticationEntryPoint.kt | 2 +- .../member/dto/request/MemberLoginRequest.kt | 2 +- .../member/service/AddressServiceImpl.kt | 1 - .../order/controller/OrderUserController.kt | 12 ++-- .../order/repository/OrderRepository.kt | 1 - .../order/service/OrderSellerService.kt | 20 +++--- .../order/service/OrderUserService.kt | 64 +++++++++---------- .../product/controller/ProductController.kt | 2 +- .../store/clothstar/product/domain/Item.kt | 1 - .../clothstar/product/domain/ItemAttribute.kt | 1 - .../store/clothstar/product/domain/Product.kt | 1 - .../clothstar/product/domain/ProductImage.kt | 1 - .../clothstar/product/domain/ProductOption.kt | 1 - .../product/repository/ProductRepository.kt | 1 - .../service/ProductApplicationService.kt | 1 - src/main/resources/order.sql | 2 +- 16 files changed, 52 insertions(+), 61 deletions(-) diff --git a/src/main/kotlin/org/store/clothstar/common/config/CustomAuthenticationEntryPoint.kt b/src/main/kotlin/org/store/clothstar/common/config/CustomAuthenticationEntryPoint.kt index d8c7d3e..d9464ef 100644 --- a/src/main/kotlin/org/store/clothstar/common/config/CustomAuthenticationEntryPoint.kt +++ b/src/main/kotlin/org/store/clothstar/common/config/CustomAuthenticationEntryPoint.kt @@ -22,7 +22,7 @@ class CustomAuthenticationEntryPoint : AuthenticationEntryPoint { authException: AuthenticationException, ) { log.error { "인증 실패 로직 실행" } - + response.status = HttpServletResponse.SC_UNAUTHORIZED response.characterEncoding = "UTF-8" response.contentType = "application/json" diff --git a/src/main/kotlin/org/store/clothstar/member/dto/request/MemberLoginRequest.kt b/src/main/kotlin/org/store/clothstar/member/dto/request/MemberLoginRequest.kt index 84b999b..f4589d3 100644 --- a/src/main/kotlin/org/store/clothstar/member/dto/request/MemberLoginRequest.kt +++ b/src/main/kotlin/org/store/clothstar/member/dto/request/MemberLoginRequest.kt @@ -9,6 +9,6 @@ class MemberLoginRequest( val password: String, ) { constructor() : this("", "") { - + } } \ No newline at end of file diff --git a/src/main/kotlin/org/store/clothstar/member/service/AddressServiceImpl.kt b/src/main/kotlin/org/store/clothstar/member/service/AddressServiceImpl.kt index e11b474..c747bb8 100644 --- a/src/main/kotlin/org/store/clothstar/member/service/AddressServiceImpl.kt +++ b/src/main/kotlin/org/store/clothstar/member/service/AddressServiceImpl.kt @@ -3,7 +3,6 @@ package org.store.clothstar.member.service import org.springframework.data.repository.findByIdOrNull import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional -import org.springframework.web.server.ResponseStatusException import org.store.clothstar.common.error.ErrorCode import org.store.clothstar.common.error.exception.NotFoundAddressException import org.store.clothstar.common.error.exception.NotFoundMemberException diff --git a/src/main/kotlin/org/store/clothstar/order/controller/OrderUserController.kt b/src/main/kotlin/org/store/clothstar/order/controller/OrderUserController.kt index 474d3d6..d07256d 100644 --- a/src/main/kotlin/org/store/clothstar/order/controller/OrderUserController.kt +++ b/src/main/kotlin/org/store/clothstar/order/controller/OrderUserController.kt @@ -31,15 +31,16 @@ class OrderUserController( ) { @Operation(summary = "단일 주문 조회", description = "단일 주문의 정보를 조회한다.") @GetMapping("/{orderId}") - fun getOrder(@PathVariable orderId: String):ResponseEntity { - val orderResponse: OrderResponse = orderUserService.getOrder(orderId); - return ResponseEntity.ok(orderResponse); + fun getOrder(@PathVariable orderId: String): ResponseEntity { + val orderResponse: OrderResponse = orderUserService.getOrder(orderId) + return ResponseEntity.ok(orderResponse) } @Operation(summary = "전체 주문 조회 offset 페이징", description = "전체 주문 리스트를 offset 페이징 형식으로 가져온다.") @GetMapping("/offset") fun getAllOrderOffsetPaging( - @PageableDefault(size = 15) pageable: Pageable): ResponseEntity> { + @PageableDefault(size = 15) pageable: Pageable + ): ResponseEntity> { val orderPages: Page = orderUserService.getAllOrderOffsetPaging(pageable) return ResponseEntity.ok(orderPages) } @@ -47,7 +48,8 @@ class OrderUserController( @Operation(summary = "전체 주문 조회 slice 페이징", description = "전체 주문 리스트를 slice 페이징 형식으로 가져온다.") @GetMapping("/slice") fun getAllOrderSlicePaging( - @PageableDefault(size = 15) pageable: Pageable): ResponseEntity> { + @PageableDefault(size = 15) pageable: Pageable + ): ResponseEntity> { val orderPages: Slice = orderUserService.getAllOrderSlicePaging(pageable) return ResponseEntity.ok(orderPages) } diff --git a/src/main/kotlin/org/store/clothstar/order/repository/OrderRepository.kt b/src/main/kotlin/org/store/clothstar/order/repository/OrderRepository.kt index 7202889..ccd63a1 100644 --- a/src/main/kotlin/org/store/clothstar/order/repository/OrderRepository.kt +++ b/src/main/kotlin/org/store/clothstar/order/repository/OrderRepository.kt @@ -3,7 +3,6 @@ package org.store.clothstar.order.repository import org.springframework.data.jpa.repository.JpaRepository import org.springframework.data.jpa.repository.Query import org.store.clothstar.order.domain.Order -import java.util.* interface OrderRepository : JpaRepository { fun findByOrderIdAndDeletedAtIsNull(orderId: String): Order? diff --git a/src/main/kotlin/org/store/clothstar/order/service/OrderSellerService.kt b/src/main/kotlin/org/store/clothstar/order/service/OrderSellerService.kt index 2728d39..6989674 100644 --- a/src/main/kotlin/org/store/clothstar/order/service/OrderSellerService.kt +++ b/src/main/kotlin/org/store/clothstar/order/service/OrderSellerService.kt @@ -37,36 +37,36 @@ class OrderSellerService( fun getConfirmedOrders(): List { val confirmedOrders: List = orderRepository.findConfirmedAndNotDeletedOrders() - return confirmedOrders.map{ + return confirmedOrders.map { // order 관련 member, address, seller 불러오기 val member: Member = memberService.getMemberByMemberId(it.memberId) val address: Address = addressService.getAddressById(it.addressId) val seller: Seller = sellerService.getSellerById(it.memberId) // 응답 DTO 생성(주문상세 리스트는 빈 상태) - val orderResponse = OrderResponse.from(it,member,address) + val orderResponse = OrderResponse.from(it, member, address) // 주문으로부터 주문상세 리스트 가져오기 val orderDetails: List = it.orderDetails - .filter{ it.deletedAt == null } + .filter { it.deletedAt == null } // 주문상세 리스트로부터 productId/itemId 리스트 가져오기 - val productIds: List = orderDetails.map{ it.productId } - val itemIds: List = orderDetails.map{ it.itemId } + val productIds: List = orderDetails.map { it.productId } + val itemIds: List = orderDetails.map { it.itemId } // productIds, itemIds로부터 Product/Item 리스트 가져오기 val products: List = productService.findByProductIdIn(productIds) val items: List = itemService.findByIdIn(itemIds) // Id, Entity를 Map으로 만들기 - val productMap: Map = products.associateBy{ it.productId!! } - val itemMap: Map = items.associateBy{ it.itemId!! } + val productMap: Map = products.associateBy { it.productId!! } + val itemMap: Map = items.associateBy { it.itemId!! } // Map으로부터 Id, Entity를 가져오면서 주문상세 DTO 리스트 만들기 - val orderDetailDTOList: List = orderDetails.map{ - val product: Product = productMap[ it.productId ] + val orderDetailDTOList: List = orderDetails.map { + val product: Product = productMap[it.productId] ?: throw ResponseStatusException(HttpStatus.NOT_FOUND, "Product not found") - val item: Item = itemMap[ it.itemId ] + val item: Item = itemMap[it.itemId] ?: throw ResponseStatusException(HttpStatus.NOT_FOUND, "Item not found") val brandName: String = seller.brandName OrderDetailDTO.from(it, item, product, brandName) diff --git a/src/main/kotlin/org/store/clothstar/order/service/OrderUserService.kt b/src/main/kotlin/org/store/clothstar/order/service/OrderUserService.kt index d331380..89bf978 100644 --- a/src/main/kotlin/org/store/clothstar/order/service/OrderUserService.kt +++ b/src/main/kotlin/org/store/clothstar/order/service/OrderUserService.kt @@ -26,11 +26,9 @@ import org.store.clothstar.order.dto.request.OrderRequestWrapper import org.store.clothstar.order.dto.response.OrderResponse import org.store.clothstar.order.repository.OrderDetailRepository import org.store.clothstar.order.repository.OrderRepository -import org.store.clothstar.order.service.OrderSave.OrderDetailValidater import org.store.clothstar.order.service.OrderSave.OrderSaveFacade import org.store.clothstar.product.domain.Item import org.store.clothstar.product.domain.Product -import org.store.clothstar.product.repository.ProductRepository import org.store.clothstar.product.service.ItemService import org.store.clothstar.product.service.ProductService @@ -46,7 +44,7 @@ class OrderUserService( private val itemService: ItemService, ) { @Transactional(readOnly = true) - fun getOrder (orderId: String): OrderResponse { + fun getOrder(orderId: String): OrderResponse { // orderId 관련 order, member, address, seller 불러오기 val order: Order = orderRepository.findByOrderIdAndDeletedAtIsNull(orderId) ?: throw OrderNotFoundException(ErrorCode.NOT_FOUND_ORDER) @@ -55,29 +53,29 @@ class OrderUserService( val seller: Seller = sellerService.getSellerById(order.memberId) // 응답 DTO 생성(주문상세 리스트는 빈 상태) - val orderResponse = OrderResponse.from(order,member,address) + val orderResponse = OrderResponse.from(order, member, address) // 주문으로부터 주문상세 리스트 가져오기 val orderDetails: List = order.orderDetails - .filter{ it.deletedAt == null } + .filter { it.deletedAt == null } // 주문상세 리스트로부터 productId/itemId 리스트 가져오기 - val productIds: List = orderDetails.map{ it.productId } - val itemIds: List = orderDetails.map{ it.itemId } + val productIds: List = orderDetails.map { it.productId } + val itemIds: List = orderDetails.map { it.itemId } // productIds, itemIds로부터 Product/Item 리스트 가져오기 val products: List = productService.findByProductIdIn(productIds) val items: List = itemService.findByIdIn(itemIds) // Id, Entity를 Map으로 만들기 - val productMap: Map = products.associateBy{ it.productId!! } - val itemMap: Map = items.associateBy{ it.itemId!! } + val productMap: Map = products.associateBy { it.productId!! } + val itemMap: Map = items.associateBy { it.itemId!! } // Map으로부터 Id, Entity를 가져오면서 주문상세 DTO 리스트 만들기 - val orderDetailDTOList: List = orderDetails.map{ - val product: Product = productMap[ it.productId ] + val orderDetailDTOList: List = orderDetails.map { + val product: Product = productMap[it.productId] ?: throw ResponseStatusException(HttpStatus.NOT_FOUND, "Product not found") - val item: Item = itemMap[ it.itemId ] + val item: Item = itemMap[it.itemId] ?: throw ResponseStatusException(HttpStatus.NOT_FOUND, "Item not found") val brandName: String = seller.brandName OrderDetailDTO.from(it, item, product, brandName) @@ -93,40 +91,40 @@ class OrderUserService( fun getAllOrderOffsetPaging(pageable: Pageable): Page { val orders: Page = orderRepository.findAll(pageable) - return orders.map{ + return orders.map { // order 관련 member, address, seller 불러오기 val member: Member = memberService.getMemberByMemberId(it.memberId) val address: Address = addressService.getAddressById(it.addressId) val seller: Seller = sellerService.getSellerById(it.memberId) // 응답 DTO 생성(주문상세 리스트는 빈 상태) - val orderResponse = OrderResponse.from(it,member,address) + val orderResponse = OrderResponse.from(it, member, address) // 주문으로부터 주문상세 리스트 가져오기 val orderDetails: List = it.orderDetails - .filter{ it.deletedAt == null } + .filter { it.deletedAt == null } // 주문상세 리스트로부터 productId/itemId 리스트 가져오기 - val productIds: List = orderDetails.map{ it.productId } - val itemIds: List = orderDetails.map{ it.itemId } + val productIds: List = orderDetails.map { it.productId } + val itemIds: List = orderDetails.map { it.itemId } // productIds, itemIds로부터 Product/Item 리스트 가져오기 val products: List = productService.findByProductIdIn(productIds) val items: List = itemService.findByIdIn(itemIds) // Id, Entity를 Map으로 만들기 - val productMap: Map = products.associateBy{ it.productId!! } - val itemMap: Map = items.associateBy{ it.itemId!! } + val productMap: Map = products.associateBy { it.productId!! } + val itemMap: Map = items.associateBy { it.itemId!! } // Map으로부터 Id, Entity를 가져오면서 주문상세 DTO 리스트 만들기 - val orderDetailDTOList: List = orderDetails.map{ - val product: Product = productMap[ it.productId ] + val orderDetailDTOList: List = orderDetails.map { + val product: Product = productMap[it.productId] ?: throw ResponseStatusException(HttpStatus.NOT_FOUND, "Product not found") - val item: Item = itemMap[ it.itemId ] + val item: Item = itemMap[it.itemId] ?: throw ResponseStatusException(HttpStatus.NOT_FOUND, "Item not found") val brandName: String = seller.brandName OrderDetailDTO.from(it, item, product, brandName) - } + } // 응답 DTO에 주문상세 DTO 리스트 추가 orderResponse.updateOrderDetailList(orderDetailDTOList) @@ -139,36 +137,36 @@ class OrderUserService( fun getAllOrderSlicePaging(pageable: Pageable): Slice { val orders: Slice = orderRepository.findAll(pageable) - return orders.map{ + return orders.map { // order 관련 member, address, seller 불러오기 val member: Member = memberService.getMemberByMemberId(it.memberId) val address: Address = addressService.getAddressById(it.addressId) val seller: Seller = sellerService.getSellerById(it.memberId) // 응답 DTO 생성(주문상세 리스트는 빈 상태) - val orderResponse = OrderResponse.from(it,member,address) + val orderResponse = OrderResponse.from(it, member, address) // 주문으로부터 주문상세 리스트 가져오기 val orderDetails: List = it.orderDetails - .filter{ it.deletedAt == null } + .filter { it.deletedAt == null } // 주문상세 리스트로부터 productId/itemId 리스트 가져오기 - val productIds: List = orderDetails.map{ it.productId } - val itemIds: List = orderDetails.map{ it.itemId } + val productIds: List = orderDetails.map { it.productId } + val itemIds: List = orderDetails.map { it.itemId } // productIds, itemIds로부터 Product/Item 리스트 가져오기 val products: List = productService.findByProductIdIn(productIds) val items: List = itemService.findByIdIn(itemIds) // Id, Entity를 Map으로 만들기 - val productMap: Map = products.associateBy{ it.productId!! } - val itemMap: Map = items.associateBy{ it.itemId!! } + val productMap: Map = products.associateBy { it.productId!! } + val itemMap: Map = items.associateBy { it.itemId!! } // Map으로부터 Id, Entity를 가져오면서 주문상세 DTO 리스트 만들기 - val orderDetailDTOList: List = orderDetails.map{ - val product: Product = productMap[ it.productId ] + val orderDetailDTOList: List = orderDetails.map { + val product: Product = productMap[it.productId] ?: throw ResponseStatusException(HttpStatus.NOT_FOUND, "Product not found") - val item: Item = itemMap[ it.itemId ] + val item: Item = itemMap[it.itemId] ?: throw ResponseStatusException(HttpStatus.NOT_FOUND, "Item not found") val brandName: String = seller.brandName OrderDetailDTO.from(it, item, product, brandName) diff --git a/src/main/kotlin/org/store/clothstar/product/controller/ProductController.kt b/src/main/kotlin/org/store/clothstar/product/controller/ProductController.kt index 9adf938..19e0d4c 100644 --- a/src/main/kotlin/org/store/clothstar/product/controller/ProductController.kt +++ b/src/main/kotlin/org/store/clothstar/product/controller/ProductController.kt @@ -18,7 +18,7 @@ import org.store.clothstar.product.service.ProductApplicationService @RestController private class ProductController( private val productApplicationService: ProductApplicationService, - ) { +) { @PostMapping @Operation( summary = "상품 등록", diff --git a/src/main/kotlin/org/store/clothstar/product/domain/Item.kt b/src/main/kotlin/org/store/clothstar/product/domain/Item.kt index a4efefe..b336704 100644 --- a/src/main/kotlin/org/store/clothstar/product/domain/Item.kt +++ b/src/main/kotlin/org/store/clothstar/product/domain/Item.kt @@ -1,7 +1,6 @@ package org.store.clothstar.product.domain import jakarta.persistence.* -import org.hibernate.annotations.BatchSize import org.store.clothstar.product.domain.type.DisplayStatus import org.store.clothstar.product.domain.type.SaleStatus diff --git a/src/main/kotlin/org/store/clothstar/product/domain/ItemAttribute.kt b/src/main/kotlin/org/store/clothstar/product/domain/ItemAttribute.kt index 8262c68..505038a 100644 --- a/src/main/kotlin/org/store/clothstar/product/domain/ItemAttribute.kt +++ b/src/main/kotlin/org/store/clothstar/product/domain/ItemAttribute.kt @@ -1,7 +1,6 @@ package org.store.clothstar.product.domain import jakarta.persistence.Embeddable -import org.hibernate.annotations.BatchSize /** * { "optionId": 1, "name": "색상", "value": "중청", "valueId": 1 } diff --git a/src/main/kotlin/org/store/clothstar/product/domain/Product.kt b/src/main/kotlin/org/store/clothstar/product/domain/Product.kt index d415eca..066e501 100644 --- a/src/main/kotlin/org/store/clothstar/product/domain/Product.kt +++ b/src/main/kotlin/org/store/clothstar/product/domain/Product.kt @@ -1,7 +1,6 @@ package org.store.clothstar.product.domain import jakarta.persistence.* -import org.hibernate.annotations.BatchSize import org.hibernate.annotations.Fetch import org.hibernate.annotations.FetchMode import org.store.clothstar.common.entity.BaseEntity diff --git a/src/main/kotlin/org/store/clothstar/product/domain/ProductImage.kt b/src/main/kotlin/org/store/clothstar/product/domain/ProductImage.kt index d1002c5..be79774 100644 --- a/src/main/kotlin/org/store/clothstar/product/domain/ProductImage.kt +++ b/src/main/kotlin/org/store/clothstar/product/domain/ProductImage.kt @@ -3,7 +3,6 @@ package org.store.clothstar.product.domain import jakarta.persistence.Embeddable import jakarta.persistence.EnumType import jakarta.persistence.Enumerated -import org.hibernate.annotations.BatchSize import org.store.clothstar.product.domain.type.ImageType @Embeddable diff --git a/src/main/kotlin/org/store/clothstar/product/domain/ProductOption.kt b/src/main/kotlin/org/store/clothstar/product/domain/ProductOption.kt index 8bb58f5..6024d5a 100644 --- a/src/main/kotlin/org/store/clothstar/product/domain/ProductOption.kt +++ b/src/main/kotlin/org/store/clothstar/product/domain/ProductOption.kt @@ -1,7 +1,6 @@ package org.store.clothstar.product.domain import jakarta.persistence.* -import org.hibernate.annotations.BatchSize /** diff --git a/src/main/kotlin/org/store/clothstar/product/repository/ProductRepository.kt b/src/main/kotlin/org/store/clothstar/product/repository/ProductRepository.kt index 33113c9..ebe40e4 100644 --- a/src/main/kotlin/org/store/clothstar/product/repository/ProductRepository.kt +++ b/src/main/kotlin/org/store/clothstar/product/repository/ProductRepository.kt @@ -1,6 +1,5 @@ package org.store.clothstar.product.repository -import org.springframework.data.jpa.repository.EntityGraph import org.springframework.data.jpa.repository.JpaRepository import org.springframework.stereotype.Repository import org.store.clothstar.product.domain.Product diff --git a/src/main/kotlin/org/store/clothstar/product/service/ProductApplicationService.kt b/src/main/kotlin/org/store/clothstar/product/service/ProductApplicationService.kt index 0dcf8b7..d670f94 100644 --- a/src/main/kotlin/org/store/clothstar/product/service/ProductApplicationService.kt +++ b/src/main/kotlin/org/store/clothstar/product/service/ProductApplicationService.kt @@ -6,7 +6,6 @@ import org.springframework.web.multipart.MultipartFile import org.store.clothstar.member.domain.Member import org.store.clothstar.member.domain.vo.MemberShoppingActivity import org.store.clothstar.member.service.MemberService -import org.store.clothstar.product.domain.Product import org.store.clothstar.product.domain.ProductImage import org.store.clothstar.product.domain.type.DisplayStatus import org.store.clothstar.product.domain.type.ImageType diff --git a/src/main/resources/order.sql b/src/main/resources/order.sql index f68bfbf..4daba37 100644 --- a/src/main/resources/order.sql +++ b/src/main/resources/order.sql @@ -55,7 +55,7 @@ INSERT INTO product (product_id, created_at, deleted_at, updated_at, category_id VALUES (1, CURRENT_TIMESTAMP, NULL, CURRENT_TIMESTAMP, 1, '반팔', 'HIDDEN', 1, '오구반팔', 19900, 1000, 'ON_SALE'); INSERT INTO seller (member_id, created_at, deleted_at, updated_at, biz_no, brand_name, total_sell_price) -VALUES (12, CURRENT_TIMESTAMP, NULL, CURRENT_TIMESTAMP, 1232-1234, '아디다스',1000); +VALUES (12, CURRENT_TIMESTAMP, NULL, CURRENT_TIMESTAMP, 1232 - 1234, '아디다스', 1000); show create table order_detail; From 3e637134bccd69f7b9a21a473a8ca4996cef7000 Mon Sep 17 00:00:00 2001 From: subin Date: Mon, 12 Aug 2024 22:59:34 +0900 Subject: [PATCH 06/10] =?UTF-8?q?refactor:=20=EC=95=88=20=EC=93=B0?= =?UTF-8?q?=EB=8A=94=20=ED=81=B4=EB=9E=98=EC=8A=A4=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../order/controller/OrderDetailController.kt | 19 --- .../order/dto/response/OrderDetailResponse.kt | 42 ------- .../order/service/OrderDetailService.kt | 116 ------------------ 3 files changed, 177 deletions(-) delete mode 100644 src/main/kotlin/org/store/clothstar/order/controller/OrderDetailController.kt delete mode 100644 src/main/kotlin/org/store/clothstar/order/dto/response/OrderDetailResponse.kt delete mode 100644 src/main/kotlin/org/store/clothstar/order/service/OrderDetailService.kt diff --git a/src/main/kotlin/org/store/clothstar/order/controller/OrderDetailController.kt b/src/main/kotlin/org/store/clothstar/order/controller/OrderDetailController.kt deleted file mode 100644 index e5584c4..0000000 --- a/src/main/kotlin/org/store/clothstar/order/controller/OrderDetailController.kt +++ /dev/null @@ -1,19 +0,0 @@ -//package org.store.clothstar.order.controller - -//@Tag(name = "OrderDetail", description = "주문 내 개별 상품에 대한 옵션, 수량 등을 나타내는, 주문상세(OrderDetail) 정보 관리에 대한 API 입니다.") -//@RestController -//class OrderDetailController( -// private val orderDetailService: OrderDetailService, -//) { -// @Operation(summary = "주문상세 추가 저장", description = "개별 상품에 대한 주문상세(상품명, 가격, 개수...)를 특정 주문에 추가 저장한다.") -// @PostMapping -// fun addOrderDetail(@RequestBody @Validated addOrderDetailRequest: AddOrderDetailRequest): ResponseEntity { -// val orderDetailId = orderDetailService.addOrderDetail(addOrderDetailRequest) -// -// return ResponseEntity.ok( -// SaveResponseDTO( -// orderDetailId, HttpStatus.OK.value(), "주문상세가 정상적으로 생성되었습니다." -// ) -// ) -// } -//} \ No newline at end of file diff --git a/src/main/kotlin/org/store/clothstar/order/dto/response/OrderDetailResponse.kt b/src/main/kotlin/org/store/clothstar/order/dto/response/OrderDetailResponse.kt deleted file mode 100644 index 5fb27dc..0000000 --- a/src/main/kotlin/org/store/clothstar/order/dto/response/OrderDetailResponse.kt +++ /dev/null @@ -1,42 +0,0 @@ -//package org.store.clothstar.order.dto.response -// -//import io.swagger.v3.oas.annotations.media.Schema -// -//@Schema(description = "주문 상세 조회용 Response") -//class OrderDetailResponse( -// @Schema(description = "주문 상세 번호", example = "1") -// val orderDetailId: Long, -// -// @Schema(description = "주문 번호", example = "1") -// val orderId: String, -// -// @Schema(description = "상품 번호", example = "1") -// val productLineId: Long, -// -// @Schema(description = "상품 옵션 번호", example = "1") -// val productId: Long, -// -// @Schema(description = "상품 수량", example = "2") -// val quantity: Int = 0, -// -// @Schema(description = "고정 가격", example = "15000") -// val fixedPrice: Int = 0, -// -// @Schema(description = "상품 종류 하나당 총 가격", example = "30000") -// val oneKindTotalPrice: Int = 0, -// -// @Schema(description = "상품 이름", example = "나이키 반팔티") -// val name: String, -// -// @Schema(description = "옵션 상품 재고", example = "30") -// val stock: Long, -// -// @Schema(description = "옵션 이름", example = "검정") -// val optionName: String, -// -// @Schema(description = "옵션 추가 비용", example = "0") -// val extraCharge: Int, -// -// @Schema(description = "브랜드 이름", example = "나이키") -// val brandName: String, -//) \ No newline at end of file diff --git a/src/main/kotlin/org/store/clothstar/order/service/OrderDetailService.kt b/src/main/kotlin/org/store/clothstar/order/service/OrderDetailService.kt deleted file mode 100644 index 34857e9..0000000 --- a/src/main/kotlin/org/store/clothstar/order/service/OrderDetailService.kt +++ /dev/null @@ -1,116 +0,0 @@ -//package org.store.clothstar.order.service -// -//import org.springframework.data.repository.findByIdOrNull -//import org.springframework.http.HttpStatus -//import org.springframework.stereotype.Service -//import org.springframework.transaction.annotation.Transactional -//import org.springframework.web.server.ResponseStatusException -//import org.store.clothstar.common.error.ErrorCode -//import org.store.clothstar.common.error.exception.order.OrderNotFoundException -//import org.store.clothstar.order.domain.vo.Status -//import org.store.clothstar.order.dto.request.AddOrderDetailRequest -//import org.store.clothstar.order.dto.request.CreateOrderDetailRequest -//import org.store.clothstar.order.repository.OrderDetailRepository -//import org.store.clothstar.order.repository.OrderRepository -//import org.store.clothstar.product.domain.Item -//import org.store.clothstar.product.domain.Product -//import org.store.clothstar.product.repository.ItemRepository -//import org.store.clothstar.product.repository.ProductRepository -//import org.store.clothstar.product.service.ItemService -// -//@Service -//class OrderDetailService( -// private val orderRepository: OrderRepository, -// private val orderDetailRepository: OrderDetailRepository, -// private val productRepository: ProductRepository, -// private val itemRepository: ItemRepository, -// private val itemService: ItemService, -//) { -//// // 주문 생성시 같이 호출되는 주문 상세 생성 메서드 - 하나의 트랜잭션으로 묶임 -//// @Transactional -//// fun saveOrderDetailWithOrder(createOrderDetailRequest: CreateOrderDetailRequest, orderId: String) { -//// val order = orderRepository.findByIdOrNull(orderId) -//// ?: throw ResponseStatusException(HttpStatus.NOT_FOUND, "주문 정보를 찾을 수 없습니다.") -//// -//// val product = productRepository.findByIdOrNull(createOrderDetailRequest.productId) -//// ?: throw ResponseStatusException(HttpStatus.NOT_FOUND, "상품 옵션 정보를 찾을 수 없습니다.") -//// -//// val item = itemRepository.findByIdOrNull(createOrderDetailRequest.itemId) -//// ?: throw ResponseStatusException(HttpStatus.NOT_FOUND, "상품 정보를 찾을 수 없습니다.") -//// -//// // 주문상세 생성 유효성 검사: 주문 수량이 상품 재고보다 클 경우, 주문이 생성되지 않는다. -//// if (createOrderDetailRequest.quantity > item.stock) { -//// throw ResponseStatusException(HttpStatus.BAD_REQUEST, "주문 개수가 재고보다 더 많습니다.") -//// } -//// -//// val orderDetail = createOrderDetailRequest.toOrderDetail(order, product, item) -//// orderDetailRepository.save(orderDetail) -//// -//// // 주문 정보 업데이트: 주문 상세 생성에 따른, 총 상품 금액과 총 결제 금액 업데이트 -//// val newTotalProductsPrice = order.totalPrice.products + orderDetail.price.oneKindTotalPrice -//// val newTotalPaymentPrice = -//// order.totalPrice.products + order.totalPrice.shipping + orderDetail.price.oneKindTotalPrice -//// -//// order.totalPrice.updatePrices(newTotalProductsPrice, newTotalPaymentPrice) -//// -//// // 주문 수량만큼 상품 재고 차감 -//// updateProductStock(item, orderDetail.quantity) -//// } -// -// // 주문 상세 추가 생성( -// @Transactional -// fun addOrderDetail(addOrderDetailRequest: AddOrderDetailRequest): Long { -// val order = orderRepository.findByIdOrNull(addOrderDetailRequest.orderId) -// ?: throw OrderNotFoundException(ErrorCode.NOT_FOUND_ORDER) -// val product: Product = productService.getProductById(addOrderDetailRequest.productId) -// val item: Item = itemService.getItemById(addOrderDetailRequest.itemId) -// -// if (addOrderDetailRequest.quantity > item.stock) { -// throw ResponseStatusException(HttpStatus.BAD_REQUEST, "주문 개수가 재고보다 더 많습니다.") -// } -// -// if (order.status != Status.CONFIRMED) { -// throw ResponseStatusException(HttpStatus.BAD_REQUEST, "이미 입금된 상태에서는 추가 주문이 불가능합니다.") -// } -// -// val orderDetail = addOrderDetailRequest.toOrderDetail(order, product, item) -// orderDetailRepository.save(orderDetail) -// -// val newTotalProductsPrice = order.totalPrice.products + orderDetail.price.oneKindTotalPrice -// val newTotalPaymentPrice = -// order.totalPrice.products + order.totalPrice.shipping + orderDetail.price.oneKindTotalPrice -// -// order.totalPrice.updatePrices(newTotalProductsPrice, newTotalPaymentPrice) -// -// updateProductStock(item, orderDetail.quantity) -// -// return orderDetail.orderDetailId!! -// } -//// -//// @Transactional -//// fun updateDeleteAt(orderDetailId: Long) { -//// val orderDetail = orderDetailRepository.findById(orderDetailId) -//// .orElseThrow { ResponseStatusException(HttpStatus.NOT_FOUND, "주문상세 번호를 찾을 수 없습니다.") } -//// -//// if (orderDetail.deletedAt != null) { -//// throw ResponseStatusException(HttpStatus.NOT_FOUND, "이미 삭제된 주문입니다.") -//// } -//// -//// restoreStockByOrderDetail(orderDetailId) -//// orderDetail.updateDeletedAt() -//// } -// -// @Transactional -// fun updateProductStock(item: Item, quantity: Int) { -// val updatedStock = item.stock - quantity -// item.updateStock(updatedStock) -// } -//// -//// @Transactional -//// fun restoreStockByOrderDetail(orderDetailId: Long) { -//// val orderDetail = orderDetailRepository.findByIdOrNull(orderDetailId) -//// ?: throw ResponseStatusException(HttpStatus.NOT_FOUND, "주문상세 번호를 찾을 수 없습니다.") -//// -//// itemService.restoreProductStockByOrderDetail(orderDetail) -//// } -//} \ No newline at end of file From 4436271bd562325ec909d058b4deafe95f70a0b4 Mon Sep 17 00:00:00 2001 From: subin Date: Thu, 15 Aug 2024 00:27:50 +0900 Subject: [PATCH 07/10] =?UTF-8?q?test:=20=EB=8B=A8=EC=9D=BC=20=EC=A3=BC?= =?UTF-8?q?=EB=AC=B8=20=EC=A1=B0=ED=9A=8C=20=ED=86=B5=ED=95=A9=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...Repository.kt => CategoryJpaRepository.kt} | 0 .../store/clothstar/member/domain/Address.kt | 3 +- .../clothstar/member/domain/vo/AddressInfo.kt | 12 ++- .../member/dto/request/CreateMemberRequest.kt | 1 + .../order/utils/CreateOrderObject.kt | 73 ++++++++++++++ src/main/resources/order.sql | 4 +- .../clothstar/member/util/CreateObject.kt | 26 ++++- .../clothstar/order/OrderIntegrationTest.kt | 97 +++++++++++++++++++ 8 files changed, 208 insertions(+), 8 deletions(-) rename src/main/kotlin/org/store/clothstar/category/repository/{CategoryRepository.kt => CategoryJpaRepository.kt} (100%) create mode 100644 src/main/kotlin/org/store/clothstar/order/utils/CreateOrderObject.kt create mode 100644 src/test/kotlin/org/store/clothstar/order/OrderIntegrationTest.kt diff --git a/src/main/kotlin/org/store/clothstar/category/repository/CategoryRepository.kt b/src/main/kotlin/org/store/clothstar/category/repository/CategoryJpaRepository.kt similarity index 100% rename from src/main/kotlin/org/store/clothstar/category/repository/CategoryRepository.kt rename to src/main/kotlin/org/store/clothstar/category/repository/CategoryJpaRepository.kt diff --git a/src/main/kotlin/org/store/clothstar/member/domain/Address.kt b/src/main/kotlin/org/store/clothstar/member/domain/Address.kt index 052401a..160daf8 100644 --- a/src/main/kotlin/org/store/clothstar/member/domain/Address.kt +++ b/src/main/kotlin/org/store/clothstar/member/domain/Address.kt @@ -16,5 +16,4 @@ class Address( @Embedded val addressInfo: AddressInfo, -) : BaseEntity() { -} \ No newline at end of file +) : BaseEntity() \ No newline at end of file diff --git a/src/main/kotlin/org/store/clothstar/member/domain/vo/AddressInfo.kt b/src/main/kotlin/org/store/clothstar/member/domain/vo/AddressInfo.kt index 6e9d1e9..cf7fb6c 100644 --- a/src/main/kotlin/org/store/clothstar/member/domain/vo/AddressInfo.kt +++ b/src/main/kotlin/org/store/clothstar/member/domain/vo/AddressInfo.kt @@ -7,4 +7,14 @@ class AddressInfo( val addressBasic: String, val addressDetail: String, val zipNo: String, -) \ No newline at end of file +) { + companion object { + fun init(): AddressInfo { + return AddressInfo( + addressBasic = "address1", + addressDetail = "address2", + zipNo = "01234", + ) + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/org/store/clothstar/member/dto/request/CreateMemberRequest.kt b/src/main/kotlin/org/store/clothstar/member/dto/request/CreateMemberRequest.kt index d369b30..87eaf2d 100644 --- a/src/main/kotlin/org/store/clothstar/member/dto/request/CreateMemberRequest.kt +++ b/src/main/kotlin/org/store/clothstar/member/dto/request/CreateMemberRequest.kt @@ -1,6 +1,7 @@ package org.store.clothstar.member.dto.request import jakarta.validation.constraints.* +import org.store.clothstar.member.domain.Member class CreateMemberRequest( @field: Email(message = "유효하지 않은 이메일 형식입니다.") diff --git a/src/main/kotlin/org/store/clothstar/order/utils/CreateOrderObject.kt b/src/main/kotlin/org/store/clothstar/order/utils/CreateOrderObject.kt new file mode 100644 index 0000000..67538e5 --- /dev/null +++ b/src/main/kotlin/org/store/clothstar/order/utils/CreateOrderObject.kt @@ -0,0 +1,73 @@ +package org.store.clothstar.order.utils + +import org.store.clothstar.category.domain.Category +import org.store.clothstar.order.domain.Order +import org.store.clothstar.order.domain.OrderDetail +import org.store.clothstar.order.domain.vo.PaymentMethod +import org.store.clothstar.order.domain.vo.Price +import org.store.clothstar.order.domain.vo.Status +import org.store.clothstar.order.domain.vo.TotalPrice +import org.store.clothstar.product.domain.Item +import org.store.clothstar.product.domain.Product +import org.store.clothstar.product.domain.type.DisplayStatus +import org.store.clothstar.product.domain.type.SaleStatus + +class CreateOrderObject { + companion object { + fun getCategory(): Category { + return Category( + categoryId = 1L, + categoryType = "상의", + ) + } + + fun getProduct(): Product { + return Product( + productId = 1L, + memberId = 1L, + categoryId = this.getCategory().categoryId!!, + name = "상품", + content = "상품내용", + price = 1000, + saleCount = 0, + displayStatus = DisplayStatus.VISIBLE, + saleStatus = SaleStatus.ALL, + ) + } + + fun getItem(): Item { + return Item( + itemId = 1L, + name = "상품 옵션 이름", + finalPrice = 2000, + stock = 10, + saleStatus = SaleStatus.ALL, + displayStatus = DisplayStatus.HIDDEN, + product = this.getProduct() + ) + } + + fun getOrder(): Order { + return Order( + orderId = "0eb44b79-6b9a-4ca9-8984-761e18101511", + memberId = 1L, + addressId = 1L, + status = Status.CONFIRMED, + paymentMethod = PaymentMethod.CARD, + totalPrice = TotalPrice(shipping = 0, products = 0, payment = 0) + ) + } + + fun getOrderDetail(): OrderDetail { + return OrderDetail( + orderDetailId = 1L, + productId = this.getProduct().productId!!, + itemId = this.getItem().itemId!!, + quantity = 1, + price = Price(fixedPrice = this.getProduct().price, + oneKindTotalPrice = 10000), + order = this.getOrder() + ) + } + } +} \ No newline at end of file diff --git a/src/main/resources/order.sql b/src/main/resources/order.sql index 4daba37..260568b 100644 --- a/src/main/resources/order.sql +++ b/src/main/resources/order.sql @@ -77,4 +77,6 @@ from address; select * from member; select * -from seller; \ No newline at end of file +from seller; +select * +from category; \ No newline at end of file diff --git a/src/test/kotlin/org/store/clothstar/member/util/CreateObject.kt b/src/test/kotlin/org/store/clothstar/member/util/CreateObject.kt index 50764e5..2ffb277 100644 --- a/src/test/kotlin/org/store/clothstar/member/util/CreateObject.kt +++ b/src/test/kotlin/org/store/clothstar/member/util/CreateObject.kt @@ -1,15 +1,13 @@ package org.store.clothstar.member.util -import org.store.clothstar.member.domain.Account -import org.store.clothstar.member.domain.Member -import org.store.clothstar.member.domain.MemberRole +import org.store.clothstar.member.domain.* +import org.store.clothstar.member.domain.vo.AddressInfo import org.store.clothstar.member.domain.vo.MemberShoppingActivity import org.store.clothstar.member.dto.request.CreateAddressRequest import org.store.clothstar.member.dto.request.CreateMemberRequest import org.store.clothstar.member.dto.request.CreateSellerRequest import org.store.clothstar.member.dto.request.MemberLoginRequest - class CreateObject { companion object { private const val email = "test@naver.com" @@ -44,12 +42,32 @@ class CreateObject { fun getMember(): Member { return Member( + memberId = 1L, telNo = "010-1234-4444", name = "현수", memberShoppingActivity = MemberShoppingActivity.init() ) } + fun getAddress(): Address { + return Address( + addressId = 1L, + receiverName = "현수", + telNo = "010-1234-4444", + memberId = this.getMember().memberId!!, + deliveryRequest = "문 앞에 놔주세요", + addressInfo = AddressInfo.init() + ) + } + + fun getSeller(): Seller { + return Seller( + memberId = this.getMember().memberId!!, + brandName = "나이키", + bizNo = "123-123", + totalSellPrice = 1000) + } + fun getAccount(userId: Long): Account { return Account( email = email, diff --git a/src/test/kotlin/org/store/clothstar/order/OrderIntegrationTest.kt b/src/test/kotlin/org/store/clothstar/order/OrderIntegrationTest.kt new file mode 100644 index 0000000..0b05ebb --- /dev/null +++ b/src/test/kotlin/org/store/clothstar/order/OrderIntegrationTest.kt @@ -0,0 +1,97 @@ +package org.store.clothstar.order + +import org.junit.jupiter.api.DisplayName +import org.junit.jupiter.api.Test +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc +import org.springframework.boot.test.context.SpringBootTest +import org.springframework.http.MediaType +import org.springframework.test.context.ActiveProfiles +import org.springframework.test.web.servlet.MockMvc +import org.springframework.test.web.servlet.ResultActions +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders +import org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath +import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status +import org.springframework.transaction.annotation.Transactional +import org.store.clothstar.category.domain.Category +import org.store.clothstar.category.repository.CategoryJpaRepository +import org.store.clothstar.member.domain.Address +import org.store.clothstar.member.domain.Member +import org.store.clothstar.member.domain.Seller +import org.store.clothstar.member.repository.AddressRepository +import org.store.clothstar.member.repository.MemberRepository +import org.store.clothstar.member.repository.SellerRepository +import org.store.clothstar.member.util.CreateObject +import org.store.clothstar.order.domain.Order +import org.store.clothstar.order.domain.OrderDetail +import org.store.clothstar.order.repository.OrderDetailRepository +import org.store.clothstar.order.repository.OrderRepository +import org.store.clothstar.order.utils.CreateOrderObject +import org.store.clothstar.product.domain.Item +import org.store.clothstar.product.domain.Product +import org.store.clothstar.product.repository.ItemRepository +import org.store.clothstar.product.repository.ProductRepository + +@Transactional +@SpringBootTest +@ActiveProfiles("test") +@AutoConfigureMockMvc +class OrderIntegrationTest{ + @Autowired + private lateinit var mockMvc: MockMvc + + @Autowired + private lateinit var orderRepository: OrderRepository + + @Autowired + private lateinit var memberRepository: MemberRepository + + @Autowired + private lateinit var addressRepository: AddressRepository + + @Autowired + private lateinit var categoryRepository: CategoryJpaRepository + + @Autowired + private lateinit var productRepository: ProductRepository + + @Autowired + private lateinit var itemRepository: ItemRepository + + @Autowired + private lateinit var sellerRepository: SellerRepository + + private val ORDER_URL: String = "/v1/orders" + + @Autowired + private lateinit var orderDetailRepository: OrderDetailRepository + + @DisplayName("단일 주문 조회 통합테스트") + @Test + fun testGetOrder(){ + //given + val member: Member = memberRepository.save(CreateObject.getMember()) + val address: Address = addressRepository.save(CreateObject.getAddress()) + val category: Category = categoryRepository.save(CreateOrderObject.getCategory()) + val seller: Seller = sellerRepository.save(CreateObject.getSeller()) + val product: Product = productRepository.save(CreateOrderObject.getProduct()) + val item: Item = itemRepository.save(CreateOrderObject.getItem()) + val order: Order = CreateOrderObject.getOrder() + orderRepository.save(order) + val orderDetail: OrderDetail = orderDetailRepository.save(CreateOrderObject.getOrderDetail()) + order.addOrderDetail(orderDetail) + orderRepository.save(order) + + val orderId: String = order.orderId + val getOrderURL: String = ORDER_URL + "/" + orderId + + //when + val actions: ResultActions = mockMvc.perform( + MockMvcRequestBuilders.get(getOrderURL) + .contentType(MediaType.APPLICATION_JSON)) + + //then + actions.andExpect(status().isOk) + .andExpect(jsonPath("$.orderId").value(orderId)) + } +} \ No newline at end of file From e714ba7d84a6725b609fd52bba80cb4d08f55f2b Mon Sep 17 00:00:00 2001 From: subin Date: Thu, 15 Aug 2024 01:17:17 +0900 Subject: [PATCH 08/10] refactor: Optimize Imports & Reformat Code --- .../member/dto/request/CreateMemberRequest.kt | 1 - .../order/utils/CreateOrderObject.kt | 6 +++-- .../dto/request/UpdateDisplayStatusRequest.kt | 2 +- .../clothstar/member/util/CreateObject.kt | 3 ++- .../clothstar/order/OrderIntegrationTest.kt | 27 +++++++++---------- 5 files changed, 19 insertions(+), 20 deletions(-) diff --git a/src/main/kotlin/org/store/clothstar/member/dto/request/CreateMemberRequest.kt b/src/main/kotlin/org/store/clothstar/member/dto/request/CreateMemberRequest.kt index 87eaf2d..d369b30 100644 --- a/src/main/kotlin/org/store/clothstar/member/dto/request/CreateMemberRequest.kt +++ b/src/main/kotlin/org/store/clothstar/member/dto/request/CreateMemberRequest.kt @@ -1,7 +1,6 @@ package org.store.clothstar.member.dto.request import jakarta.validation.constraints.* -import org.store.clothstar.member.domain.Member class CreateMemberRequest( @field: Email(message = "유효하지 않은 이메일 형식입니다.") diff --git a/src/main/kotlin/org/store/clothstar/order/utils/CreateOrderObject.kt b/src/main/kotlin/org/store/clothstar/order/utils/CreateOrderObject.kt index 67538e5..4138ed1 100644 --- a/src/main/kotlin/org/store/clothstar/order/utils/CreateOrderObject.kt +++ b/src/main/kotlin/org/store/clothstar/order/utils/CreateOrderObject.kt @@ -64,8 +64,10 @@ class CreateOrderObject { productId = this.getProduct().productId!!, itemId = this.getItem().itemId!!, quantity = 1, - price = Price(fixedPrice = this.getProduct().price, - oneKindTotalPrice = 10000), + price = Price( + fixedPrice = this.getProduct().price, + oneKindTotalPrice = 10000 + ), order = this.getOrder() ) } diff --git a/src/main/kotlin/org/store/clothstar/product/dto/request/UpdateDisplayStatusRequest.kt b/src/main/kotlin/org/store/clothstar/product/dto/request/UpdateDisplayStatusRequest.kt index a44536a..667cbe9 100644 --- a/src/main/kotlin/org/store/clothstar/product/dto/request/UpdateDisplayStatusRequest.kt +++ b/src/main/kotlin/org/store/clothstar/product/dto/request/UpdateDisplayStatusRequest.kt @@ -4,7 +4,7 @@ package org.store.clothstar.product.dto.request import jakarta.validation.constraints.NotNull import org.store.clothstar.product.domain.type.DisplayStatus -class UpdateDisplayStatusRequest ( +class UpdateDisplayStatusRequest( @NotNull(message = "진열 상태를 설정해주세요.") val displayStatus: DisplayStatus, diff --git a/src/test/kotlin/org/store/clothstar/member/util/CreateObject.kt b/src/test/kotlin/org/store/clothstar/member/util/CreateObject.kt index 2ffb277..c0dbd89 100644 --- a/src/test/kotlin/org/store/clothstar/member/util/CreateObject.kt +++ b/src/test/kotlin/org/store/clothstar/member/util/CreateObject.kt @@ -65,7 +65,8 @@ class CreateObject { memberId = this.getMember().memberId!!, brandName = "나이키", bizNo = "123-123", - totalSellPrice = 1000) + totalSellPrice = 1000 + ) } fun getAccount(userId: Long): Account { diff --git a/src/test/kotlin/org/store/clothstar/order/OrderIntegrationTest.kt b/src/test/kotlin/org/store/clothstar/order/OrderIntegrationTest.kt index 0b05ebb..c6f79cc 100644 --- a/src/test/kotlin/org/store/clothstar/order/OrderIntegrationTest.kt +++ b/src/test/kotlin/org/store/clothstar/order/OrderIntegrationTest.kt @@ -13,11 +13,7 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders import org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status import org.springframework.transaction.annotation.Transactional -import org.store.clothstar.category.domain.Category import org.store.clothstar.category.repository.CategoryJpaRepository -import org.store.clothstar.member.domain.Address -import org.store.clothstar.member.domain.Member -import org.store.clothstar.member.domain.Seller import org.store.clothstar.member.repository.AddressRepository import org.store.clothstar.member.repository.MemberRepository import org.store.clothstar.member.repository.SellerRepository @@ -27,8 +23,6 @@ import org.store.clothstar.order.domain.OrderDetail import org.store.clothstar.order.repository.OrderDetailRepository import org.store.clothstar.order.repository.OrderRepository import org.store.clothstar.order.utils.CreateOrderObject -import org.store.clothstar.product.domain.Item -import org.store.clothstar.product.domain.Product import org.store.clothstar.product.repository.ItemRepository import org.store.clothstar.product.repository.ProductRepository @@ -36,7 +30,7 @@ import org.store.clothstar.product.repository.ProductRepository @SpringBootTest @ActiveProfiles("test") @AutoConfigureMockMvc -class OrderIntegrationTest{ +class OrderIntegrationTest { @Autowired private lateinit var mockMvc: MockMvc @@ -68,14 +62,16 @@ class OrderIntegrationTest{ @DisplayName("단일 주문 조회 통합테스트") @Test - fun testGetOrder(){ + fun testGetOrder() { //given - val member: Member = memberRepository.save(CreateObject.getMember()) - val address: Address = addressRepository.save(CreateObject.getAddress()) - val category: Category = categoryRepository.save(CreateOrderObject.getCategory()) - val seller: Seller = sellerRepository.save(CreateObject.getSeller()) - val product: Product = productRepository.save(CreateOrderObject.getProduct()) - val item: Item = itemRepository.save(CreateOrderObject.getItem()) + // + memberRepository.save(CreateObject.getMember()) + addressRepository.save(CreateObject.getAddress()) + categoryRepository.save(CreateOrderObject.getCategory()) + sellerRepository.save(CreateObject.getSeller()) + productRepository.save(CreateOrderObject.getProduct()) + itemRepository.save(CreateOrderObject.getItem()) + val order: Order = CreateOrderObject.getOrder() orderRepository.save(order) val orderDetail: OrderDetail = orderDetailRepository.save(CreateOrderObject.getOrderDetail()) @@ -88,7 +84,8 @@ class OrderIntegrationTest{ //when val actions: ResultActions = mockMvc.perform( MockMvcRequestBuilders.get(getOrderURL) - .contentType(MediaType.APPLICATION_JSON)) + .contentType(MediaType.APPLICATION_JSON) + ) //then actions.andExpect(status().isOk) From 5f1185d44ce225d8df25683fe03ba51338bacd18 Mon Sep 17 00:00:00 2001 From: subin Date: Thu, 15 Aug 2024 01:19:03 +0900 Subject: [PATCH 09/10] =?UTF-8?q?refactor:=20=EC=A3=BC=EC=84=9D=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/org/store/clothstar/order/OrderIntegrationTest.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/kotlin/org/store/clothstar/order/OrderIntegrationTest.kt b/src/test/kotlin/org/store/clothstar/order/OrderIntegrationTest.kt index c6f79cc..5b5911d 100644 --- a/src/test/kotlin/org/store/clothstar/order/OrderIntegrationTest.kt +++ b/src/test/kotlin/org/store/clothstar/order/OrderIntegrationTest.kt @@ -64,7 +64,6 @@ class OrderIntegrationTest { @Test fun testGetOrder() { //given - // memberRepository.save(CreateObject.getMember()) addressRepository.save(CreateObject.getAddress()) categoryRepository.save(CreateOrderObject.getCategory()) From 43f92a09ea459717ef96c2a1e64737f059df4c8a Mon Sep 17 00:00:00 2001 From: subin Date: Thu, 15 Aug 2024 03:39:38 +0900 Subject: [PATCH 10/10] =?UTF-8?q?refactor:=20DirtiesContext=20=EC=96=B4?= =?UTF-8?q?=EB=85=B8=ED=85=8C=EC=9D=B4=EC=85=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../clothstar/order/OrderIntegrationTest.kt | 57 ++++++++++++++----- 1 file changed, 44 insertions(+), 13 deletions(-) diff --git a/src/test/kotlin/org/store/clothstar/order/OrderIntegrationTest.kt b/src/test/kotlin/org/store/clothstar/order/OrderIntegrationTest.kt index 5b5911d..fcbb8da 100644 --- a/src/test/kotlin/org/store/clothstar/order/OrderIntegrationTest.kt +++ b/src/test/kotlin/org/store/clothstar/order/OrderIntegrationTest.kt @@ -6,6 +6,7 @@ import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc import org.springframework.boot.test.context.SpringBootTest import org.springframework.http.MediaType +import org.springframework.test.annotation.DirtiesContext import org.springframework.test.context.ActiveProfiles import org.springframework.test.web.servlet.MockMvc import org.springframework.test.web.servlet.ResultActions @@ -26,39 +27,69 @@ import org.store.clothstar.order.utils.CreateOrderObject import org.store.clothstar.product.repository.ItemRepository import org.store.clothstar.product.repository.ProductRepository -@Transactional @SpringBootTest -@ActiveProfiles("test") @AutoConfigureMockMvc -class OrderIntegrationTest { +@ActiveProfiles("test") +@Transactional +@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) +class OrderIntegrationTest( @Autowired - private lateinit var mockMvc: MockMvc + private val mockMvc: MockMvc, @Autowired - private lateinit var orderRepository: OrderRepository + private val orderRepository: OrderRepository, @Autowired - private lateinit var memberRepository: MemberRepository + private val memberRepository: MemberRepository, @Autowired - private lateinit var addressRepository: AddressRepository + private val addressRepository: AddressRepository, @Autowired - private lateinit var categoryRepository: CategoryJpaRepository + private val categoryRepository: CategoryJpaRepository, @Autowired - private lateinit var productRepository: ProductRepository + private val productRepository: ProductRepository, @Autowired - private lateinit var itemRepository: ItemRepository + private val itemRepository: ItemRepository, @Autowired - private lateinit var sellerRepository: SellerRepository + private val sellerRepository: SellerRepository, + @Autowired + private val orderDetailRepository: OrderDetailRepository, +) { private val ORDER_URL: String = "/v1/orders" - @Autowired - private lateinit var orderDetailRepository: OrderDetailRepository +// @Autowired +// private lateinit var mockMvc: MockMvc +// +// @Autowired +// private lateinit var orderRepository: OrderRepository +// +// @Autowired +// private lateinit var memberRepository: MemberRepository +// +// @Autowired +// private lateinit var addressRepository: AddressRepository +// +// @Autowired +// private lateinit var categoryRepository: CategoryJpaRepository +// +// @Autowired +// private lateinit var productRepository: ProductRepository +// +// @Autowired +// private lateinit var itemRepository: ItemRepository +// +// @Autowired +// private lateinit var sellerRepository: SellerRepository +// +// private val ORDER_URL: String = "/v1/orders" +// +// @Autowired +// private lateinit var orderDetailRepository: OrderDetailRepository @DisplayName("단일 주문 조회 통합테스트") @Test