|
@@ -43,6 +43,7 @@ public class PollController {
|
43
|
43
|
|
44
|
44
|
@RequestMapping(value="/polls/{pollId}", method=RequestMethod.GET)
|
45
|
45
|
public ResponseEntity<?> getPoll(@PathVariable Long pollId) {
|
|
46
|
+ verifyPoll(pollId);
|
46
|
47
|
Poll p = pollRepository.findOne(pollId);
|
47
|
48
|
return new ResponseEntity<> (p, HttpStatus.OK);
|
48
|
49
|
}
|
|
@@ -50,17 +51,24 @@ public class PollController {
|
50
|
51
|
@RequestMapping(value="/polls/{pollId}", method=RequestMethod.PUT)
|
51
|
52
|
public ResponseEntity<?> updatePoll(@RequestBody Poll poll, @PathVariable Long pollId) {
|
52
|
53
|
// Save the entity
|
|
54
|
+ verifyPoll(pollId);
|
53
|
55
|
Poll p = pollRepository.save(poll);
|
54
|
56
|
return new ResponseEntity<>(HttpStatus.OK);
|
55
|
57
|
}
|
56
|
58
|
|
57
|
59
|
@RequestMapping(value="/polls/{pollId}", method=RequestMethod.DELETE)
|
58
|
60
|
public ResponseEntity<?> deletePoll(@PathVariable Long pollId) {
|
|
61
|
+ verifyPoll(pollId);
|
59
|
62
|
pollRepository.delete(pollId);
|
60
|
63
|
return new ResponseEntity<>(HttpStatus.OK);
|
61
|
64
|
}
|
62
|
65
|
|
63
|
|
- public void verifyPoll(){
|
|
66
|
+ // @RequestMapping(value = "/polls/{pollId}", method = RequestMethod.GET)
|
|
67
|
+ public void verifyPoll(Long pollId) throws ResourceNotFoundException{
|
|
68
|
+
|
|
69
|
+ if(pollRepository.findOne(pollId) == null){
|
|
70
|
+ throw new ResourceNotFoundException();
|
|
71
|
+ }
|
64
|
72
|
}
|
65
|
73
|
|
66
|
74
|
}
|