Kibret Tecle vor 8 Jahren
Ursprung
Commit
05be509132

+ 32
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/controller/ComputeResultController.java Datei anzeigen

@@ -0,0 +1,32 @@
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
+
14
+@RestController
15
+public class ComputeResultController {
16
+
17
+    private VoteRepository voteRepository;
18
+
19
+    @Autowired
20
+    public ComputeResultController(VoteRepository voteRepository) {
21
+        this.voteRepository = voteRepository;
22
+    }
23
+
24
+    @RequestMapping(value = "/computeresult", method = RequestMethod.GET)
25
+    public ResponseEntity<?> computeResult(@RequestParam Long pollId) {
26
+        VoteResult voteResult = new VoteResult();
27
+        Iterable<Vote> allVotes = voteRepository.findVotesByPoll(pollId);
28
+
29
+        //TODO: Implement algorithm to count votes
30
+        return new ResponseEntity<VoteResult>(voteResult, HttpStatus.OK);
31
+    }
32
+}

+ 23
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/dtos/OptionCount.java Datei anzeigen

@@ -0,0 +1,23 @@
1
+package io.zipcoder.tc_spring_poll_application.dtos;
2
+
3
+public class OptionCount {
4
+        private Long optionId;
5
+        private int count;
6
+
7
+        public Long getOptionId() {
8
+            return optionId;
9
+        }
10
+
11
+        public void setOptionId(Long optionId) {
12
+            this.optionId = optionId;
13
+        }
14
+
15
+        public int getCount() {
16
+            return count;
17
+        }
18
+
19
+        public void setCount(int count) {
20
+            this.count = count;
21
+        }
22
+
23
+}

+ 23
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/dtos/VoteResult.java Datei anzeigen

@@ -0,0 +1,23 @@
1
+package io.zipcoder.tc_spring_poll_application.dtos;
2
+
3
+import java.util.Collection;
4
+public class VoteResult {
5
+    private int totalVotes;
6
+    private Collection<OptionCount> results;
7
+
8
+    public int getTotalVotes() {
9
+        return totalVotes;
10
+    }
11
+
12
+    public void setTotalVotes(int totalVotes) {
13
+        this.totalVotes = totalVotes;
14
+    }
15
+
16
+    public Collection<OptionCount> getResults() {
17
+        return results;
18
+    }
19
+
20
+    public void setResults(Collection<OptionCount> results) {
21
+        this.results = results;
22
+    }
23
+}