|
@@ -44,6 +44,7 @@ public class PollController {
|
44
|
44
|
|
45
|
45
|
@RequestMapping(value="/polls/{pollId}", method=RequestMethod.GET)
|
46
|
46
|
public ResponseEntity<?> getPoll(@PathVariable Long pollId) {
|
|
47
|
+ verifyPoll(pollId);
|
47
|
48
|
Poll p = pollRepository.findOne(pollId);
|
48
|
49
|
return new ResponseEntity<> (p, HttpStatus.OK);
|
49
|
50
|
}
|
|
@@ -53,16 +54,12 @@ public class PollController {
|
53
|
54
|
// Save the entity
|
54
|
55
|
verifyPoll(poll);
|
55
|
56
|
Poll p = pollRepository.save(poll);
|
56
|
|
- return new ResponseEntity<>(HttpStatus.OK);
|
|
57
|
+ return new ResponseEntity<>(p, HttpStatus.OK);
|
57
|
58
|
}
|
58
|
59
|
|
59
|
60
|
@RequestMapping(value="/polls/{pollId}", method=RequestMethod.DELETE)
|
60
|
61
|
public ResponseEntity<?> deletePoll(@PathVariable Long pollId) {
|
61
|
|
- try {
|
62
|
|
- pollRepository.findOne(pollId);
|
63
|
|
- } catch (NullPointerException nullpointer) {
|
64
|
|
- throw new ResourceNotFoundException("Poll Id was not found.");
|
65
|
|
- }
|
|
62
|
+ verifyPoll(pollId);
|
66
|
63
|
pollRepository.delete(pollId);
|
67
|
64
|
return new ResponseEntity<>(HttpStatus.OK);
|
68
|
65
|
}
|
|
@@ -75,4 +72,11 @@ public class PollController {
|
75
|
72
|
}
|
76
|
73
|
}
|
77
|
74
|
|
|
75
|
+ @RequestMapping(method = RequestMethod.GET)
|
|
76
|
+ public void verifyPoll(Long pollId) throws ResourceNotFoundException {
|
|
77
|
+ if (pollRepository.findOne(pollId) == null) {
|
|
78
|
+ throw new ResourceNotFoundException();
|
|
79
|
+ }
|
|
80
|
+ }
|
|
81
|
+
|
78
|
82
|
}
|