Selaa lähdekoodia

computeresult

Seth 6 vuotta sitten
vanhempi
commit
17ad1c71ac

+ 33
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/controller/ComputeResultController.java Näytä tiedosto

@@ -0,0 +1,33 @@
1
+package io.zipcoder.tc_spring_poll_application.controller;
2
+
3
+import io.zipcoder.tc_spring_poll_application.domain.Vote;
4
+import io.zipcoder.tc_spring_poll_application.dtos.VoteResult;
5
+import io.zipcoder.tc_spring_poll_application.repositories.VoteRepository;
6
+import org.springframework.beans.factory.annotation.Autowired;
7
+import org.springframework.http.HttpStatus;
8
+import org.springframework.http.ResponseEntity;
9
+import org.springframework.web.bind.annotation.RequestMapping;
10
+import org.springframework.web.bind.annotation.RequestMethod;
11
+import org.springframework.web.bind.annotation.RequestParam;
12
+import org.springframework.web.bind.annotation.RestController;
13
+    @RestController
14
+    public class ComputeResultController {
15
+
16
+        private VoteRepository voteRepository;
17
+
18
+        @Autowired
19
+        public ComputeResultController(VoteRepository voteRepository) {
20
+            this.voteRepository = voteRepository;
21
+        }
22
+
23
+        @RequestMapping(value = "/computeresult", method = RequestMethod.GET)
24
+        public ResponseEntity<?> computeResult(@RequestParam Long pollId) {
25
+            VoteResult voteResult = new VoteResult();
26
+            Iterable<Vote> allVotes = voteRepository.findVotesByPoll(pollId);
27
+
28
+            //TODO: Implement algorithm to count votes
29
+            return new ResponseEntity<VoteResult>(voteResult, HttpStatus.OK);
30
+        }
31
+}
32
+
33
+