|
@@ -3,12 +3,19 @@ package com.ziplinegreen.vault.Controller;
|
3
|
3
|
import com.ziplinegreen.vault.Model.Post;
|
4
|
4
|
import com.ziplinegreen.vault.Service.PostService;
|
5
|
5
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
6
|
+import org.springframework.data.domain.Page;
|
|
7
|
+import org.springframework.data.domain.PageImpl;
|
|
8
|
+import org.springframework.data.domain.PageRequest;
|
|
9
|
+import org.springframework.data.domain.Pageable;
|
6
|
10
|
import org.springframework.http.ResponseEntity;
|
7
|
11
|
import org.springframework.messaging.handler.annotation.MessageMapping;
|
8
|
12
|
import org.springframework.messaging.handler.annotation.SendTo;
|
9
|
13
|
import org.springframework.web.bind.annotation.*;
|
10
|
14
|
|
11
|
|
-import java.util.Collection;
|
|
15
|
+
|
|
16
|
+import java.util.*;
|
|
17
|
+import java.util.stream.Collectors;
|
|
18
|
+import java.util.stream.StreamSupport;
|
12
|
19
|
|
13
|
20
|
@CrossOrigin
|
14
|
21
|
@RestController
|
|
@@ -33,9 +40,22 @@ public class PostController {
|
33
|
40
|
}
|
34
|
41
|
|
35
|
42
|
|
|
43
|
+// @GetMapping("/posts/all")
|
|
44
|
+// public Iterable<Post> getAllPosts() {
|
|
45
|
+// return postService.getAllPosts();
|
|
46
|
+// }
|
|
47
|
+
|
36
|
48
|
@GetMapping("/posts/all")
|
37
|
|
- public Iterable<Post> getAllPosts() {
|
38
|
|
- return postService.getAllPosts();
|
|
49
|
+ Page<Post> pageAllPosts(Pageable pageable) {
|
|
50
|
+ Iterable<Post> posts = postService.getAllPosts();
|
|
51
|
+ List<Post> postList = StreamSupport.stream(posts.spliterator(), false)
|
|
52
|
+ .collect(Collectors.toList());
|
|
53
|
+ Collections.reverse(postList);
|
|
54
|
+
|
|
55
|
+ int start = (int)pageable.getOffset();
|
|
56
|
+ int end = (start + pageable.getPageSize()) > postList.size() ? postList.size() : (start + pageable.getPageSize());
|
|
57
|
+
|
|
58
|
+ return new PageImpl<Post>(postList.subList(start,end),pageable, postList.size());
|
39
|
59
|
}
|
40
|
60
|
|
41
|
61
|
@GetMapping("/posts/id/{userId}")
|