Browse Source

actually complete

Brandon Defrancis 5 years ago
parent
commit
139e4a673a

+ 4
- 4
src/main/java/io/zipcoder/tc_spring_poll_application/controller/PollController.java View File

4
 import io.zipcoder.tc_spring_poll_application.exception.ResourceNotFoundException;
4
 import io.zipcoder.tc_spring_poll_application.exception.ResourceNotFoundException;
5
 import io.zipcoder.tc_spring_poll_application.repositories.PollRepository;
5
 import io.zipcoder.tc_spring_poll_application.repositories.PollRepository;
6
 import org.springframework.beans.factory.annotation.Autowired;
6
 import org.springframework.beans.factory.annotation.Autowired;
7
+import org.springframework.data.domain.Page;
8
+import org.springframework.data.domain.Pageable;
7
 import org.springframework.http.HttpHeaders;
9
 import org.springframework.http.HttpHeaders;
8
 import org.springframework.http.HttpStatus;
10
 import org.springframework.http.HttpStatus;
9
 import org.springframework.http.ResponseEntity;
11
 import org.springframework.http.ResponseEntity;
18
 
20
 
19
     private PollRepository pollRepository;
21
     private PollRepository pollRepository;
20
 
22
 
21
-
22
-
23
     @Autowired
23
     @Autowired
24
     public PollController(PollRepository pollRepository) {
24
     public PollController(PollRepository pollRepository) {
25
         this.pollRepository = pollRepository;
25
         this.pollRepository = pollRepository;
26
     }
26
     }
27
 
27
 
28
     @RequestMapping(value="/polls", method= RequestMethod.GET)
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
         return new ResponseEntity<>(allPolls, HttpStatus.OK);
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 View File

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