51 lines
1.7 KiB
Kotlin
51 lines
1.7 KiB
Kotlin
package com.chantha.jdbc.jpa.service.customer
|
|
|
|
|
|
import com.chantha.jdbc.jpa.model.Customer
|
|
import com.chantha.jdbc.jpa.model.Order
|
|
import com.chantha.jdbc.jpa.model.view.CustomerOrderView
|
|
import com.chantha.jdbc.jpa.model.view.OrderDetailView
|
|
import com.chantha.jdbc.jpa.model.view.OrderView
|
|
import com.chantha.jdbc.jpa.repo.CustomerRepo
|
|
import org.springframework.beans.factory.annotation.Autowired
|
|
import org.springframework.stereotype.Service
|
|
|
|
@Service
|
|
class CustomerServiceImpl @Autowired constructor(private val customerRepo: CustomerRepo) : CustomerService {
|
|
override fun fetchAllCustomerOrder(): List<CustomerOrderView> {
|
|
return customerRepo.findAll().map { toView(it) }
|
|
}
|
|
|
|
private fun toView(data:Customer):CustomerOrderView{
|
|
val view=CustomerOrderView()
|
|
view.cusID=data.id
|
|
view.cusName=data.cusName
|
|
view.gender=data.gender
|
|
view.orderList=data.orders.map { toCustomerOrderView(it) }
|
|
return view
|
|
}
|
|
|
|
private fun toCustomerOrderView(data:Order):OrderView{
|
|
val view=OrderView()
|
|
view.orderId=data.orderId
|
|
view.orderDate=data.orderDate
|
|
view.amount=data.amount
|
|
return view
|
|
}
|
|
|
|
// private fun toView(data: Product): ProductWithOrderDetail {
|
|
// val view = ProductWithOrderDetail()
|
|
// view.productId = data.productId
|
|
// view.productName = data.productName
|
|
// view.details = data.orderDetails.map { toOrderDetailView(it) }
|
|
// return view
|
|
// }
|
|
//
|
|
// private fun toOrderDetailView(data: OrderDetail): OrderDetailView {
|
|
// val view = OrderDetailView()
|
|
// view.orderDetailId = data.orderDetailId
|
|
// view.price = data.price
|
|
// view.qty = data.qty
|
|
// return view
|
|
// }
|
|
} |