-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathPersonController.java
More file actions
52 lines (42 loc) · 1.64 KB
/
PersonController.java
File metadata and controls
52 lines (42 loc) · 1.64 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
package io.zipcoder.crudapp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RequestMapping(value = "person-controller")
@RestController
public class PersonController {
@Autowired
private PersonService service;
@RequestMapping(method = RequestMethod.POST,value = "/create")
public ResponseEntity<Person> create (
@RequestBody Person person
) {
return new ResponseEntity<>(service.create(person), HttpStatus.CREATED);
}
@RequestMapping(method = RequestMethod.GET,value = "/people")
public ResponseEntity<List<Person>> findAll () {
return new ResponseEntity<>(service.readAll(), HttpStatus.OK);
}
@RequestMapping(method = RequestMethod.GET, value = "/people/{id}")
public ResponseEntity<Person> findOne (
@PathVariable Long id
) {
return new ResponseEntity<>(service.read(id), HttpStatus.OK);
}
@RequestMapping(method = RequestMethod.PUT, value = "/update/{id}")
public ResponseEntity<Person> update (
@PathVariable Long id,
@RequestBody Person person
) {
return new ResponseEntity<>(service.update(id, person), HttpStatus.CREATED);
}
@RequestMapping(method = RequestMethod.DELETE, value = "/delete/{id}")
public ResponseEntity<Person> delete (
@PathVariable Long id
) {
return new ResponseEntity<>(service.delete(id), HttpStatus.NO_CONTENT);
}
}