blob: 1968139ec8a59fa2502db8b5297a5aebbe5e9039 (
plain) (
blame)
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
|
package dev.submelon.pantry;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
@RequestMapping(path="/items")
public class PantryItemController {
@Autowired
private PantryItemRepository itemRepository;
@PostMapping(path="/add")
@ResponseBody
Integer addNewItem(@RequestParam String name, @RequestParam String description, @RequestParam double quantity, @RequestParam String quantityUnitType) {
PantryItem item = new PantryItem();
item.setName(name);
item.setDescription(description);
item.setQuantity(quantity);
item.setQuantityUnitType(quantityUnitType);
PantryItem updatedItem = itemRepository.save(item);
return updatedItem.getId();
}
@GetMapping(path="")
@ResponseBody
Iterable<PantryItem> getAllItems() {
return itemRepository.findAll();
}
}
|