Carolynn Vansant 8 lat temu
rodzic
commit
09c6ba37ac

+ 22
- 0
src/main/java/dtos/OptionCount.java Wyświetl plik

1
+package 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
+}

+ 25
- 0
src/main/java/dtos/VoteResult.java Wyświetl plik

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

+ 28
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/controller/ComputeResultController.java Wyświetl plik

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