|
|
@@ -1,9 +1,9 @@
|
|
1
|
1
|
package io.zipcoder.tc_spring_poll_application.controllers;
|
|
2
|
2
|
|
|
3
|
|
-import io.zipcoder.tc_spring_poll_application.domain.Option;
|
|
4
|
3
|
import io.zipcoder.tc_spring_poll_application.domain.Vote;
|
|
5
|
4
|
import io.zipcoder.tc_spring_poll_application.dtos.VoteResult;
|
|
6
|
5
|
import io.zipcoder.tc_spring_poll_application.repositories.VoteRepository;
|
|
|
6
|
+import io.zipcoder.tc_spring_poll_application.utils.ResultCalculator;
|
|
7
|
7
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
8
|
8
|
import org.springframework.http.HttpStatus;
|
|
9
|
9
|
import org.springframework.http.ResponseEntity;
|
|
|
@@ -38,12 +38,14 @@ public class ComputeResultController {
|
|
38
|
38
|
return new ResponseEntity<>(voteResult, HttpStatus.OK);
|
|
39
|
39
|
}
|
|
40
|
40
|
|
|
41
|
|
- protected VoteResult computeResults(Iterable<Vote> votes) {
|
|
|
41
|
+ private VoteResult computeResults(Iterable<Vote> votes) {
|
|
42
|
42
|
Iterator<Vote> voterator = votes.iterator();
|
|
43
|
|
- VoteResult result = new VoteResult();
|
|
44
|
|
- while(voterator.hasNext()) {
|
|
|
43
|
+
|
|
|
44
|
+ ResultCalculator rc = new ResultCalculator();
|
|
|
45
|
+ while (voterator.hasNext()) {
|
|
45
|
46
|
Vote v = voterator.next();
|
|
|
47
|
+ rc.add(v.getOption());
|
|
46
|
48
|
}
|
|
47
|
|
- return result;
|
|
|
49
|
+ return rc.calculate();
|
|
48
|
50
|
}
|
|
49
|
51
|
}
|