|
|
@@ -6,26 +6,30 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
6
|
6
|
import org.springframework.http.HttpStatus;
|
|
7
|
7
|
import org.springframework.http.ResponseEntity;
|
|
8
|
8
|
|
|
9
|
|
-import org.springframework.web.bind.annotation.PathVariable;
|
|
10
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
11
|
|
-import org.springframework.web.bind.annotation.RequestMethod;
|
|
12
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
9
|
+import org.springframework.web.bind.annotation.*;
|
|
|
10
|
+
|
|
|
11
|
+import javax.persistence.criteria.CriteriaBuilder;
|
|
13
|
12
|
|
|
14
|
13
|
@RestController
|
|
15
|
14
|
public class PersonController {
|
|
16
|
15
|
@Autowired
|
|
17
|
16
|
PersonService personService;
|
|
18
|
17
|
|
|
19
|
|
- @RequestMapping(value="/person", method= RequestMethod.GET)
|
|
|
18
|
+ @RequestMapping(value="/people", method= RequestMethod.GET)
|
|
20
|
19
|
public ResponseEntity<Iterable<Person>> getPeople() {
|
|
21
|
20
|
Iterable<Person> people = personService.getAllPeople();
|
|
22
|
21
|
return new ResponseEntity<>(people, HttpStatus.OK);
|
|
23
|
22
|
}
|
|
24
|
23
|
|
|
25
|
|
- @RequestMapping(value = "/person/{id}", method = RequestMethod.GET)
|
|
|
24
|
+ @RequestMapping(value = "/people/{id}", method = RequestMethod.GET)
|
|
26
|
25
|
public ResponseEntity<Person> getPersonById(@PathVariable Integer id) {
|
|
27
|
26
|
Person p = personService.findPersonById(id);
|
|
28
|
27
|
return new ResponseEntity<>(p, HttpStatus.OK);
|
|
29
|
28
|
}
|
|
30
|
29
|
|
|
|
30
|
+ @PostMapping("/people")
|
|
|
31
|
+ public ResponseEntity<Person> createPerson(@RequestBody Person p) {
|
|
|
32
|
+ personService.add(p);
|
|
|
33
|
+ return new ResponseEntity<>(p, HttpStatus.CREATED);
|
|
|
34
|
+ }
|
|
31
|
35
|
}
|