|
@@ -1,6 +1,7 @@
|
1
|
1
|
package io.zipcoder.tc_spring_poll_application.controller;
|
2
|
2
|
|
3
|
3
|
import io.zipcoder.tc_spring_poll_application.domain.Poll;
|
|
4
|
+import io.zipcoder.tc_spring_poll_application.exception.ResourceNotFoundException;
|
4
|
5
|
import io.zipcoder.tc_spring_poll_application.repositories.PollRepository;
|
5
|
6
|
import org.springframework.beans.factory.annotation.Autowired;
|
6
|
7
|
import org.springframework.http.HttpHeaders;
|
|
@@ -42,6 +43,7 @@ public class PollController {
|
42
|
43
|
|
43
|
44
|
@RequestMapping(value="/polls/{pollId}", method=RequestMethod.GET)
|
44
|
45
|
public ResponseEntity<?> getPoll(@PathVariable Long pollId) {
|
|
46
|
+ verifyPoll(pollId);
|
45
|
47
|
Poll p = pollRepository.findOne(pollId);
|
46
|
48
|
return new ResponseEntity<> (p, HttpStatus.OK);
|
47
|
49
|
}
|
|
@@ -49,14 +51,24 @@ public class PollController {
|
49
|
51
|
@RequestMapping(value="/polls/{pollId}", method=RequestMethod.PUT)
|
50
|
52
|
public ResponseEntity<?> updatePoll(@RequestBody Poll poll, @PathVariable Long pollId) {
|
51
|
53
|
// Save the entity
|
|
54
|
+ verifyPoll(pollId);
|
52
|
55
|
Poll p = pollRepository.save(poll);
|
53
|
56
|
return new ResponseEntity<>(HttpStatus.OK);
|
54
|
57
|
}
|
55
|
58
|
|
56
|
59
|
@RequestMapping(value="/polls/{pollId}", method=RequestMethod.DELETE)
|
57
|
60
|
public ResponseEntity<?> deletePoll(@PathVariable Long pollId) {
|
|
61
|
+ verifyPoll(pollId);
|
58
|
62
|
pollRepository.delete(pollId);
|
59
|
63
|
return new ResponseEntity<>(HttpStatus.OK);
|
60
|
64
|
}
|
61
|
65
|
|
|
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
|
+ }
|
|
72
|
+ }
|
|
73
|
+
|
62
|
74
|
}
|