blob: 778f93bd66260de9139629f77acc8b1e7a444354 (
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
37
38
39
|
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.PathVariable;
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="/item")
public class ItemController {
@Autowired
private ItemRepository itemRepository;
@PostMapping(path="/add")
public @ResponseBody String addNewItem (@RequestParam String name, @RequestParam String description, @RequestParam double quantity) {
Item item = new Item();
item.setName(name);
item.setDescription(description);
item.setQuantity(quantity);
itemRepository.save(item);
return "Ok";
}
@GetMapping(path="/all")
public @ResponseBody Iterable<Item> getAllItems() {
return itemRepository.findAll();
}
@GetMapping(path="/name/{name}")
public @ResponseBody Item getByName(@PathVariable String name) {
return itemRepository.findByName(name);
}
}
|