Bladeren bron

added a get for posts for timeline, working on method to filte those posts

Lauren Green 5 jaren geleden
bovenliggende
commit
cbf0ceff3e
1 gewijzigde bestanden met toevoegingen van 16 en 0 verwijderingen
  1. 16
    0
      src/main/java/rocks/zipcode/io/web/rest/PostResource.java

+ 16
- 0
src/main/java/rocks/zipcode/io/web/rest/PostResource.java Bestand weergeven

@@ -16,6 +16,7 @@ import java.net.URISyntaxException;
16 16
 
17 17
 import java.util.List;
18 18
 import java.util.Optional;
19
+import java.util.stream.Collectors;
19 20
 
20 21
 /**
21 22
  * REST controller for managing Post.
@@ -116,4 +117,19 @@ public class PostResource {
116 117
         postRepository.deleteById(id);
117 118
         return ResponseEntity.ok().headers(HeaderUtil.createEntityDeletionAlert(ENTITY_NAME, id.toString())).build();
118 119
     }
120
+
121
+    @GetMapping("/timeline")
122
+    @Timed
123
+    public List<Post> getPostsForUserTimeline() {
124
+        log.debug("REST request to get all Posts");
125
+        return postRepository.findAll().stream()
126
+            .filter(this::isViewable)
127
+            .collect(Collectors.toList());
128
+    }
129
+
130
+    private boolean isViewable(Post post) {
131
+        return (post.getPrivacySetting().isPublicView()) ||
132
+            (post.getPrivacySetting().isCohortView() && post.getPoster().getCohort().equals(thisUserProfile.getCohort())) ||
133
+            (post.getPrivacySetting().isEmployerView() && post.getPoster().getEmployer().equals(thisUserProfile.getEmployer()));
134
+    }
119 135
 }