-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProductController.java
More file actions
85 lines (68 loc) · 2.54 KB
/
Copy pathProductController.java
File metadata and controls
85 lines (68 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package com.example.demo.controller;
import com.example.demo.model.Product;
import com.example.demo.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.List;
@RestController
@RequestMapping(value = "/product")
public class ProductController {
@Autowired
private ProductService productService;
// (GET) get all products
@GetMapping("/")
public List<Product> getAll(){
return productService.retreiveAll();
}
// (GET) get all products by category
@GetMapping("/category")
public List<Product> getAllProductByCategory(
@RequestParam String category
){
return productService.retreiveByCategory(category);
}
// (GET) get all products that a merchant has by category
@GetMapping("/category/merchant")
public List<Product> getAllProductByCategoryOfMerchant(
@RequestParam String category,
@RequestParam int merchantID
){
return productService.retreiveByCategoryOfMerchant(merchantID,category);
}
// (POST) add new product
@PostMapping("/new")
public Product addProduct(
@Valid @RequestBody Product product
){
return productService.saveNewProduct(product);
}
// (PUT) update existing product by productID
@PutMapping("/update")
public void updateProduct(
@Valid @RequestBody Product product,
@RequestParam int productID
){
productService.updateExistingProduct(productID,product);
}
// (DELETE) delete product by productID
@DeleteMapping("/delete")
public void deleteProduct(
@RequestParam int productID
){
productService.deleteProduct(productID);
}
// @RequestMapping(value = "/", method = RequestMethod.GET)
// public List<Product> getAll(){
// return productService.retreiveAll();
// }
//
// @RequestMapping(value = "/category/{category}", method = RequestMethod.GET)
// public List<Product> getAllProductByCategory(@PathVariable("category") String category){
// return productService.retreiveByCategory(category);
// }
// @RequestMapping(value = "/category/{category}/merchant/{merchantID}",method = RequestMethod.GET)
// public List<Product> getAllProductByCategoryOfMerchant(@PathVariable("category") String category, @PathVariable("merchantID") int merchantID){
// return productService.retreiveByCategoryOfMerchant(merchantID,category);
// }
}