Skip to content

Commit 85b778a

Browse files
GET/POST methods are working,PUT is not
1 parent ddfcba3 commit 85b778a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+2510
-2461
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ build/
2222
nbbuild/
2323
dist/
2424
nbdist/
25-
.nb-gradle/
25+
.nb-gradle/
26+
/bin/

src/main/java/com/example/Controller/CategoryController.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.example.Controller;
22

3-
import com.example.Entity.CategoryEntity;
3+
import com.example.Entity.Category;
44
import com.example.Service.CategoryService;
55
import org.springframework.beans.factory.annotation.Autowired;
66
import org.springframework.web.bind.annotation.*;
@@ -21,33 +21,33 @@ public class CategoryController {
2121

2222

2323
@RequestMapping("")
24-
public Iterable<CategoryEntity> getAllCategory() {
24+
public Iterable<Category> getAllCategory() {
2525

2626
//return categoryService.getAllCategoryList();
2727
return categoryService.findAll();
2828
}
2929

3030

3131
@RequestMapping("/{id}")
32-
public Optional<CategoryEntity> searchCategory(@PathVariable int id) {
32+
public Optional<Category> searchCategory(@PathVariable int id) {
3333
//return categoryService.searchCategory(id);
3434
return categoryService.findById(id);
3535
}
3636

3737
@RequestMapping(method = RequestMethod.POST, value = "")
38-
public void addCategory(@RequestBody CategoryEntity category) {
38+
public void addCategory(@RequestBody Category category) {
3939

4040
//categoryService.addCategory(category);
4141
categoryService.insert(category);
4242
}
4343

4444
@RequestMapping(method = RequestMethod.PUT,value ="/{id}")
45-
public void updateCategory(@RequestBody CategoryEntity category, @PathVariable int categoryId) {
45+
public void updateCategory(@RequestBody Category category, @PathVariable int categoryId) {
4646
categoryService.updateCategory(categoryId, category);
4747
}
4848

4949
@RequestMapping(method = RequestMethod.DELETE,value ="/{id}")
50-
public void deleteCategory(int categoryId) {
50+
public void deleteCategory(@PathVariable int categoryId) {
5151
categoryService.deleteCategory(categoryId);
5252
}
5353

src/main/java/com/example/Controller/PricingController.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.example.Controller;
22

3-
import com.example.Entity.PricingEntity;
3+
import com.example.Entity.Pricing;
44
import com.example.Service.PricingService;
55
import org.springframework.beans.factory.annotation.Autowired;
66
import org.springframework.web.bind.annotation.*;
@@ -26,28 +26,28 @@ public class PricingController {
2626

2727

2828
/* @RequestMapping("")
29-
public List<PricingEntity> getAllPricing() {
29+
public List<Pricing> getAllPricing() {
3030
3131
//return pricingService.getAllCategoryList();
3232
return pricingService.findAll();
3333
}*/
3434

3535

3636
@RequestMapping("/pricings/{id}")
37-
public Optional<PricingEntity> searchPricing(@PathVariable int id) {
37+
public Optional<Pricing> searchPricing(@PathVariable int id) {
3838
//return categoryService.searchCategory(id);
3939
return pricingService.find(id);
4040
}
4141

4242
@RequestMapping(method = RequestMethod.POST, value = "")
43-
public void addPricing(@RequestBody PricingEntity pricing) {
43+
public void addPricing(@RequestBody Pricing pricing) {
4444

4545
//categoryService.addCategory(category);
4646
pricingService.insert(pricing);
4747
}
4848

4949
@RequestMapping(method = RequestMethod.PUT,value ="/{id}")
50-
public void updateCategory(@RequestBody PricingEntity pricing) {
50+
public void updateCategory(@RequestBody Pricing pricing) {
5151
pricingService.updatePricing(pricing);
5252
}
5353

src/main/java/com/example/Controller/ProductController.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.example.Controller;
22

3-
import com.example.Entity.ProductEntity;
3+
import com.example.Entity.Product;
44
import com.example.Service.ProductService;
55
import org.springframework.beans.factory.annotation.Autowired;
66
import org.springframework.web.bind.annotation.*;
@@ -20,30 +20,30 @@ public class ProductController {
2020
public ProductService productService;
2121

2222
/* @RequestMapping("")
23-
public List<ProductEntity> getAllProducts() {
23+
public List<Product> getAllProducts() {
2424
2525
//return productService.getAllProductList();
2626
return productService.findAll();
2727
}*/
2828

2929

3030
@RequestMapping("/{id}")
31-
public Optional<ProductEntity> searchProduct(@PathVariable int id) {
31+
public Optional<Product> searchProduct(@PathVariable int id) {
3232
//return productService.searchProduct(id);
3333
return productService.find(id);
3434
}
3535

36-
// ToDo: Cant map request body with two entities (ProductEntity and CategoryEntity)
36+
// ToDo: Cant map request body with two entities (Product and Category)
3737
// @RequestMapping(method = RequestMethod.POST, value = "")
38-
// public void addProduct(@RequestBody ProductEntity product, @RequestBody CategoryEntity category) {
38+
// public void addProduct(@RequestBody Product product, @RequestBody Category category) {
3939
//
4040
// //productService.addProduct(product);
4141
// product.setCategoryByCategoryId(category);
4242
// productService.insert(product);
4343
// }
4444

4545
@RequestMapping(method = RequestMethod.PUT,value ="/{id}")
46-
public void updateProduct(@RequestBody ProductEntity product) {
46+
public void updateProduct(@RequestBody Product product) {
4747
productService.updateProduct(product);
4848
}
4949

src/main/java/com/example/Controller/StockController.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.example.Controller;
22

3-
import com.example.Entity.StockEntity;
3+
import com.example.Entity.Stock;
44
import com.example.Service.StockService;
55
import org.springframework.beans.factory.annotation.Autowired;
66
import org.springframework.web.bind.annotation.*;
@@ -14,28 +14,28 @@ public class StockController {
1414
private StockService stockService;
1515

1616
@RequestMapping("")
17-
public Iterable<StockEntity> getAllStock() {
17+
public Iterable<Stock> getAllStock() {
1818

1919
//return categoryService.getAllCategoryList();
2020
return stockService.findAll();
2121
}
2222

2323

2424
@RequestMapping("/{id}")
25-
public Optional<StockEntity> searchStock(@PathVariable int id) {
25+
public Optional<Stock> searchStock(@PathVariable int id) {
2626
//return categoryService.searchCategory(id);
2727
return stockService.findById(id);
2828
}
2929

3030
@RequestMapping(method = RequestMethod.POST, value = "")
31-
public void addStock(@RequestBody StockEntity stock) {
31+
public void addStock(@RequestBody Stock stock) {
3232

3333
//categoryService.addCategory(category);
3434
stockService.insert(stock);
3535
}
3636

3737
@RequestMapping(method = RequestMethod.PUT,value ="/{id}")
38-
public void updateStock(@RequestBody StockEntity stock, @PathVariable int stockId) {
38+
public void updateStock(@RequestBody Stock stock, @PathVariable int stockId) {
3939
stockService.updateStock(stockId, stock);
4040
}
4141

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
package com.example.Entity;
2+
3+
import java.io.Serializable;
4+
import javax.persistence.*;
5+
import java.math.BigDecimal;
6+
import java.util.Date;
7+
import java.util.List;
8+
9+
10+
/**
11+
* The persistent class for the category database table.
12+
*
13+
*/
14+
@Entity
15+
@NamedQuery(name="Category.findAll", query="SELECT c FROM Category c")
16+
public class Category implements Serializable {
17+
private static final long serialVersionUID = 1L;
18+
19+
@Id
20+
@GeneratedValue(strategy=GenerationType.AUTO)
21+
private int categoryId;
22+
23+
private String categoryName;
24+
25+
@Temporal(TemporalType.TIMESTAMP)
26+
private Date createdDateTime;
27+
28+
private String createdUser;
29+
30+
@Temporal(TemporalType.TIMESTAMP)
31+
private Date lastModifiedDateTime;
32+
33+
private String lastModifiedUser;
34+
35+
private BigDecimal version;
36+
37+
//bi-directional many-to-one association to Product
38+
@OneToMany(mappedBy="category")
39+
private List<Product> products;
40+
41+
//bi-directional many-to-one association to Stock
42+
@OneToMany(mappedBy="category")
43+
private List<Stock> stocks;
44+
45+
public Category() {
46+
}
47+
48+
public int getCategoryId() {
49+
return this.categoryId;
50+
}
51+
52+
public void setCategoryId(int categoryId) {
53+
this.categoryId = categoryId;
54+
}
55+
56+
public String getCategoryName() {
57+
return this.categoryName;
58+
}
59+
60+
public void setCategoryName(String categoryName) {
61+
this.categoryName = categoryName;
62+
}
63+
64+
public Date getCreatedDateTime() {
65+
return this.createdDateTime;
66+
}
67+
68+
public void setCreatedDateTime(Date createdDateTime) {
69+
this.createdDateTime = createdDateTime;
70+
}
71+
72+
public String getCreatedUser() {
73+
return this.createdUser;
74+
}
75+
76+
public void setCreatedUser(String createdUser) {
77+
this.createdUser = createdUser;
78+
}
79+
80+
public Date getLastModifiedDateTime() {
81+
return this.lastModifiedDateTime;
82+
}
83+
84+
public void setLastModifiedDateTime(Date lastModifiedDateTime) {
85+
this.lastModifiedDateTime = lastModifiedDateTime;
86+
}
87+
88+
public String getLastModifiedUser() {
89+
return this.lastModifiedUser;
90+
}
91+
92+
public void setLastModifiedUser(String lastModifiedUser) {
93+
this.lastModifiedUser = lastModifiedUser;
94+
}
95+
96+
public BigDecimal getVersion() {
97+
return this.version;
98+
}
99+
100+
public void setVersion(BigDecimal version) {
101+
this.version = version;
102+
}
103+
104+
public List<Product> getProducts() {
105+
return this.products;
106+
}
107+
108+
public void setProducts(List<Product> products) {
109+
this.products = products;
110+
}
111+
112+
public Product addProduct(Product product) {
113+
getProducts().add(product);
114+
product.setCategory(this);
115+
116+
return product;
117+
}
118+
119+
public Product removeProduct(Product product) {
120+
getProducts().remove(product);
121+
product.setCategory(null);
122+
123+
return product;
124+
}
125+
126+
public List<Stock> getStocks() {
127+
return this.stocks;
128+
}
129+
130+
public void setStocks(List<Stock> stocks) {
131+
this.stocks = stocks;
132+
}
133+
134+
public Stock addStock(Stock stock) {
135+
getStocks().add(stock);
136+
stock.setCategory(this);
137+
138+
return stock;
139+
}
140+
141+
public Stock removeStock(Stock stock) {
142+
getStocks().remove(stock);
143+
stock.setCategory(null);
144+
145+
return stock;
146+
}
147+
148+
}

0 commit comments

Comments
 (0)