瀏覽代碼

actually complete

Brandon Defrancis 5 年之前
父節點
當前提交
139e4a673a

+ 4
- 4
src/main/java/io/zipcoder/tc_spring_poll_application/controller/PollController.java 查看文件

@@ -4,6 +4,8 @@ import io.zipcoder.tc_spring_poll_application.domain.Poll;
4 4
 import io.zipcoder.tc_spring_poll_application.exception.ResourceNotFoundException;
5 5
 import io.zipcoder.tc_spring_poll_application.repositories.PollRepository;
6 6
 import org.springframework.beans.factory.annotation.Autowired;
7
+import org.springframework.data.domain.Page;
8
+import org.springframework.data.domain.Pageable;
7 9
 import org.springframework.http.HttpHeaders;
8 10
 import org.springframework.http.HttpStatus;
9 11
 import org.springframework.http.ResponseEntity;
@@ -18,16 +20,14 @@ public class PollController {
18 20
 
19 21
     private PollRepository pollRepository;
20 22
 
21
-
22
-
23 23
     @Autowired
24 24
     public PollController(PollRepository pollRepository) {
25 25
         this.pollRepository = pollRepository;
26 26
     }
27 27
 
28 28
     @RequestMapping(value="/polls", method= RequestMethod.GET)
29
-    public ResponseEntity<Iterable<Poll>> getAllPolls() {
30
-        Iterable<Poll> allPolls = pollRepository.findAll();
29
+    public ResponseEntity<Page<Poll>> getAllPolls(Pageable pageable) {
30
+        Page<Poll> allPolls = pollRepository.findAll(pageable);
31 31
         return new ResponseEntity<>(allPolls, HttpStatus.OK);
32 32
     }
33 33
 

+ 5
- 1
src/main/java/io/zipcoder/tc_spring_poll_application/dto/error/RestExceptionHandler.java 查看文件

@@ -18,8 +18,12 @@ import java.util.List;
18 18
 @ControllerAdvice
19 19
 public class RestExceptionHandler {
20 20
 
21
+    private final MessageSource messageSource;
22
+
21 23
     @Autowired
22
-    private MessageSource messageSource;
24
+    public RestExceptionHandler(MessageSource messageSource) {
25
+        this.messageSource = messageSource;
26
+    }
23 27
 
24 28
     @ExceptionHandler(ResourceNotFoundException.class)
25 29
     public ResponseEntity<?> handleResourceNotFoundException(ResourceNotFoundException rnfe, HttpServletRequest request) {