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 eb91f6e commit d031b7c
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,12 @@ class DistributionAdminController(
): DistributionStateResponse {
return distributionUpdateUseCase.updateState(distributionId, isReceived)
}

// [어드민] 현장 배부 목록 엑셀 데이터 추출
@GetMapping("/{project_id}/excels")
fun findAll(
@PathVariable("project_id") projectId: Long
): List<DistributionResponse> {
return distributionReadUseCase.findAllExcel(projectId)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,20 @@ class DistributionReadUseCase(
DistributionResponse.of(order = order, distribution = distribution)
}
}

fun findAllExcel(projectId: Long): List<DistributionResponse> {
val project = projectAdapter.queryById(projectId)
if (project.userId != SecurityUtils.currentUserId) {
throw ProjectNotHostException.EXCEPTION
}

val findAll = distributionAdapter.findAll(projectId)
val orderIds = findAll.map { distribution -> distribution.orderId }.toList()
val orders = orderAdapter.findAllById(orderIds)

return findAll.map { distribution ->
val order = orders.find { it.id == distribution.orderId } ?: throw OrderNotFoundException.EXCEPTION
DistributionResponse.of(order = order, distribution = distribution)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,36 @@ class DistributionAdminControllerTest : BaseControllerTest() {
)
)
}

test("현장 배부 목록 엑셀 데이터 추출") {

every { distributionReadUseCase.findAllExcel(any()) } returns listOf(distributionResponse())

get("/v1/admins/distributions/{project_id}/excels", pathParams = arrayOf("1")) {
contentType(MediaType.APPLICATION_JSON)
accept(MediaType.APPLICATION_JSON)
authorizationHeader(1)
}
.isStatus(200)
.makeDocument(
DocumentInfo(
identifier = "[어드민] 현장 배부 목록 엑셀 데이터 추출",
tag = OpenApiTag.DISTRIBUTION,
description = "[어드민] 현현장 배부 목록 엑셀 데이터 추출 API, 엑셀용 현장 배부 전체 데이터를 조회합니다."
),
pathParameters(
"project_id" type NUMBER means "프로젝트 아이디"
),
responseFields(
"[].distributionId" type NUMBER means "배부 id",
"[].orderNo" type STRING means "주문번호",
"[].name" type STRING means "이름",
"[].orderDate" type STRING means "주문 일시",
"[].phoneNumber" type STRING means "전화번호",
"[].receiveDate" type STRING means "수령한 날짜",
"[].distributionType" type STRING means "상태 enum NOT_RECEIVED, RECEIVED"
)
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,8 @@ class DistributionAdapter(
fun queryById(distributionId: Long): Distribution {
return distributionRepository.findByIdOrNull(distributionId) ?: throw DistributionNotFoundException.EXCEPTION
}

fun findAll(projectId: Long): List<Distribution> {
return distributionRepository.findAllByProjectId(projectId)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ import org.springframework.data.jpa.repository.JpaRepository

interface DistributionRepository : JpaRepository<Distribution, Long> {
fun deleteByOrderId(orderId: Long)

fun findAllByProjectId(projectId: Long): List<Distribution>
}

0 comments on commit d031b7c

Please sign in to comment.