Skip to content

Commit

Permalink
feat: 마이페이지-내 주문 목록 조회 API 카테고리 정보 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
cofls6581 committed Sep 27, 2023
1 parent d031b7c commit 4f0c4d1
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.higoods.api.order.dto.response

import com.higoods.domain.item.domain.ProductCategory
import com.higoods.domain.order.domain.OrderState
import com.higoods.domain.project.domain.Project

Expand All @@ -8,20 +9,20 @@ data class OrderProjectsResponse(
val title: String,
val titleImage: String,
val subTitle: String,
val orderState: OrderState
// TODO: 프로젝트단 관련 작업 완료되면 추가 작업 필요
// val category: String,
val orderState: OrderState,
val category: ProductCategory
// TODO: 프로젝트 상태 도메인 개발 후 추가 작업 필요
// val projectStatus: String
) {
companion object {
fun of(orderId: Long, orderState: OrderState, project: Project): OrderProjectsResponse {
fun of(orderId: Long, orderState: OrderState, project: Project, category: ProductCategory): OrderProjectsResponse {
return OrderProjectsResponse(
orderId = orderId,
title = project.title,
titleImage = project.titleImage,
subTitle = project.subTitle,
orderState = orderState
orderState = orderState,
category = category
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class OrderCreateUseCase(
fun execute(projectId: Long, orderCreateRequest: OrderCreateRequest): OrderResponse {
val currentUserId = SecurityUtils.currentUserId
val project = projectAdapter.queryById(projectId)
// TODO: 리스폰스에 주문번호 업데이트 되는지 확인 필요
val newOrder = orderDomainService.createOrder(orderCreateRequest.toOrder(project.id, currentUserId))
val newOrderOptions = orderDomainService.createOrderOptions(orderCreateRequest.toOrderOptionItems(newOrder.id))
var newOrderAnswers: List<OrderAnswer>? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.higoods.api.order.dto.response.OrderAdminResponse
import com.higoods.api.order.dto.response.OrderProjectsResponse
import com.higoods.api.order.dto.response.OrderResponse
import com.higoods.common.annotation.UseCase
import com.higoods.domain.item.adapter.ItemAdapter
import com.higoods.domain.order.adapter.OrderAdapter
import com.higoods.domain.order.domain.OrderState
import com.higoods.domain.order.exception.OrderNotUserException
Expand All @@ -17,15 +18,17 @@ import org.springframework.transaction.annotation.Transactional
@UseCase
class OrderReadUseCase(
private val orderAdapter: OrderAdapter,
private val projectAdapter: ProjectAdapter
private val projectAdapter: ProjectAdapter,
private val itemAdapter: ItemAdapter
) {
@Transactional(readOnly = true)
fun findAll(): List<OrderProjectsResponse> {
val orders = orderAdapter.findAll(SecurityUtils.currentUserId)
if (orders.isNullOrEmpty()) return emptyList()
return orders.map { order ->
val project = projectAdapter.queryById(order.projectId)
OrderProjectsResponse.of(order.id, order.orderState, project)
val item = itemAdapter.queryItemByProjectId(project.id)
OrderProjectsResponse.of(order.id, order.orderState, project, item.category)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.higoods.api.order.dto.response.OrderProjectsResponse
import com.higoods.api.order.dto.response.OrderResponse
import com.higoods.api.order.usecase.OrderCreateUseCase
import com.higoods.api.order.usecase.OrderReadUseCase
import com.higoods.domain.item.domain.ProductCategory
import com.higoods.domain.order.domain.AnswerType
import com.higoods.domain.order.domain.OrderState
import com.higoods.domain.order.domain.ReceiveType
Expand Down Expand Up @@ -137,7 +138,8 @@ class OrderControllerTest : BaseControllerTest() {
title = "제목",
titleImage = "image",
subTitle = "부제목",
orderState = OrderState.PENDING
orderState = OrderState.PENDING,
category = ProductCategory.CLOTHES
)
)

Expand All @@ -163,7 +165,8 @@ class OrderControllerTest : BaseControllerTest() {
fieldWithPath("[].title").type(JsonFieldType.STRING).description("제목"),
fieldWithPath("[].titleImage").type(JsonFieldType.STRING).description("이미지"),
fieldWithPath("[].subTitle").type(JsonFieldType.STRING).description("부제목"),
fieldWithPath("[].orderState").type(JsonFieldType.STRING).description("주문 상태 이넘 PENDING,APPROVAL,CANCELED")
fieldWithPath("[].orderState").type(JsonFieldType.STRING).description("주문 상태 이넘 PENDING,APPROVAL,CANCELED"),
fieldWithPath("[].category").type(JsonFieldType.STRING).description("카테고리 이넘 CLOTHES, OFFICE_SUPPLIES, STUFF, ETC")
)
.responseSchema(Schema.schema("마이페이지-내 주문 목록 조회 Res"))
.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@ class ItemAdapter(
fun save(item: Item): Item {
return itemRepository.save(item)
}

fun queryItemByProjectId(projectId: Long): Item {
return itemRepository.findByProjectId(projectId) ?: run { throw ItemNotFoundException.EXCEPTION }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ package com.higoods.domain.item.repository
import com.higoods.domain.item.domain.Item
import org.springframework.data.jpa.repository.JpaRepository

interface ItemRepository : JpaRepository<Item, Long>
interface ItemRepository : JpaRepository<Item, Long> {
fun findByProjectId(projectId: Long): Item?
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import javax.persistence.Entity
import javax.persistence.Table

@Entity
@Table(name = "tbl_order_item")
@Table(name = "tbl_order_option_item")
class OrderOptionItem(

val orderId: Long, // 주문 아이디
Expand Down

0 comments on commit 4f0c4d1

Please sign in to comment.