mpierse пре 7 година
родитељ
комит
56ab84fe04

+ 24
- 0
src/main/java/dtos/OptionCount.java Прегледај датотеку

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

+ 25
- 0
src/main/java/dtos/VoteResult.java Прегледај датотеку

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

+ 9
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/controller/VoteController.java Прегледај датотеку

@@ -34,5 +34,14 @@ public class VoteController {
34 34
         return new ResponseEntity<>(null, responseHeaders, HttpStatus.CREATED);
35 35
     }
36 36
 
37
+    @RequestMapping(value="/polls/votes", method=RequestMethod.GET)
38
+    public Iterable<Vote> getAllVotes() {
39
+        return voteRepository.findAll();
40
+    }
41
+
42
+    @RequestMapping(value="/polls/{pollId}/votes", method=RequestMethod.GET)
43
+    public Iterable<Vote> getVote(@PathVariable Long pollId) {
44
+        return voteRepository.findVotesByPoll(pollId);
45
+    }
37 46
     
38 47
 }

+ 7
- 1
src/main/java/io/zipcoder/tc_spring_poll_application/repositories/VoteRepository.java Прегледај датотеку

@@ -1,7 +1,13 @@
1 1
 package io.zipcoder.tc_spring_poll_application.repositories;
2 2
 
3 3
 import io.zipcoder.tc_spring_poll_application.domain.Vote;
4
+import org.springframework.data.jpa.repository.Query;
4 5
 import org.springframework.data.repository.CrudRepository;
5 6
 
6 7
 public interface VoteRepository extends CrudRepository<Vote, Long> {
7
-}
8
+    @Query(value = "SELECT v.* " +
9
+            "FROM Option o, Vote v " +
10
+            "WHERE o.POLL_ID = ?1 " +
11
+            "AND v.OPTION_ID = o.OPTION_ID", nativeQuery = true)
12
+    public Iterable<Vote> findVotesByPoll(Long pollId);
13
+}