Trinh Tong 7 лет назад
Родитель
Сommit
95d4be0255

+ 2
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/controller/ComputeResultController.java Просмотреть файл

@@ -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.Vote;
4
+import io.zipcoder.tc_spring_poll_application.dtos.VoteResult;
4 5
 import io.zipcoder.tc_spring_poll_application.repositories.VoteRepository;
5 6
 import org.springframework.beans.factory.annotation.Autowired;
6 7
 import org.springframework.http.HttpStatus;
@@ -28,4 +29,5 @@ public class ComputeResultController {
28 29
         //TODO: Implement algorithm to count votes
29 30
         return new ResponseEntity<VoteResult>(voteResult, HttpStatus.OK);
30 31
 
32
+    }
31 33
 }

+ 9
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/controller/PollController.java Просмотреть файл

@@ -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;
@@ -59,4 +60,12 @@ public class PollController {
59 60
         return new ResponseEntity<>(HttpStatus.OK);
60 61
     }
61 62
 
63
+
64
+    @RequestMapping(method = RequestMethod.GET)
65
+    public void verifyPoll(Poll poll) throws ResourceNotFoundException {
66
+        if (pollRepository.findOne(poll.getId()) == null) {
67
+            throw new ResourceNotFoundException();
68
+        }
69
+    }
70
+
62 71
 }

+ 19
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/exception/ResourceNotFoundException.java Просмотреть файл

@@ -0,0 +1,19 @@
1
+package io.zipcoder.tc_spring_poll_application.exception;
2
+
3
+import org.springframework.http.HttpStatus;
4
+import org.springframework.web.bind.annotation.ResponseStatus;
5
+
6
+@ResponseStatus(HttpStatus.NOT_FOUND)
7
+public class ResourceNotFoundException extends RuntimeException {
8
+
9
+    public ResourceNotFoundException() {
10
+    }
11
+
12
+    public ResourceNotFoundException(String message) {
13
+        super(message);
14
+    }
15
+
16
+    public ResourceNotFoundException(String message, Throwable cause) {
17
+        super(message, cause);
18
+    }
19
+}