|
|
@@ -13,34 +13,38 @@ import java.util.Map;
|
|
13
|
13
|
import java.util.stream.Collector;
|
|
14
|
14
|
import java.util.stream.Collectors;
|
|
15
|
15
|
|
|
16
|
|
-@Controller
|
|
|
16
|
+//change this to RestController
|
|
|
17
|
+@RestController
|
|
17
|
18
|
@RequestMapping(path="/users")
|
|
18
|
19
|
public class UserController {
|
|
|
20
|
+
|
|
19
|
21
|
@Autowired
|
|
20
|
22
|
private UserRepository repository;
|
|
21
|
23
|
|
|
22
|
|
- @GetMapping(path="/new")
|
|
23
|
|
- public String newUser(Model model){
|
|
24
|
|
- model.addAttribute("user", new User());
|
|
25
|
|
- return "users/new";
|
|
26
|
|
- }
|
|
|
24
|
+ //Don't need this anymore
|
|
|
25
|
+// @GetMapping(path="/new")
|
|
|
26
|
+// public String newUser(Model model){
|
|
|
27
|
+// model.addAttribute("user", new User());
|
|
|
28
|
+// return "users/new";
|
|
|
29
|
+// }
|
|
27
|
30
|
|
|
|
31
|
+ // change @ModelAttribute to @RequestBody
|
|
28
|
32
|
@PostMapping
|
|
29
|
|
- public String create(@ModelAttribute User user){
|
|
|
33
|
+ public String create(@RequestBody User user){
|
|
30
|
34
|
repository.save(user);
|
|
31
|
|
- return "redirect:users";
|
|
|
35
|
+ return "Created";
|
|
32
|
36
|
}
|
|
33
|
37
|
|
|
|
38
|
+ //change this to return user instead of template name
|
|
34
|
39
|
@RequestMapping(value="/{id}")
|
|
35
|
|
- public String get(@PathVariable long id, Model model){
|
|
36
|
|
- model.addAttribute("user", repository.findById(id));
|
|
37
|
|
- return "users/show";
|
|
|
40
|
+ public User get(@PathVariable long id){
|
|
|
41
|
+ return repository.findById(id);
|
|
38
|
42
|
}
|
|
39
|
43
|
|
|
|
44
|
+// change this to return list instead of template name
|
|
40
|
45
|
@GetMapping
|
|
41
|
|
- public String index(Model model){
|
|
42
|
|
- model.addAttribute("allUsers", repository.findAll());
|
|
43
|
|
- return "users/index";
|
|
|
46
|
+ public List<User> index(){
|
|
|
47
|
+ return repository.findAll();
|
|
44
|
48
|
}
|
|
45
|
49
|
|
|
46
|
50
|
|