config cors header

This commit is contained in:
Chantha 2020-05-17 13:35:32 +07:00
parent 5e35060d53
commit ba9e100a18
11 changed files with 69 additions and 34 deletions

View File

@ -2,15 +2,14 @@
<project version="4">
<component name="ChangeListManager">
<list default="true" id="47c3fbf4-4238-47d3-9ffa-fcd23da4e01e" name="Default Changelist" comment="">
<change afterPath="$PROJECT_DIR$/src/main/kotlin/com/chantha/jdbc/jpa/model/view/CustomerOrderView.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/kotlin/com/chantha/jdbc/jpa/model/view/OrderView.kt" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/kotlin/com/chantha/jdbc/jpa/service/customer/CustomerServiceImpl.kt" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/kotlin/com/chantha/jdbc/config/CORSConfig.kt" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/kotlin/com/chantha/jdbc/controller/CustomerController.kt" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/kotlin/com/chantha/jdbc/controller/CustomerController.kt" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/kotlin/com/chantha/jdbc/jpa/service/customer/CustomerService.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/kotlin/com/chantha/jdbc/jpa/service/customer/CustomerService.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/kotlin/com/chantha/jdbc/jpa/service/customer/CustomerServiceImpl.java" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/target/classes/com/chantha/jdbc/controller/CustomerController.class" beforeDir="false" afterPath="$PROJECT_DIR$/target/classes/com/chantha/jdbc/controller/CustomerController.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/target/classes/com/chantha/jdbc/jpa/service/customer/CustomerServiceImpl.class" beforeDir="false" afterPath="$PROJECT_DIR$/target/classes/com/chantha/jdbc/jpa/service/customer/CustomerServiceImpl.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/kotlin/com/chantha/jdbc/controller/ProductController.kt" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/kotlin/com/chantha/jdbc/controller/ProductController.kt" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/kotlin/com/chantha/jdbc/jpa/model/Product.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/kotlin/com/chantha/jdbc/jpa/model/Product.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/kotlin/com/chantha/jdbc/jpa/repo/ProductRepo.kt" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/kotlin/com/chantha/jdbc/jpa/repo/ProductRepo.kt" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/kotlin/com/chantha/jdbc/jpa/service/product/ProductServiceImpl.kt" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/kotlin/com/chantha/jdbc/jpa/service/product/ProductServiceImpl.kt" afterDir="false" />
<change beforePath="$PROJECT_DIR$/target/classes/com/chantha/jdbc/controller/ProductController.class" beforeDir="false" afterPath="$PROJECT_DIR$/target/classes/com/chantha/jdbc/controller/ProductController.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/target/classes/com/chantha/jdbc/jpa/service/product/ProductServiceImpl.class" beforeDir="false" afterPath="$PROJECT_DIR$/target/classes/com/chantha/jdbc/jpa/service/product/ProductServiceImpl.class" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -86,7 +85,8 @@
<workItem from="1589600878500" duration="1425000" />
<workItem from="1589602595035" duration="1232000" />
<workItem from="1589605337172" duration="14812000" />
<workItem from="1589690218526" duration="2731000" />
<workItem from="1589690218526" duration="3238000" />
<workItem from="1589695280458" duration="2028000" />
</task>
<servers />
</component>
@ -102,10 +102,10 @@
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state x="690" y="276" key="#com.intellij.codeInsight.editorActions.RestoreReferencesDialog/0.0.1920.1040@0.0.1920.1040" timestamp="1589601961718" />
<state x="765" y="197" key="#com.intellij.ide.util.MemberChooser" timestamp="1589692404775">
<state x="765" y="197" key="#com.intellij.ide.util.MemberChooser" timestamp="1589695931011">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state x="765" y="197" key="#com.intellij.ide.util.MemberChooser/0.0.1920.1040@0.0.1920.1040" timestamp="1589692404775" />
<state x="765" y="197" key="#com.intellij.ide.util.MemberChooser/0.0.1920.1040@0.0.1920.1040" timestamp="1589695931011" />
<state x="649" y="437" key="#com.intellij.refactoring.move.MoveHandler.SelectRefactoringDialog" timestamp="1589690277066">
<screen x="0" y="0" width="1920" height="1040" />
</state>
@ -118,49 +118,49 @@
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state x="739" y="31" key="#org.jetbrains.kotlin.idea.refactoring.move.moveDeclarations.ui.MoveKotlinTopLevelDeclarationsDialog/0.0.1920.1040@0.0.1920.1040" timestamp="1589608464352" />
<state x="740" y="276" key="FileChooserDialogImpl" timestamp="1589690795641">
<state x="740" y="276" key="FileChooserDialogImpl" timestamp="1589695324127">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state x="740" y="276" key="FileChooserDialogImpl/0.0.1920.1040@0.0.1920.1040" timestamp="1589690795641" />
<state width="1877" height="420" key="GridCell.Tab.0.bottom" timestamp="1589692987531">
<state x="740" y="276" key="FileChooserDialogImpl/0.0.1920.1040@0.0.1920.1040" timestamp="1589695324127" />
<state width="1877" height="420" key="GridCell.Tab.0.bottom" timestamp="1589697284781">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state width="1877" height="420" key="GridCell.Tab.0.bottom/0.0.1920.1040@0.0.1920.1040" timestamp="1589692987531" />
<state width="1877" height="420" key="GridCell.Tab.0.center" timestamp="1589692987530">
<state width="1877" height="420" key="GridCell.Tab.0.bottom/0.0.1920.1040@0.0.1920.1040" timestamp="1589697284781" />
<state width="1877" height="420" key="GridCell.Tab.0.center" timestamp="1589697284781">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state width="1877" height="420" key="GridCell.Tab.0.center/0.0.1920.1040@0.0.1920.1040" timestamp="1589692987530" />
<state width="1877" height="420" key="GridCell.Tab.0.left" timestamp="1589692987530">
<state width="1877" height="420" key="GridCell.Tab.0.center/0.0.1920.1040@0.0.1920.1040" timestamp="1589697284781" />
<state width="1877" height="420" key="GridCell.Tab.0.left" timestamp="1589697284781">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state width="1877" height="420" key="GridCell.Tab.0.left/0.0.1920.1040@0.0.1920.1040" timestamp="1589692987530" />
<state width="1877" height="420" key="GridCell.Tab.0.right" timestamp="1589692987530">
<state width="1877" height="420" key="GridCell.Tab.0.left/0.0.1920.1040@0.0.1920.1040" timestamp="1589697284781" />
<state width="1877" height="420" key="GridCell.Tab.0.right" timestamp="1589697284781">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state width="1877" height="420" key="GridCell.Tab.0.right/0.0.1920.1040@0.0.1920.1040" timestamp="1589692987530" />
<state width="1877" height="420" key="GridCell.Tab.1.bottom" timestamp="1589692987531">
<state width="1877" height="420" key="GridCell.Tab.0.right/0.0.1920.1040@0.0.1920.1040" timestamp="1589697284781" />
<state width="1877" height="420" key="GridCell.Tab.1.bottom" timestamp="1589697284781">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state width="1877" height="420" key="GridCell.Tab.1.bottom/0.0.1920.1040@0.0.1920.1040" timestamp="1589692987531" />
<state width="1877" height="420" key="GridCell.Tab.1.center" timestamp="1589692987531">
<state width="1877" height="420" key="GridCell.Tab.1.bottom/0.0.1920.1040@0.0.1920.1040" timestamp="1589697284781" />
<state width="1877" height="420" key="GridCell.Tab.1.center" timestamp="1589697284781">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state width="1877" height="420" key="GridCell.Tab.1.center/0.0.1920.1040@0.0.1920.1040" timestamp="1589692987531" />
<state width="1877" height="420" key="GridCell.Tab.1.left" timestamp="1589692987531">
<state width="1877" height="420" key="GridCell.Tab.1.center/0.0.1920.1040@0.0.1920.1040" timestamp="1589697284781" />
<state width="1877" height="420" key="GridCell.Tab.1.left" timestamp="1589697284781">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state width="1877" height="420" key="GridCell.Tab.1.left/0.0.1920.1040@0.0.1920.1040" timestamp="1589692987531" />
<state width="1877" height="420" key="GridCell.Tab.1.right" timestamp="1589692987531">
<state width="1877" height="420" key="GridCell.Tab.1.left/0.0.1920.1040@0.0.1920.1040" timestamp="1589697284781" />
<state width="1877" height="420" key="GridCell.Tab.1.right" timestamp="1589697284781">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state width="1877" height="420" key="GridCell.Tab.1.right/0.0.1920.1040@0.0.1920.1040" timestamp="1589692987531" />
<state width="1877" height="420" key="GridCell.Tab.1.right/0.0.1920.1040@0.0.1920.1040" timestamp="1589697284781" />
<state x="767" y="433" key="com.intellij.openapi.vcs.update.UpdateOrStatusOptionsDialogupdate-v2" timestamp="1589538516704">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state x="767" y="433" key="com.intellij.openapi.vcs.update.UpdateOrStatusOptionsDialogupdate-v2/0.0.1920.1040@0.0.1920.1040" timestamp="1589538516704" />
<state x="623" y="225" width="672" height="678" key="search.everywhere.popup" timestamp="1589692961508">
<state x="623" y="225" width="672" height="678" key="search.everywhere.popup" timestamp="1589696948784">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state x="623" y="225" width="672" height="678" key="search.everywhere.popup/0.0.1920.1040@0.0.1920.1040" timestamp="1589692961508" />
<state x="623" y="225" width="672" height="678" key="search.everywhere.popup/0.0.1920.1040@0.0.1920.1040" timestamp="1589696948784" />
</component>
</project>

View File

@ -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")
}
}

View File

@ -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<ProductWithOrderDetail>{
return productService.fetchAllProducts()
}
@GetMapping("/api/product/getproduct")
fun getAllProduct():List<Product>{
return productRepo.readAllRecord()
}
}

View File

@ -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<OrderDetail> orderDetails) {
public Product(Long productId, String productName, double price, List<OrderDetail> orderDetails,String img) {
this.productId=productId;
this.productName=productName;
this.price=price;
this.orderDetails=orderDetails;
this.img=img;
}
// @JsonManagedReference

View File

@ -10,4 +10,8 @@ interface ProductRepo : CrudRepository<Product,Long>{
@Query("SELECT * FROM product INNER JOIN order_detail ON (product.product_id=order_detail.product_id)"
, nativeQuery = true)
override fun findAll(): MutableIterable<Product>
@Query("SELECT * FROM product",nativeQuery = true)
fun readAllRecord():List<Product>
}

View File

@ -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