diff --git a/src/main/kotlin/com/psr/psr/cs/service/CsService.kt b/src/main/kotlin/com/psr/psr/cs/service/CsService.kt index 6ec23c6..e9ae1b6 100644 --- a/src/main/kotlin/com/psr/psr/cs/service/CsService.kt +++ b/src/main/kotlin/com/psr/psr/cs/service/CsService.kt @@ -8,7 +8,7 @@ import com.psr.psr.cs.dto.assembler.CsAssembler import com.psr.psr.cs.entity.FaqType import com.psr.psr.cs.repository.FaqRepository import com.psr.psr.cs.repository.NoticeRepository -import com.psr.psr.global.Constant.USER_STATUS.USER_STATUS.ACTIVE_STATUS +import com.psr.psr.global.Constant.UserStatus.UserStatus.ACTIVE_STATUS import com.psr.psr.global.exception.BaseException import com.psr.psr.global.exception.BaseResponseCode import org.springframework.stereotype.Service diff --git a/src/main/kotlin/com/psr/psr/global/Constant.kt b/src/main/kotlin/com/psr/psr/global/Constant.kt index 3734600..7128186 100644 --- a/src/main/kotlin/com/psr/psr/global/Constant.kt +++ b/src/main/kotlin/com/psr/psr/global/Constant.kt @@ -7,18 +7,25 @@ class Constant { const val BEARER_PREFIX: String = "Bearer " } } - class USER_STATUS { - companion object USER_STATUS { + class UserStatus { + companion object UserStatus { const val LOGOUT = "logout" const val ACTIVE_STATUS = "active" const val INACTIVE_STATUS = "inactive" } } - class USER_EID{ - companion object USER_EID{ + class UserEID{ + companion object UserEID{ const val EID_URL = "https://api.odcloud.kr/api/nts-businessman/v1/validate?serviceKey=" const val PAY_STATUS = "01" } } + + class OrderType{ + companion object OrderType{ + const val SELL = "sell" + const val ORDER = "order" + } + } } \ No newline at end of file diff --git a/src/main/kotlin/com/psr/psr/global/exception/BaseResponseCode.kt b/src/main/kotlin/com/psr/psr/global/exception/BaseResponseCode.kt index 982656f..594d60d 100644 --- a/src/main/kotlin/com/psr/psr/global/exception/BaseResponseCode.kt +++ b/src/main/kotlin/com/psr/psr/global/exception/BaseResponseCode.kt @@ -46,6 +46,8 @@ enum class BaseResponseCode(status: HttpStatus, message: String) { // order NOT_FOUND_ORDER(HttpStatus.NOT_FOUND, "해당 요청을 찾을 수 없습니다."), + INVALID_ORDER_STATUS(HttpStatus.BAD_REQUEST, "올바르지 않은 요청 상태입니다."), + INVALID_ORDER_TYPE(HttpStatus.BAD_REQUEST, "올바르지 않은 요청 타입입니다."), // product NOT_FOUND_PRODUCT(HttpStatus.NOT_FOUND, "해당 상품을 찾을 수 없습니다."); diff --git a/src/main/kotlin/com/psr/psr/global/jwt/UserDetailsServiceImpl.kt b/src/main/kotlin/com/psr/psr/global/jwt/UserDetailsServiceImpl.kt index c923030..759e1c7 100644 --- a/src/main/kotlin/com/psr/psr/global/jwt/UserDetailsServiceImpl.kt +++ b/src/main/kotlin/com/psr/psr/global/jwt/UserDetailsServiceImpl.kt @@ -1,15 +1,12 @@ package com.psr.psr.global.jwt -import com.psr.psr.global.Constant.USER_STATUS.USER_STATUS.ACTIVE_STATUS +import com.psr.psr.global.Constant.UserStatus.UserStatus.ACTIVE_STATUS import com.psr.psr.global.exception.BaseException -import com.psr.psr.global.exception.BaseResponseCode import com.psr.psr.global.exception.BaseResponseCode.NOT_FOUND_USER import com.psr.psr.user.entity.User import com.psr.psr.user.repository.UserRepository -import org.springframework.data.repository.findByIdOrNull import org.springframework.security.core.userdetails.UserDetails import org.springframework.security.core.userdetails.UserDetailsService -import org.springframework.security.core.userdetails.UsernameNotFoundException import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional diff --git a/src/main/kotlin/com/psr/psr/inquiry/service/InquiryService.kt b/src/main/kotlin/com/psr/psr/inquiry/service/InquiryService.kt index e30298c..52f266e 100644 --- a/src/main/kotlin/com/psr/psr/inquiry/service/InquiryService.kt +++ b/src/main/kotlin/com/psr/psr/inquiry/service/InquiryService.kt @@ -1,6 +1,6 @@ package com.psr.psr.inquiry.service -import com.psr.psr.global.Constant.USER_STATUS.USER_STATUS.ACTIVE_STATUS +import com.psr.psr.global.Constant.UserStatus.UserStatus.ACTIVE_STATUS import com.psr.psr.global.exception.BaseException import com.psr.psr.global.exception.BaseResponseCode import com.psr.psr.inquiry.dto.* @@ -13,8 +13,8 @@ import org.springframework.stereotype.Service @Service class InquiryService( - private val inquiryRepository: InquiryRepository, - private val inquiryAssembler: InquiryAssembler + private val inquiryRepository: InquiryRepository, + private val inquiryAssembler: InquiryAssembler ) { // 문의 등록 fun makeInquiry(user: User, inquiryReq: InquiryReq) { @@ -31,12 +31,13 @@ class InquiryService( // 문의 목록 조회 fun getInquiryList(user: User, status: String): InquiryListRes { val inquiryStatus: InquiryStatus = InquiryStatus.findByName(status) - val inquiries: List = - (if (user.type == Type.MANAGER) - inquiryRepository.findByInquiryStatusAndStatus(inquiryStatus, ACTIVE_STATUS) - else - inquiryRepository.findByUserAndInquiryStatusAndStatus(user, inquiryStatus, ACTIVE_STATUS)) - .map { inquiry: Inquiry -> inquiryAssembler.toPrepareListDto(inquiry) } + val inquiries: List = ( + if (user.type == Type.MANAGER) + inquiryRepository.findByInquiryStatusAndStatus(inquiryStatus, ACTIVE_STATUS) + else + inquiryRepository.findByUserAndInquiryStatusAndStatus(user, inquiryStatus, ACTIVE_STATUS) + ) + .map { inquiry: Inquiry -> inquiryAssembler.toPrepareListDto(inquiry) } return inquiryAssembler.toListDto(inquiries) } diff --git a/src/main/kotlin/com/psr/psr/order/controller/OrderController.kt b/src/main/kotlin/com/psr/psr/order/controller/OrderController.kt index a9727d2..81f6af2 100644 --- a/src/main/kotlin/com/psr/psr/order/controller/OrderController.kt +++ b/src/main/kotlin/com/psr/psr/order/controller/OrderController.kt @@ -1,7 +1,11 @@ package com.psr.psr.order.controller +import com.psr.psr.global.Constant.OrderType.OrderType.ORDER +import com.psr.psr.global.Constant.OrderType.OrderType.SELL import com.psr.psr.global.dto.BaseResponse +import com.psr.psr.global.exception.BaseResponseCode import com.psr.psr.global.jwt.UserAccount +import com.psr.psr.order.dto.OrderListRes import com.psr.psr.order.dto.OrderReq import com.psr.psr.order.dto.OrderRes import com.psr.psr.order.service.OrderService @@ -12,18 +16,25 @@ import org.springframework.web.bind.annotation.* @RestController @RequestMapping("/orders") class OrderController( - private val orderService: OrderService + private val orderService: OrderService ) { - // 요청하기 - @PostMapping - fun makeOrder (@AuthenticationPrincipal userAccount: UserAccount, @RequestBody @Valid orderReq: OrderReq) : BaseResponse { - if (orderReq.websiteUrl.isNullOrBlank()) orderReq.websiteUrl = null - return BaseResponse(orderService.makeOrder(userAccount.getUser(), orderReq)) - } + // 요청하기 + @PostMapping + fun makeOrder(@AuthenticationPrincipal userAccount: UserAccount, @RequestBody @Valid orderReq: OrderReq): BaseResponse { + if (orderReq.websiteUrl.isNullOrBlank()) orderReq.websiteUrl = null + return BaseResponse(orderService.makeOrder(userAccount.getUser(), orderReq)) + } - // 요청 상세 조회 - @GetMapping("/{orderId}") - fun getOrderDetail (@AuthenticationPrincipal userAccount: UserAccount, @PathVariable orderId: Long) : BaseResponse { - return BaseResponse(orderService.getOrderDetail(userAccount.getUser(), orderId)) - } + // 요청 상세 조회 + @GetMapping("/{orderId}") + fun getOrderDetail(@AuthenticationPrincipal userAccount: UserAccount,@PathVariable orderId: Long): BaseResponse { + return BaseResponse(orderService.getOrderDetail(userAccount.getUser(), orderId)) + } + + // 요청 목록 조회 + @GetMapping + fun getOrderList(@AuthenticationPrincipal userAccount: UserAccount, type: String, status: String): BaseResponse { + if (type !in listOf(SELL, ORDER)) return BaseResponse(BaseResponseCode.INVALID_ORDER_TYPE) + return BaseResponse(orderService.getOrderList(userAccount.getUser(), type, status)) + } } \ No newline at end of file diff --git a/src/main/kotlin/com/psr/psr/order/dto/OrderAssembler.kt b/src/main/kotlin/com/psr/psr/order/dto/OrderAssembler.kt index c1a1ced..d585c7b 100644 --- a/src/main/kotlin/com/psr/psr/order/dto/OrderAssembler.kt +++ b/src/main/kotlin/com/psr/psr/order/dto/OrderAssembler.kt @@ -1,5 +1,6 @@ package com.psr.psr.order.dto +import com.psr.psr.global.Constant.OrderType.OrderType.SELL import com.psr.psr.order.entity.Order import com.psr.psr.product.entity.product.Product import com.psr.psr.user.entity.User @@ -22,7 +23,7 @@ class OrderAssembler { fun toOrderResDTO(order: Order, isSeller: Boolean): OrderRes { return OrderRes( isSeller = isSeller, - status = order.orderStatus.value, + status = order.orderStatus.statusName, orderUserId = order.user.id!!, orderDate = order.createdAt.format(DateTimeFormatter.ISO_DATE), productId = order.product.id, @@ -33,4 +34,23 @@ class OrderAssembler { description = order.description ) } + + fun toPrepareListDto(order: Order, type: String): OrderListComp { + val userName: String = + if (type == SELL) order.ordererName + else order.product.user.nickname + return OrderListComp( + orderId = order.id!!, + orderDate = order.createdAt.format(DateTimeFormatter.ISO_DATE), + userName = userName, + productId = order.product.id, + productName = order.product.name, + isReviewed = order.isReviewed + ) + } + + fun toListDto(orderList: List): OrderListRes { + if (orderList.isEmpty()) return OrderListRes(null) + return OrderListRes(orderList) + } } \ No newline at end of file diff --git a/src/main/kotlin/com/psr/psr/order/dto/OrderListComp.kt b/src/main/kotlin/com/psr/psr/order/dto/OrderListComp.kt new file mode 100644 index 0000000..9a0a20a --- /dev/null +++ b/src/main/kotlin/com/psr/psr/order/dto/OrderListComp.kt @@ -0,0 +1,10 @@ +package com.psr.psr.order.dto + +data class OrderListComp ( + val orderId: Long, + val orderDate: String, + val userName: String, + val productId: Long, + val productName: String, + val isReviewed: Boolean +) \ No newline at end of file diff --git a/src/main/kotlin/com/psr/psr/order/dto/OrderListRes.kt b/src/main/kotlin/com/psr/psr/order/dto/OrderListRes.kt new file mode 100644 index 0000000..88b5c19 --- /dev/null +++ b/src/main/kotlin/com/psr/psr/order/dto/OrderListRes.kt @@ -0,0 +1,5 @@ +package com.psr.psr.order.dto + +data class OrderListRes ( + val orders: List? +) \ No newline at end of file diff --git a/src/main/kotlin/com/psr/psr/order/entity/Order.kt b/src/main/kotlin/com/psr/psr/order/entity/Order.kt index e5d7db6..b5b79cb 100644 --- a/src/main/kotlin/com/psr/psr/order/entity/Order.kt +++ b/src/main/kotlin/com/psr/psr/order/entity/Order.kt @@ -9,31 +9,34 @@ import org.jetbrains.annotations.NotNull @Entity @Table(name = "orders") data class Order( - @Id @GeneratedValue(strategy = GenerationType.IDENTITY) - var id: Long? = null, + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + var id: Long? = null, - @ManyToOne - @JoinColumn(nullable = false, name = "product_id") - var product: Product, + @ManyToOne + @JoinColumn(nullable = false, name = "product_id") + var product: Product, - @ManyToOne - @JoinColumn(nullable = false, name = "user_id") - var user: User, + @ManyToOne + @JoinColumn(nullable = false, name = "user_id") + var user: User, - @NotNull - @Column(length = 100) - var ordererName: String, + @NotNull + @Column(length = 100) + var ordererName: String, - var websiteUrl: String?, + var websiteUrl: String?, - @NotNull - @Enumerated(EnumType.STRING) - var orderStatus: OrderStatus = OrderStatus.ORDER_WAITING, + @NotNull + @Enumerated(EnumType.STRING) + var orderStatus: OrderStatus = OrderStatus.ORDER_WAITING, - @NotNull - var inquiry: String, + @NotNull + var inquiry: String, - @NotNull - var description: String + @NotNull + var description: String, -): BaseEntity() + @NotNull + var isReviewed: Boolean = false + +) : BaseEntity() diff --git a/src/main/kotlin/com/psr/psr/order/entity/OrderStatus.kt b/src/main/kotlin/com/psr/psr/order/entity/OrderStatus.kt index bb5daa9..aac58fa 100644 --- a/src/main/kotlin/com/psr/psr/order/entity/OrderStatus.kt +++ b/src/main/kotlin/com/psr/psr/order/entity/OrderStatus.kt @@ -1,8 +1,18 @@ package com.psr.psr.order.entity -enum class OrderStatus(val value: String) { +import com.psr.psr.global.exception.BaseException +import com.psr.psr.global.exception.BaseResponseCode + +enum class OrderStatus(val statusName: String) { ORDER_WAITING("요청대기"), PROGRESSING("진행중"), COMPLETED("진행완료"), - CANCELED("요청취소") + CANCELED("요청취소"); + + companion object { + fun findByName(statusName: String): OrderStatus { + return OrderStatus.values().find { it.statusName == statusName } + ?: throw BaseException(BaseResponseCode.INVALID_ORDER_STATUS) + } + } } diff --git a/src/main/kotlin/com/psr/psr/order/repository/OrderRepository.kt b/src/main/kotlin/com/psr/psr/order/repository/OrderRepository.kt index 44a2d98..c897b6e 100644 --- a/src/main/kotlin/com/psr/psr/order/repository/OrderRepository.kt +++ b/src/main/kotlin/com/psr/psr/order/repository/OrderRepository.kt @@ -1,10 +1,14 @@ package com.psr.psr.order.repository import com.psr.psr.order.entity.Order +import com.psr.psr.order.entity.OrderStatus +import com.psr.psr.user.entity.User import org.springframework.data.jpa.repository.JpaRepository import org.springframework.stereotype.Repository @Repository interface OrderRepository: JpaRepository { fun findByIdAndStatus(orderId: Long, status: String): Order? + fun findByUserAndOrderStatusAndStatus(orderer: User, orderStatus: OrderStatus, status: String): List + fun findByProductUserAndOrderStatusAndStatus(seller: User, orderStatus: OrderStatus, status: String): List } \ No newline at end of file diff --git a/src/main/kotlin/com/psr/psr/order/service/OrderService.kt b/src/main/kotlin/com/psr/psr/order/service/OrderService.kt index d553e0b..ab5359e 100644 --- a/src/main/kotlin/com/psr/psr/order/service/OrderService.kt +++ b/src/main/kotlin/com/psr/psr/order/service/OrderService.kt @@ -1,12 +1,12 @@ package com.psr.psr.order.service -import com.psr.psr.global.Constant.USER_STATUS.USER_STATUS.ACTIVE_STATUS +import com.psr.psr.global.Constant.OrderType.OrderType.SELL +import com.psr.psr.global.Constant.UserStatus.UserStatus.ACTIVE_STATUS import com.psr.psr.global.exception.BaseException import com.psr.psr.global.exception.BaseResponseCode -import com.psr.psr.order.dto.OrderAssembler -import com.psr.psr.order.dto.OrderReq -import com.psr.psr.order.dto.OrderRes +import com.psr.psr.order.dto.* import com.psr.psr.order.entity.Order +import com.psr.psr.order.entity.OrderStatus import com.psr.psr.order.repository.OrderRepository import com.psr.psr.product.entity.product.Product import com.psr.psr.product.repository.product.ProductRepository @@ -15,23 +15,37 @@ import org.springframework.stereotype.Service @Service class OrderService( - private val orderRepository: OrderRepository, - private val productRepository: ProductRepository, - private val orderAssembler: OrderAssembler + private val orderRepository: OrderRepository, + private val productRepository: ProductRepository, + private val orderAssembler: OrderAssembler ) { - // 요청하기 - fun makeOrder(user: User, orderReq: OrderReq) { - val product: Product = productRepository.findByIdAndStatus(orderReq.productId, ACTIVE_STATUS) - ?: throw BaseException(BaseResponseCode.NOT_FOUND_PRODUCT) - orderRepository.save(orderAssembler.toEntity(user, orderReq, product)) - } + // 요청하기 + fun makeOrder(user: User, orderReq: OrderReq) { + val product: Product = productRepository.findByIdAndStatus(orderReq.productId, ACTIVE_STATUS) + ?: throw BaseException(BaseResponseCode.NOT_FOUND_PRODUCT) + orderRepository.save(orderAssembler.toEntity(user, orderReq, product)) + } - // 요청 상세 조회 - fun getOrderDetail(user: User, orderId: Long): OrderRes { - val order: Order = orderRepository.findByIdAndStatus(orderId, ACTIVE_STATUS) - ?: throw BaseException(BaseResponseCode.NOT_FOUND_ORDER) - val isSeller = order.product.user.id == user.id - if (order.user.id != user.id && !isSeller) throw BaseException(BaseResponseCode.NO_PERMISSION) - return orderAssembler.toOrderResDTO(order, isSeller) - } + // 요청 상세 조회 + fun getOrderDetail(user: User, orderId: Long): OrderRes { + val order: Order = orderRepository.findByIdAndStatus(orderId, ACTIVE_STATUS) + ?: throw BaseException(BaseResponseCode.NOT_FOUND_ORDER) + val isSeller = order.product.user.id == user.id + if (order.user.id != user.id && !isSeller) throw BaseException(BaseResponseCode.NO_PERMISSION) + return orderAssembler.toOrderResDTO(order, isSeller) + } + + // 요청 목록 조회 + fun getOrderList(user: User, type: String, status: String): OrderListRes { + val orderStatus: OrderStatus = OrderStatus.findByName(status) + val orders: List = ( + if (type == SELL) + orderRepository.findByProductUserAndOrderStatusAndStatus(user, orderStatus, ACTIVE_STATUS) + else + orderRepository.findByUserAndOrderStatusAndStatus(user, orderStatus, ACTIVE_STATUS) + ) + .map { order: Order -> orderAssembler.toPrepareListDto(order, type) } + + return orderAssembler.toListDto(orders) + } } \ No newline at end of file diff --git a/src/main/kotlin/com/psr/psr/product/service/ProductService.kt b/src/main/kotlin/com/psr/psr/product/service/ProductService.kt index 4c3f053..555eb2d 100644 --- a/src/main/kotlin/com/psr/psr/product/service/ProductService.kt +++ b/src/main/kotlin/com/psr/psr/product/service/ProductService.kt @@ -1,6 +1,6 @@ package com.psr.psr.product.service -import com.psr.psr.global.Constant.USER_STATUS.USER_STATUS.ACTIVE_STATUS +import com.psr.psr.global.Constant.UserStatus.UserStatus.ACTIVE_STATUS import com.psr.psr.global.exception.BaseException import com.psr.psr.global.exception.BaseResponseCode import com.psr.psr.product.dto.assembler.ProductAssembler diff --git a/src/main/kotlin/com/psr/psr/user/controller/UserController.kt b/src/main/kotlin/com/psr/psr/user/controller/UserController.kt index c4f4957..c704286 100644 --- a/src/main/kotlin/com/psr/psr/user/controller/UserController.kt +++ b/src/main/kotlin/com/psr/psr/user/controller/UserController.kt @@ -1,7 +1,7 @@ package com.psr.psr.user.controller -import com.psr.psr.global.Constant.USER_STATUS.USER_STATUS.INACTIVE_STATUS -import com.psr.psr.global.Constant.USER_STATUS.USER_STATUS.LOGOUT +import com.psr.psr.global.Constant.UserStatus.UserStatus.INACTIVE_STATUS +import com.psr.psr.global.Constant.UserStatus.UserStatus.LOGOUT import com.psr.psr.global.dto.BaseResponse import com.psr.psr.global.exception.BaseResponseCode import com.psr.psr.global.jwt.UserAccount diff --git a/src/main/kotlin/com/psr/psr/user/service/UserService.kt b/src/main/kotlin/com/psr/psr/user/service/UserService.kt index d387365..913842c 100644 --- a/src/main/kotlin/com/psr/psr/user/service/UserService.kt +++ b/src/main/kotlin/com/psr/psr/user/service/UserService.kt @@ -2,9 +2,9 @@ package com.psr.psr.user.service import com.fasterxml.jackson.databind.ObjectMapper import com.psr.psr.global.Constant -import com.psr.psr.global.Constant.USER_EID.USER_EID.EID_URL -import com.psr.psr.global.Constant.USER_EID.USER_EID.PAY_STATUS -import com.psr.psr.global.Constant.USER_STATUS.USER_STATUS.ACTIVE_STATUS +import com.psr.psr.global.Constant.UserEID.UserEID.EID_URL +import com.psr.psr.global.Constant.UserEID.UserEID.PAY_STATUS +import com.psr.psr.global.Constant.UserStatus.UserStatus.ACTIVE_STATUS import com.psr.psr.global.exception.BaseException import com.psr.psr.global.exception.BaseResponseCode.* import com.psr.psr.global.jwt.dto.TokenDto