Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

구매자 구매확정 기능 단위테스트를 kotest 형식으로 변경 #20

Merged
merged 8 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class CustomAuthenticationEntryPoint : AuthenticationEntryPoint {
authException: AuthenticationException,
) {
log.error { "인증 실패 로직 실행" }

response.status = HttpServletResponse.SC_UNAUTHORIZED
response.characterEncoding = "UTF-8"
response.contentType = "application/json"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ class MemberLoginRequest(
val password: String,
) {
constructor() : this("", "") {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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 입니다.")
Expand All @@ -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<List<OrderResponse>> {
// val orderResponseList: List<OrderResponse> = orderSellerService.getConfirmedOrder()
// return ResponseEntity.ok(orderResponseList)
// }

@Operation(summary = "(판매자) WAITING 주문 리스트 조회", description = "(판매자) 주문상태가 '승인대기'인 주문 리스트를 조회한다.")
@GetMapping
fun getWaitingOrder(): ResponseEntity<List<OrderResponse>> {
val orderResponseList: List<OrderResponse> = orderSellerService.getConfirmedOrders()
return ResponseEntity.ok(orderResponseList)
}

@Operation(summary = "판매자 주문 승인", description = "판매자가 주문을 출고처리한다.")
@ApiResponses(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,53 @@ 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
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.OrderResponse
import org.store.clothstar.order.dto.response.SaveOrderResponse
import org.store.clothstar.order.service.OrderUserService

@Tag(name = "Order", description = "주문(Order) 정보 관리에 대한 API 입니다.")
@RestController
@RequestMapping("/v1/orders")
class OrderUserController(
private val orderService: OrderUserService
private val orderUserService: OrderUserService,
) {
// @Operation(summary = "단일 주문 조회", description = "단일 주문의 정보를 조회한다.")
// @GetMapping("/{orderId}")
// fun getOrder(@PathVariable orderId: String): ResponseEntity<OrderResponse> {
// val orderResponse: OrderResponse = orderService.getOrder(orderId)
// return ResponseEntity.ok(orderResponse)
// }
@Operation(summary = "단일 주문 조회", description = "단일 주문의 정보를 조회한다.")
@GetMapping("/{orderId}")
fun getOrder(@PathVariable orderId: String): ResponseEntity<OrderResponse> {
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<Page<OrderResponse>> {
val orderPages: Page<OrderResponse> = orderUserService.getAllOrderOffsetPaging(pageable)
return ResponseEntity.ok(orderPages)
}

@Operation(summary = "전체 주문 조회 slice 페이징", description = "전체 주문 리스트를 slice 페이징 형식으로 가져온다.")
@GetMapping("/slice")
fun getAllOrderSlicePaging(
@PageableDefault(size = 15) pageable: Pageable
): ResponseEntity<Slice<OrderResponse>> {
val orderPages: Slice<OrderResponse> = orderUserService.getAllOrderSlicePaging(pageable)
return ResponseEntity.ok(orderPages)
}

@Operation(summary = "주문 생성", description = "단일 주문을 생성한다.")
@ApiResponses(
Expand All @@ -48,11 +73,35 @@ class OrderUserController(
)
@PostMapping
fun saveOrder(@RequestBody @Validated orderRequestWrapper: OrderRequestWrapper): ResponseEntity<SaveOrderResponse> {
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<SaveResponseDTO> {
val orderDetailId = orderUserService.addOrderDetail(addOrderDetailRequest)
val saveResponseDTO = SaveResponseDTO(orderDetailId, HttpStatus.OK.value(), "주문상세가 정상적으로 생성되었습니다.")
return ResponseEntity.ok(saveResponseDTO)
}

@Operation(summary = "구매자 구매 확정", description = "구매자가 주문을 구매확정하면, 주문상태가 '구매확정'으로 변경된다(단, 주문상태가 '배송완료'일 때만 가능).")
@ApiResponses(
value = [
Expand All @@ -72,7 +121,7 @@ class OrderUserController(
)
@PatchMapping("{orderId}/complete")
fun confirmOrder(@PathVariable orderId: String): ResponseEntity<MessageDTO> {
orderService.completeOrder(orderId)
orderUserService.completeOrder(orderId)
val messageDTO = MessageDTO(HttpStatus.OK.value(), "주문이 정상적으로 구매 확정 되었습니다.")
return ResponseEntity.ok(messageDTO)
}
Expand All @@ -99,7 +148,7 @@ class OrderUserController(
)
@PatchMapping("{orderId}/cancel")
fun cancelOrder(@PathVariable orderId: String): ResponseEntity<MessageDTO> {
orderService.cancelOrder(orderId)
orderUserService.cancelOrder(orderId)
val messageDTO = MessageDTO(HttpStatus.OK.value(), "주문이 정상적으로 취소되었습니다.")
return ResponseEntity.ok(messageDTO)
}
Expand All @@ -119,7 +168,7 @@ class OrderUserController(
@Operation(summary = "주문 삭제", description = "주문 삭제시간을 현재시간으로 업데이트 한다.")
@DeleteMapping("{orderId}")
fun deleteOrder(@PathVariable orderId: String): ResponseEntity<MessageDTO> {
orderService.updateDeleteAt(orderId)
orderUserService.updateDeleteAt(orderId)
val messageDTO = MessageDTO(HttpStatus.OK.value(), "주문이 정상적으로 삭제되었습니다.")
return ResponseEntity.ok(messageDTO)
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class OrderResponse(

val totalPrice: TotalPrice,

var orderDetailList: List<OrderDetailDTO> = ArrayList<OrderDetailDTO>(),
var orderDetailList: List<OrderDetailDTO> = arrayListOf(),
) {

fun updateOrderDetailList(orderDetailDTOList: List<OrderDetailDTO>) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,12 @@
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

interface OrderRepository : JpaRepository<Order, String> {
@Query("SELECT o FROM orders o WHERE o.status = 'CONFIRMED' AND o.deletedAt is null")
fun findConfirmedOrders(): List<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)

fun findByOrderIdAndDeletedAtIsNull(orderId: String): Order?

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