diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 2f9d634..5bdc19a 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,15 +2,14 @@ - - - + - - - - - + + + + + + @@ -102,10 +102,10 @@ - + - + @@ -118,49 +118,49 @@ - + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - + - + - + \ No newline at end of file diff --git a/src/main/kotlin/com/chantha/jdbc/config/CORSConfig.kt b/src/main/kotlin/com/chantha/jdbc/config/CORSConfig.kt new file mode 100644 index 0000000..775a085 --- /dev/null +++ b/src/main/kotlin/com/chantha/jdbc/config/CORSConfig.kt @@ -0,0 +1,13 @@ +package com.chantha.jdbc.config + +import org.springframework.context.annotation.Configuration +import org.springframework.web.servlet.config.annotation.CorsRegistry +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer + +@Configuration +class CORSConfig :WebMvcConfigurer{ + + override fun addCorsMappings(registry: CorsRegistry) { + registry.addMapping("/**").allowedOrigins("http://localhost:3001") + } +} diff --git a/src/main/kotlin/com/chantha/jdbc/controller/ProductController.kt b/src/main/kotlin/com/chantha/jdbc/controller/ProductController.kt index 172b0e0..87c1181 100644 --- a/src/main/kotlin/com/chantha/jdbc/controller/ProductController.kt +++ b/src/main/kotlin/com/chantha/jdbc/controller/ProductController.kt @@ -9,11 +9,15 @@ import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.RestController @RestController -public class ProductController @Autowired constructor(private val productService: ProductService) { +public class ProductController @Autowired constructor(private val productService: ProductService,private val productRepo: ProductRepo) { - @GetMapping("/product") + @GetMapping("/api/product/order") fun product():List{ return productService.fetchAllProducts() } + @GetMapping("/api/product/getproduct") + fun getAllProduct():List{ + return productRepo.readAllRecord() + } } \ No newline at end of file diff --git a/src/main/kotlin/com/chantha/jdbc/jpa/model/Product.java b/src/main/kotlin/com/chantha/jdbc/jpa/model/Product.java index aca6da2..bcd809f 100644 --- a/src/main/kotlin/com/chantha/jdbc/jpa/model/Product.java +++ b/src/main/kotlin/com/chantha/jdbc/jpa/model/Product.java @@ -8,6 +8,7 @@ import java.util.List; @Entity //@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "productId") +@JsonPropertyOrder({"productId"}) public class Product implements Serializable { @Id @@ -17,6 +18,16 @@ public class Product implements Serializable { private String productName; private double price; + public String getImg() { + return img; + } + + public void setImg(String img) { + this.img = img; + } + + private String img; + public Product() { } @@ -53,11 +64,12 @@ public class Product implements Serializable { this.orderDetails = orderDetails; } - public Product(Long productId, String productName, double price, List orderDetails) { + public Product(Long productId, String productName, double price, List orderDetails,String img) { this.productId=productId; this.productName=productName; this.price=price; this.orderDetails=orderDetails; + this.img=img; } // @JsonManagedReference diff --git a/src/main/kotlin/com/chantha/jdbc/jpa/repo/ProductRepo.kt b/src/main/kotlin/com/chantha/jdbc/jpa/repo/ProductRepo.kt index 992c05f..5b3fec2 100644 --- a/src/main/kotlin/com/chantha/jdbc/jpa/repo/ProductRepo.kt +++ b/src/main/kotlin/com/chantha/jdbc/jpa/repo/ProductRepo.kt @@ -10,4 +10,8 @@ interface ProductRepo : CrudRepository{ @Query("SELECT * FROM product INNER JOIN order_detail ON (product.product_id=order_detail.product_id)" , nativeQuery = true) override fun findAll(): MutableIterable + + @Query("SELECT * FROM product",nativeQuery = true) + fun readAllRecord():List + } \ No newline at end of file diff --git a/src/main/kotlin/com/chantha/jdbc/jpa/service/product/ProductServiceImpl.kt b/src/main/kotlin/com/chantha/jdbc/jpa/service/product/ProductServiceImpl.kt index e99b733..7c4e0c2 100644 --- a/src/main/kotlin/com/chantha/jdbc/jpa/service/product/ProductServiceImpl.kt +++ b/src/main/kotlin/com/chantha/jdbc/jpa/service/product/ProductServiceImpl.kt @@ -16,6 +16,8 @@ class ProductServiceImpl @Autowired constructor(private val productRepo: Product return productRepo.findAll().map { toView(it) } } + + private fun toView(data: Product): ProductWithOrderDetail { val view = ProductWithOrderDetail() view.productId = data.productId diff --git a/target/classes/com/chantha/jdbc/config/CORSConfig.class b/target/classes/com/chantha/jdbc/config/CORSConfig.class new file mode 100644 index 0000000..cb0a722 Binary files /dev/null and b/target/classes/com/chantha/jdbc/config/CORSConfig.class differ diff --git a/target/classes/com/chantha/jdbc/controller/ProductController.class b/target/classes/com/chantha/jdbc/controller/ProductController.class index fa675b3..0cafbee 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/Product.class b/target/classes/com/chantha/jdbc/jpa/model/Product.class index 3cb7783..860302b 100644 Binary files a/target/classes/com/chantha/jdbc/jpa/model/Product.class and b/target/classes/com/chantha/jdbc/jpa/model/Product.class differ diff --git a/target/classes/com/chantha/jdbc/jpa/repo/ProductRepo.class b/target/classes/com/chantha/jdbc/jpa/repo/ProductRepo.class index 5f6934c..b28e832 100644 Binary files a/target/classes/com/chantha/jdbc/jpa/repo/ProductRepo.class and b/target/classes/com/chantha/jdbc/jpa/repo/ProductRepo.class differ diff --git a/target/classes/com/chantha/jdbc/jpa/service/product/ProductServiceImpl.class b/target/classes/com/chantha/jdbc/jpa/service/product/ProductServiceImpl.class index 2f70426..43c5dc4 100644 Binary files a/target/classes/com/chantha/jdbc/jpa/service/product/ProductServiceImpl.class and b/target/classes/com/chantha/jdbc/jpa/service/product/ProductServiceImpl.class differ