-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNotes
More file actions
93 lines (79 loc) · 3.24 KB
/
Notes
File metadata and controls
93 lines (79 loc) · 3.24 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
86
87
88
89
90
91
92
93
/** public void addProduct(Integer productID, String productName, Double productPrice, String vendorName)
throws ProductException, VendorException {
//add logging
//generate product id
if(productName.isEmpty()) {
//add logging
throw new ProductException("Product Name cannot blank");
}
else if (productPrice <= 0) {
//add logging
throw new ProductException("Product price must be a positive number greater than zero");
}
else if (vendorName.isEmpty()){
//add logging
throw new VendorException("Vendor name cannot be blank");
}
else if (vendors does not contain vendorName) {
//add logging
throw new ProductException("Vendor does not currently exist; please add vendor first and then add product");
}
Product x = new Product(productID, productName, productPrice, vendorName);
products.add(x);
} **/
/**public void addVendor(String vendorName) throws VendorException {
//add logging
if(vendorName.isEmpty()){
//add logging
throw new VendorException("Vendor name cannot be blank");
}
else if(vendors.contains(vendorName)){
//add logging
throw new VendorException("Vendor already exists");
}
Vendor v = new Vendor();
vendors.add(v);
}**/
/**
public void getAllVendorsHandler(Context context){
List<Vendor> vendors = vendorService.retrieveVendors();
context.json(vendors);
}
//where do we put in checks for null values entered and matching (non-unique) values entered?
public void postVendorHandler(Context context) {
ObjectMapper om = new ObjectMapper();
try{
Vendor v = om.readValue(context.body(), Vendor.class);
vendorService.addVendor(v);
context.status(201);
}catch (JsonProcessingException e) {
context.status(400);
}
}
public void getAllProductsHandler(Context context){
List<Product> productList = productService.viewAllProduct();
context.json(productList);
}
public static void getProductHandler(Context context){
}
//where do we put in checks for null values entered and matching (non-unique) values entered?
public void postProductHandler(Context context) throws ProductException {
ObjectMapper om = new ObjectMapper();
try{
Product x = om.readValue(context.body(), Product.class);
productService.addProduct(x);
context.status(201);
}catch (JsonProcessingException e) {
context.status(400);
}
}
public static void putProductHandler(Context context){
}
public static void deleteProductHandler(Context context){
}
} **/
/** does this make sense to generate a unique productID each time??? would this go under the setter instead???
private final AtomicLong id = new AtomicLong(1);
public long getNext() {
return id.getAndIncrement();
} **/