diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 5bdc19a..15b2bba 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -2,14 +2,16 @@
-
+
+
+
+
-
-
-
+
+
-
+
@@ -21,9 +23,9 @@
-
+
@@ -49,7 +51,7 @@
-
+
@@ -86,7 +88,9 @@
-
+
+
+
@@ -102,65 +106,65 @@
-
+
-
+
-
+
-
+
-
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
+
-
+
-
+
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index d70d3ce..b9b4b07 100644
--- a/pom.xml
+++ b/pom.xml
@@ -39,6 +39,13 @@
42.2.12
+
+
+ org.springframework.boot
+ spring-boot-starter-security
+ 2.3.0.RELEASE
+
+
org.jetbrains.kotlin
kotlin-reflect
diff --git a/src/main/kotlin/com/chantha/jdbc/config/WebConfig.java b/src/main/kotlin/com/chantha/jdbc/config/WebConfig.java
new file mode 100644
index 0000000..cc1a322
--- /dev/null
+++ b/src/main/kotlin/com/chantha/jdbc/config/WebConfig.java
@@ -0,0 +1,4 @@
+package com.chantha.jdbc.config;
+
+public class WebConfig {
+}
diff --git a/src/main/kotlin/com/chantha/jdbc/controller/ProductController.kt b/src/main/kotlin/com/chantha/jdbc/controller/ProductController.kt
index 87c1181..6ddcdbb 100644
--- a/src/main/kotlin/com/chantha/jdbc/controller/ProductController.kt
+++ b/src/main/kotlin/com/chantha/jdbc/controller/ProductController.kt
@@ -5,6 +5,7 @@ import com.chantha.jdbc.jpa.model.view.ProductWithOrderDetail
import com.chantha.jdbc.jpa.repo.ProductRepo
import com.chantha.jdbc.jpa.service.product.ProductService
import org.springframework.beans.factory.annotation.Autowired
+import org.springframework.web.bind.annotation.CrossOrigin
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RestController
@@ -15,6 +16,7 @@ public class ProductController @Autowired constructor(private val productService
fun product():List{
return productService.fetchAllProducts()
}
+
@GetMapping("/api/product/getproduct")
fun getAllProduct():List{
return productRepo.readAllRecord()
diff --git a/src/main/kotlin/com/chantha/jdbc/jpa/model/Customer.java b/src/main/kotlin/com/chantha/jdbc/jpa/model/Customer.java
index 68f3841..015bd9b 100644
--- a/src/main/kotlin/com/chantha/jdbc/jpa/model/Customer.java
+++ b/src/main/kotlin/com/chantha/jdbc/jpa/model/Customer.java
@@ -72,4 +72,5 @@ public class Customer implements Serializable {
@JsonManagedReference
@OneToMany(mappedBy = "customer")
private List orders;
+
}
diff --git a/src/main/kotlin/com/chantha/jdbc/jpa/model/Order.java b/src/main/kotlin/com/chantha/jdbc/jpa/model/Order.java
index 9a1ca4a..b7bf864 100644
--- a/src/main/kotlin/com/chantha/jdbc/jpa/model/Order.java
+++ b/src/main/kotlin/com/chantha/jdbc/jpa/model/Order.java
@@ -31,6 +31,11 @@ public class Order implements Serializable {
@JoinColumn(name = "cusId",nullable = false,referencedColumnName = "id")
private Customer customer;
+ @ManyToOne(fetch = FetchType.LAZY)
+ @JsonBackReference
+ @JoinColumn(name = "sid",nullable = false,referencedColumnName = "id")
+ private Staff staff;
+
@OneToMany(mappedBy = "order")
private List orderDetails;
@@ -39,6 +44,14 @@ public class Order implements Serializable {
return orderId;
}
+ public Staff getStaff() {
+ return staff;
+ }
+
+ public void setStaff(Staff staff) {
+ this.staff = staff;
+ }
+
public void setOrderId(Long orderId) {
this.orderId = orderId;
}
@@ -80,10 +93,11 @@ public class Order implements Serializable {
public Order() {
}
- public Order(Long orderId,Date orderDate,double amount,Customer customer,List orderDetails) {
+ public Order(Long orderId,Date orderDate,double amount,Customer customer,List orderDetails,Staff staff) {
this.orderId=orderId;
this.orderDate=orderDate;
this.amount=amount;
this.orderDetails=orderDetails;
+ this.staff=staff;
}
}
diff --git a/src/main/kotlin/com/chantha/jdbc/jpa/model/Position.java b/src/main/kotlin/com/chantha/jdbc/jpa/model/Position.java
new file mode 100644
index 0000000..ac9bb52
--- /dev/null
+++ b/src/main/kotlin/com/chantha/jdbc/jpa/model/Position.java
@@ -0,0 +1,25 @@
+package com.chantha.jdbc.jpa.model;
+
+import com.fasterxml.jackson.annotation.JsonManagedReference;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import javax.persistence.*;
+import java.util.List;
+
+@Entity
+@NoArgsConstructor
+@AllArgsConstructor
+@Data
+public class Position {
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ private Long id;
+ private String tittle;
+
+ @OneToMany(mappedBy = "position")
+ @JsonManagedReference
+ private List staff;
+}
diff --git a/src/main/kotlin/com/chantha/jdbc/jpa/model/Staff.java b/src/main/kotlin/com/chantha/jdbc/jpa/model/Staff.java
new file mode 100644
index 0000000..407d7f0
--- /dev/null
+++ b/src/main/kotlin/com/chantha/jdbc/jpa/model/Staff.java
@@ -0,0 +1,33 @@
+package com.chantha.jdbc.jpa.model;
+
+import com.fasterxml.jackson.annotation.JsonBackReference;
+import com.fasterxml.jackson.annotation.JsonManagedReference;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import javax.persistence.*;
+import java.util.List;
+
+@Entity
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+public class Staff {
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ private Long id;
+ private String name;
+ private Gender gender;
+ private double salary;
+
+
+ @JsonManagedReference
+ @OneToMany(mappedBy = "staff")
+ private List orderList;
+
+ @JsonBackReference
+ @ManyToOne(fetch = FetchType.LAZY,cascade = CascadeType.ALL)
+ @JoinColumn(name = "posId",nullable = false,referencedColumnName = "id")
+ private Position position;
+}
diff --git a/target/classes/com/chantha/jdbc/controller/ProductController.class b/target/classes/com/chantha/jdbc/controller/ProductController.class
index 0cafbee..95d7dd3 100644
Binary files a/target/classes/com/chantha/jdbc/controller/ProductController.class and b/target/classes/com/chantha/jdbc/controller/ProductController.class differ
diff --git a/target/classes/com/chantha/jdbc/jpa/model/Order.class b/target/classes/com/chantha/jdbc/jpa/model/Order.class
index be4a4c8..4d5ba02 100644
Binary files a/target/classes/com/chantha/jdbc/jpa/model/Order.class and b/target/classes/com/chantha/jdbc/jpa/model/Order.class differ
diff --git a/target/classes/com/chantha/jdbc/jpa/model/Position.class b/target/classes/com/chantha/jdbc/jpa/model/Position.class
new file mode 100644
index 0000000..c727eae
Binary files /dev/null and b/target/classes/com/chantha/jdbc/jpa/model/Position.class differ
diff --git a/target/classes/com/chantha/jdbc/jpa/model/Staff.class b/target/classes/com/chantha/jdbc/jpa/model/Staff.class
new file mode 100644
index 0000000..ea3a3d5
Binary files /dev/null and b/target/classes/com/chantha/jdbc/jpa/model/Staff.class differ