|
@@ -8,14 +8,17 @@ import org.springframework.http.HttpStatus;
|
8
|
8
|
import org.springframework.http.ResponseEntity;
|
9
|
9
|
import org.springframework.web.bind.annotation.*;
|
10
|
10
|
|
11
|
|
-import javax.xml.ws.Response;
|
12
|
|
-
|
13
|
11
|
@RestController
|
14
|
12
|
public class HomeController {
|
15
|
13
|
|
16
|
|
- @Autowired
|
|
14
|
+ private final
|
17
|
15
|
HomeService homeService;
|
18
|
16
|
|
|
17
|
+ @Autowired
|
|
18
|
+ public HomeController(HomeService homeService) {
|
|
19
|
+ this.homeService = homeService;
|
|
20
|
+ }
|
|
21
|
+
|
19
|
22
|
@PostMapping(value = "/homes")
|
20
|
23
|
public ResponseEntity<Home> createHome(@RequestBody Home home) {
|
21
|
24
|
homeService.addHome(home);
|
|
@@ -31,20 +34,23 @@ public class HomeController {
|
31
|
34
|
return new ResponseEntity<>(homes, HttpStatus.OK);
|
32
|
35
|
}
|
33
|
36
|
|
|
37
|
+ // these get methods are throwing ambiguous handler methods
|
|
38
|
+ // Illegal state exception - fixed by specifying URL's better
|
|
39
|
+
|
34
|
40
|
@GetMapping(value = "/homes/{id}")
|
35
|
41
|
public ResponseEntity<Home> getHomeById(@PathVariable Integer id) {
|
36
|
42
|
Home h = homeService.findHomeById(id);
|
37
|
43
|
return new ResponseEntity<>(h, HttpStatus.OK);
|
38
|
44
|
}
|
39
|
45
|
|
40
|
|
- @GetMapping(value = "/homes/{homeNumber}")
|
41
|
|
- public ResponseEntity<Home> getHomeByHomeNumber(@PathVariable String homeNumer) {
|
42
|
|
- Home h = homeService.findHomeByHomeNumber(homeNumer);
|
|
46
|
+ @GetMapping(value = "/homes/homenumber/{homeNumber}")
|
|
47
|
+ public ResponseEntity<Home> getHomeByHomeNumber(@PathVariable String homeNumber) {
|
|
48
|
+ Home h = homeService.findHomeByHomeNumber(homeNumber);
|
43
|
49
|
return new ResponseEntity<>(h, HttpStatus.OK);
|
44
|
50
|
}
|
45
|
51
|
|
46
|
52
|
// Test this
|
47
|
|
- @GetMapping(value = "/homes/{address}")
|
|
53
|
+ @GetMapping(value = "/homes/address/{address}")
|
48
|
54
|
public ResponseEntity<Home> getHomeByAddress(@PathVariable String address) {
|
49
|
55
|
Home h = homeService.findHomeByAddress(address);
|
50
|
56
|
return new ResponseEntity<>(h, HttpStatus.OK);
|