瀏覽代碼

Compute Results Controller

Mitch Taylor 8 年之前
父節點
當前提交
440905b67a

+ 1
- 0
README.md 查看文件

425
         //TODO: Implement algorithm to count votes
425
         //TODO: Implement algorithm to count votes
426
         return new ResponseEntity<VoteResult>(voteResult, HttpStatus.OK);
426
         return new ResponseEntity<VoteResult>(voteResult, HttpStatus.OK);
427
     }
427
     }
428
+}    
428
 ```
429
 ```
429
 
430
 
430
 
431
 

+ 30
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/controller/ComputeResultController.java 查看文件

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