Keith Brinker 8 лет назад
Родитель
Сommit
a8425a90e0

+ 12
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/controller/VoteController.java Просмотреть файл

@@ -2,6 +2,8 @@ package io.zipcoder.tc_spring_poll_application.controller;
2 2
 
3 3
 import io.zipcoder.tc_spring_poll_application.domain.Vote;
4 4
 import io.zipcoder.tc_spring_poll_application.repositories.VoteRepository;
5
+import org.springframework.data.jpa.repository.Query;
6
+import org.springframework.data.repository.CrudRepository;
5 7
 import org.springframework.http.HttpHeaders;
6 8
 import org.springframework.http.HttpStatus;
7 9
 import org.springframework.http.ResponseEntity;
@@ -26,6 +28,16 @@ public class VoteController {
26 28
                     fromCurrentRequest().path("/{id}").buildAndExpand(vote.getId()).toUri());
27 29
             return new ResponseEntity<>(null, responseHeaders, HttpStatus.CREATED);
28 30
         }
31
+
32
+
33
+    public interface VoteRepository extends CrudRepository<Vote, Long> {
34
+        @Query(value = "SELECT v.* " +
35
+                "FROM Option o, Vote v " +
36
+                "WHERE o.POLL_ID = ?1 " +
37
+                "AND v.OPTION_ID = o.OPTION_ID", nativeQuery = true)
38
+        public Iterable<Vote> findVotesByPoll(Long pollId);
29 39
     }
30 40
 
41
+}
42
+
31 43