diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index f2a6d9d..2f9d634 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -2,32 +2,15 @@
-
-
-
+
+
+
-
-
-
-
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
+
@@ -39,9 +22,9 @@
+
-
@@ -67,7 +50,7 @@
-
+
@@ -102,7 +85,8 @@
-
+
+
@@ -118,10 +102,14 @@
-
+
-
+
+
+
+
+
@@ -130,49 +118,49 @@
-
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
+
-
+
-
+
\ No newline at end of file
diff --git a/src/main/kotlin/com/chantha/jdbc/controller/CustomerController.kt b/src/main/kotlin/com/chantha/jdbc/controller/CustomerController.kt
index db576c3..45328ef 100644
--- a/src/main/kotlin/com/chantha/jdbc/controller/CustomerController.kt
+++ b/src/main/kotlin/com/chantha/jdbc/controller/CustomerController.kt
@@ -2,6 +2,8 @@ package com.chantha.jdbc.controller
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.repo.CustomerRepo
import com.chantha.jdbc.jpa.service.customer.CustomerService
import com.chantha.jdbc.jpa.view.ViewsInvoice
import org.apache.tomcat.util.json.JSONParser
@@ -14,8 +16,9 @@ import org.springframework.web.bind.annotation.RestController
@RestController
class CustomerController @Autowired constructor(private val customerService: CustomerService) {
+
@GetMapping("/customer")
- fun customer():List{
- return customerService.findAll().toList()
+ fun customer():List{
+ return customerService.fetchAllCustomerOrder()
}
}
\ No newline at end of file
diff --git a/src/main/kotlin/com/chantha/jdbc/jpa/model/view/CustomerOrderView.java b/src/main/kotlin/com/chantha/jdbc/jpa/model/view/CustomerOrderView.java
new file mode 100644
index 0000000..f40c8a4
--- /dev/null
+++ b/src/main/kotlin/com/chantha/jdbc/jpa/model/view/CustomerOrderView.java
@@ -0,0 +1,49 @@
+package com.chantha.jdbc.jpa.model.view;
+
+import com.chantha.jdbc.jpa.model.Gender;
+import com.chantha.jdbc.jpa.model.Order;
+
+import java.util.Date;
+import java.util.List;
+
+public class CustomerOrderView {
+ public Long getCusID() {
+ return cusID;
+ }
+
+ public void setCusID(Long cusID) {
+ this.cusID = cusID;
+ }
+
+ public String getCusName() {
+ return cusName;
+ }
+
+ public void setCusName(String cusName) {
+ this.cusName = cusName;
+ }
+
+ public Gender getGender() {
+ return gender;
+ }
+
+ public void setGender(Gender gender) {
+ this.gender = gender;
+ }
+
+ public List getOrderList() {
+ return orderList;
+ }
+
+ public void setOrderList(List orderList) {
+ this.orderList = orderList;
+ }
+
+ private Long cusID;
+ private String cusName;
+ private Gender gender;
+
+ private List orderList;
+
+
+}
diff --git a/src/main/kotlin/com/chantha/jdbc/jpa/model/view/OrderView.kt b/src/main/kotlin/com/chantha/jdbc/jpa/model/view/OrderView.kt
new file mode 100644
index 0000000..4dd0556
--- /dev/null
+++ b/src/main/kotlin/com/chantha/jdbc/jpa/model/view/OrderView.kt
@@ -0,0 +1,13 @@
+package com.chantha.jdbc.jpa.model.view
+
+import com.chantha.jdbc.utils.CustomDateSerializer
+import com.fasterxml.jackson.annotation.JsonFormat
+import com.fasterxml.jackson.databind.annotation.JsonSerialize
+import java.util.*
+
+open class OrderView{
+ var orderId:Long ?= 0
+ @JsonFormat(shape=JsonFormat.Shape.STRING, pattern="yyyy-MMM-dd HH:mm:ss ")
+ var orderDate:Date ? = Calendar.getInstance().time
+ var amount:Double ? = 0.0
+}
\ No newline at end of file
diff --git a/src/main/kotlin/com/chantha/jdbc/jpa/repo/CustomerRepo.java b/src/main/kotlin/com/chantha/jdbc/jpa/repo/CustomerRepo.java
index 236acac..fed4a2a 100644
--- a/src/main/kotlin/com/chantha/jdbc/jpa/repo/CustomerRepo.java
+++ b/src/main/kotlin/com/chantha/jdbc/jpa/repo/CustomerRepo.java
@@ -5,16 +5,7 @@ import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
public interface CustomerRepo extends CrudRepository {
- @Query(value = "SELECT *\n" +
- " FROM tb_order o\n" +
- " INNER JOIN order_detail od\n" +
- " ON (o.order_id=od.order_id)\n" +
- " INNER JOIN tb_customer c\n" +
- " ON (o.cus_id=c.id)\n" +
- " INNER JOIN product pro\n" +
- " ON (pro.product_id=od.product_id)\n" +
- "\n" +
- "\t\t",nativeQuery = true)
+ @Query(value ="SELECT * FROM tb_customer c INNER JOIN tb_order o ON (c.id=o.cus_id)",nativeQuery = true)
@Override
Iterable findAll();
}
diff --git a/src/main/kotlin/com/chantha/jdbc/jpa/service/customer/CustomerService.java b/src/main/kotlin/com/chantha/jdbc/jpa/service/customer/CustomerService.java
index 08aa06d..ba493d0 100644
--- a/src/main/kotlin/com/chantha/jdbc/jpa/service/customer/CustomerService.java
+++ b/src/main/kotlin/com/chantha/jdbc/jpa/service/customer/CustomerService.java
@@ -1,6 +1,12 @@
package com.chantha.jdbc.jpa.service.customer;
+import com.chantha.jdbc.jpa.model.view.CustomerOrderView;
import com.chantha.jdbc.jpa.repo.CustomerRepo;
+import org.springframework.stereotype.Service;
-public interface CustomerService extends CustomerRepo {
+import java.util.List;
+
+@Service
+public interface CustomerService {
+ List fetchAllCustomerOrder();
}
diff --git a/src/main/kotlin/com/chantha/jdbc/jpa/service/customer/CustomerServiceImpl.java b/src/main/kotlin/com/chantha/jdbc/jpa/service/customer/CustomerServiceImpl.java
deleted file mode 100644
index 6a05698..0000000
--- a/src/main/kotlin/com/chantha/jdbc/jpa/service/customer/CustomerServiceImpl.java
+++ /dev/null
@@ -1,62 +0,0 @@
-package com.chantha.jdbc.jpa.service.customer;
-
-import com.chantha.jdbc.jpa.model.Customer;
-
-import java.util.Optional;
-
-public class CustomerServiceImpl implements CustomerService {
- @Override
- public S save(S s) {
- return null;
- }
-
- @Override
- public Iterable saveAll(Iterable iterable) {
- return null;
- }
-
- @Override
- public Optional findById(Long aLong) {
- return Optional.empty();
- }
-
- @Override
- public boolean existsById(Long aLong) {
- return false;
- }
-
- @Override
- public Iterable findAll() {
- return null;
- }
-
- @Override
- public Iterable findAllById(Iterable iterable) {
- return null;
- }
-
- @Override
- public long count() {
- return 0;
- }
-
- @Override
- public void deleteById(Long aLong) {
-
- }
-
- @Override
- public void delete(Customer customer) {
-
- }
-
- @Override
- public void deleteAll(Iterable extends Customer> iterable) {
-
- }
-
- @Override
- public void deleteAll() {
-
- }
-}
diff --git a/src/main/kotlin/com/chantha/jdbc/jpa/service/customer/CustomerServiceImpl.kt b/src/main/kotlin/com/chantha/jdbc/jpa/service/customer/CustomerServiceImpl.kt
new file mode 100644
index 0000000..f3c6db3
--- /dev/null
+++ b/src/main/kotlin/com/chantha/jdbc/jpa/service/customer/CustomerServiceImpl.kt
@@ -0,0 +1,51 @@
+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 {
+ 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
+// }
+}
\ No newline at end of file
diff --git a/target/classes/com/chantha/jdbc/controller/CustomerController.class b/target/classes/com/chantha/jdbc/controller/CustomerController.class
index 029bd26..32f6bf1 100644
Binary files a/target/classes/com/chantha/jdbc/controller/CustomerController.class and b/target/classes/com/chantha/jdbc/controller/CustomerController.class differ
diff --git a/target/classes/com/chantha/jdbc/jpa/model/view/CustomerOrderView.class b/target/classes/com/chantha/jdbc/jpa/model/view/CustomerOrderView.class
new file mode 100644
index 0000000..435b332
Binary files /dev/null and b/target/classes/com/chantha/jdbc/jpa/model/view/CustomerOrderView.class differ
diff --git a/target/classes/com/chantha/jdbc/jpa/model/view/OrderView.class b/target/classes/com/chantha/jdbc/jpa/model/view/OrderView.class
new file mode 100644
index 0000000..92b0487
Binary files /dev/null and b/target/classes/com/chantha/jdbc/jpa/model/view/OrderView.class differ
diff --git a/target/classes/com/chantha/jdbc/jpa/repo/CustomerRepo.class b/target/classes/com/chantha/jdbc/jpa/repo/CustomerRepo.class
index b3a60a7..5e01a1c 100644
Binary files a/target/classes/com/chantha/jdbc/jpa/repo/CustomerRepo.class and b/target/classes/com/chantha/jdbc/jpa/repo/CustomerRepo.class differ
diff --git a/target/classes/com/chantha/jdbc/jpa/service/customer/CustomerService.class b/target/classes/com/chantha/jdbc/jpa/service/customer/CustomerService.class
index 826b6f5..95d5e92 100644
Binary files a/target/classes/com/chantha/jdbc/jpa/service/customer/CustomerService.class and b/target/classes/com/chantha/jdbc/jpa/service/customer/CustomerService.class differ
diff --git a/target/classes/com/chantha/jdbc/jpa/service/customer/CustomerServiceImpl.class b/target/classes/com/chantha/jdbc/jpa/service/customer/CustomerServiceImpl.class
index 88c7c17..8bc142f 100644
Binary files a/target/classes/com/chantha/jdbc/jpa/service/customer/CustomerServiceImpl.class and b/target/classes/com/chantha/jdbc/jpa/service/customer/CustomerServiceImpl.class differ