-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathHomeController.java
More file actions
62 lines (48 loc) · 2.43 KB
/
HomeController.java
File metadata and controls
62 lines (48 loc) · 2.43 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
53
54
55
56
57
58
59
60
61
62
package io.zipcoder.persistenceapp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
public class HomeController {
private HomeService homeService;
@Autowired
public HomeController(HomeService homeService) {
this.homeService = homeService;
}
@RequestMapping(value = "/homes", method = RequestMethod.POST)
public ResponseEntity<Home> createPerson(@RequestBody Home home) {
return new ResponseEntity<>(this.homeService.insertHome(home), HttpStatus.CREATED);
}
@RequestMapping(value = "/homeUp", method = RequestMethod.PUT)
public ResponseEntity<Home> updateHome(@RequestBody Home homeUpdated) {
return new ResponseEntity<>(this.homeService.updateHome(homeUpdated), HttpStatus.OK);
}
@RequestMapping(value = "/home/{id}", method = RequestMethod.DELETE)
public ResponseEntity<Home> deletePerson(@PathVariable Long id) {
this.homeService.removeHome(id);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
@RequestMapping(value = "/home/delete-list", method = RequestMethod.DELETE)
public ResponseEntity<List<Home>> deleteManyHomes(@RequestBody List<Home> homes) {
this.homeService.removeHomes(homes);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
@RequestMapping(value = "/home/id/{id}", method = RequestMethod.GET)
public ResponseEntity<Home> findHomeById(@PathVariable Long id) {
return new ResponseEntity<>(this.homeService.findHomeById(id), HttpStatus.OK);
}
@RequestMapping(value = "/home", method = RequestMethod.GET)
public ResponseEntity<List<Home>> findAllHomes() {
return new ResponseEntity<>(this.homeService.findAllHomes(), HttpStatus.OK);
}
@RequestMapping(value = "/home/home-number/{homeNumber}", method = RequestMethod.GET)
public ResponseEntity<Home> findHomeByHomeNumber(@PathVariable String homeNumber) {
return new ResponseEntity<>(this.homeService.findHomeByHomeNumber(homeNumber), HttpStatus.OK);
}
@RequestMapping(value = "/home/address/{address}", method = RequestMethod.GET)
public ResponseEntity<Home> findHomeByAddress(@PathVariable String address) {
return new ResponseEntity<>(this.homeService.findHomeByAddress(address), HttpStatus.OK);
}
}