Skip to content

Commit

Permalink
Merge pull request #23 from ClothingStoreService/test/order-integration
Browse files Browse the repository at this point in the history
주문 통합테스트 구현
  • Loading branch information
axhtl authored Aug 22, 2024
2 parents aca383a + 070c198 commit e29229a
Show file tree
Hide file tree
Showing 21 changed files with 735 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
package org.store.clothstar.member

import org.springframework.stereotype.Component
import org.store.clothstar.common.error.ErrorCode
import org.store.clothstar.common.error.exception.order.BadRequestException
import org.store.clothstar.member.domain.Account
import org.store.clothstar.member.domain.MemberRole

@Component
class AccountValidateUtil (
class AccountValidateUtil(

) {

Expand Down
3 changes: 1 addition & 2 deletions src/main/kotlin/org/store/clothstar/member/domain/Address.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,4 @@ class Address(

@Embedded
val addressInfo: AddressInfo,
) : BaseEntity() {
}
) : BaseEntity()
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,14 @@ class AddressInfo(
val addressBasic: String,
val addressDetail: String,
val zipNo: String,
)
) {
companion object {
fun init(): AddressInfo {
return AddressInfo(
addressBasic = "address1",
addressDetail = "address2",
zipNo = "01234",
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class OrderSellerController(
private val orderSellerService: OrderSellerService
) {

@Operation(summary = "(판매자) WAITING 주문 리스트 조회", description = "(판매자) 주문상태가 '승인대기'인 주문 리스트를 조회한다.")
@Operation(summary = "(판매자) CONFIRMED 주문 리스트 조회", description = "(판매자) 주문상태가 '승인대기'인 주문 리스트를 조회한다.")
@GetMapping
fun getWaitingOrder(): ResponseEntity<List<OrderResponse>> {
val orderResponseList: List<OrderResponse> = orderSellerService.getConfirmedOrders()
Expand All @@ -48,7 +48,7 @@ class OrderSellerController(
@PatchMapping("/{orderId}/process")
fun approveOrder(@PathVariable orderId: String): ResponseEntity<MessageDTO> {
orderSellerService.approveOrder(orderId)
val messageDTO = MessageDTO(HttpStatus.OK.value(), "주문이 정상적으로 출고처리 되었습니다.")
val messageDTO = MessageDTO(HttpStatus.OK.value(), "주문이 정상적으로 출고처리되었습니다.")
return ResponseEntity.ok(messageDTO)
}

Expand All @@ -72,7 +72,7 @@ class OrderSellerController(
@PatchMapping("/{orderId}/cancel")
fun cancelOrder(@PathVariable orderId: String): ResponseEntity<MessageDTO> {
orderSellerService.cancelOrder(orderId)
val messageDTO = MessageDTO(HttpStatus.OK.value(), "주문이 정상적으로 취소 되었습니다.")
val messageDTO = MessageDTO(HttpStatus.OK.value(), "주문이 정상적으로 취소되었습니다.")
return ResponseEntity.ok(messageDTO)
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.store.clothstar.order.repository

import org.springframework.data.domain.Pageable
import org.springframework.data.domain.Slice
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.jpa.repository.Query
import org.store.clothstar.order.domain.Order
Expand All @@ -9,4 +11,6 @@ interface OrderRepository : JpaRepository<Order, String> {

@Query("SELECT o FROM orders o WHERE o.status = 'CONFIRMED' AND o.deletedAt is null")
fun findConfirmedAndNotDeletedOrders(): List<Order>

fun findAllByOrderByOrderIdDesc(pageable: Pageable): Slice<Order>
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class OrderUserService(
}

fun getAllOrderSlicePaging(pageable: Pageable): Slice<OrderResponse> {
val orders: Slice<Order> = orderRepository.findAll(pageable)
val orders: Slice<Order> = orderRepository.findAllByOrderByOrderIdDesc(pageable)

return orders.map {
// order 관련 member, address, seller 불러오기
Expand Down Expand Up @@ -164,10 +164,8 @@ class OrderUserService(

// Map으로부터 Id, Entity를 가져오면서 주문상세 DTO 리스트 만들기
val orderDetailDTOList: List<OrderDetailDTO> = 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 product: Product = productMap[it.productId]!!
val item: Item = itemMap[it.itemId]!!
val brandName: String = seller.brandName
OrderDetailDTO.from(it, item, product, brandName)
}
Expand Down Expand Up @@ -204,6 +202,7 @@ class OrderUserService(

val orderDetail = addOrderDetailRequest.toOrderDetail(order, product, item)
orderDetailRepository.save(orderDetail)
order.addOrderDetail(orderDetail)

val newTotalProductsPrice = order.totalPrice.products + orderDetail.price.oneKindTotalPrice
val newTotalPaymentPrice =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ import org.springframework.data.domain.Slice
import org.springframework.data.web.PageableDefault
import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity
import org.springframework.validation.annotation.Validated
import org.springframework.web.bind.annotation.*
import org.springframework.web.multipart.MultipartFile
import org.store.clothstar.common.dto.MessageDTO
import org.store.clothstar.product.dto.request.ProductCreateRequest
import org.store.clothstar.product.dto.response.ProductListResponse
import org.store.clothstar.product.dto.response.ProductResponse
import org.store.clothstar.product.service.ProductApplicationService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import org.store.clothstar.product.dto.request.ProductCreateRequest
import org.store.clothstar.product.dto.request.UpdateDisplayStatusRequest
import org.store.clothstar.product.dto.request.UpdateStockRequest
import org.store.clothstar.product.dto.response.ProductResponse
import org.store.clothstar.product.service.ProductApplicationService
import org.store.clothstar.product.service.ProductSellerApplicationService

@Tag(name = "ProductSellers", description = "ProductSellers(판매자) 관련 API 입니다.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package org.store.clothstar.product.dto.request
import jakarta.validation.constraints.NotNull
import jakarta.validation.constraints.PositiveOrZero

class UpdateStockRequest (
class UpdateStockRequest(

@field:NotNull(message = "재고 수량은 필수 입력 사항입니다.")
@field:PositiveOrZero(message = "재고 수량은 0 이상이어야 합니다.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package org.store.clothstar.product.dto.response

import io.swagger.v3.oas.annotations.media.Schema
import org.store.clothstar.member.dto.response.SellerSimpleResponse
import org.store.clothstar.product.domain.Item
import org.store.clothstar.product.domain.Product
import org.store.clothstar.product.domain.type.SaleStatus

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.store.clothstar.product.dto.response

import org.store.clothstar.member.domain.Seller
import org.store.clothstar.member.dto.response.SellerSimpleResponse
import org.store.clothstar.product.domain.*
import org.store.clothstar.product.domain.type.DisplayStatus
Expand Down Expand Up @@ -39,9 +38,10 @@ class ProductResponse(
val seller: SellerSimpleResponse
) {
companion object {
fun from(product: Product,
seller: SellerSimpleResponse,
isSeller: Boolean
fun from(
product: Product,
seller: SellerSimpleResponse,
isSeller: Boolean
): ProductResponse {

val items = if (isSeller) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import org.store.clothstar.product.dto.request.ProductCreateRequest
import org.store.clothstar.product.dto.response.ProductResponse

@Service
class ProductSellerApplicationService (
class ProductSellerApplicationService(
private val productService: ProductService,
private val productOptionService: ProductOptionService,
private val itemService: ItemService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ class ProductService(
}
}

fun getAllProductsOffsetPaging(pageable: Pageable, keyword: String?
fun getAllProductsOffsetPaging(
pageable: Pageable, keyword: String?
): Page<ProductListResponse> {

val productPages = productRepository.findAllOffsetPaging(pageable, keyword)
Expand All @@ -80,7 +81,8 @@ class ProductService(
}
}

fun getAllProductsSlicePaging(pageable: Pageable, keyword: String?
fun getAllProductsSlicePaging(
pageable: Pageable, keyword: String?
): Slice<ProductListResponse> {

val productPages = productRepository.findAllSlicePaging(pageable, keyword)
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/order.sql
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,6 @@ from address;
select *
from member;
select *
from seller;
from seller;
select *
from category;
27 changes: 23 additions & 4 deletions src/test/kotlin/org/store/clothstar/member/util/CreateObject.kt
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]"
Expand Down Expand Up @@ -44,12 +42,33 @@ 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,
Expand Down
11 changes: 11 additions & 0 deletions src/test/kotlin/org/store/clothstar/member/util/OrderComponent.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.store.clothstar.member.util

import org.store.clothstar.order.domain.Order
import org.store.clothstar.product.domain.Item
import org.store.clothstar.product.domain.Product

class OrderComponent(
val order: Order,
val product: Product,
val item: Item
)
Loading

0 comments on commit e29229a

Please sign in to comment.