@Override public void likeComment(String postId, String commentId) { UUID commentUUID = UUID.fromString(commentId); Integer numberOfLikes = cassandraCommentRepository.getNumberOfLikes(UUID.fromString(postId), commentUUID); cassandraCommentRepository.likeComment(++numberOfLikes, commentUUID); }
@Override public Post getPost(String postId) { CassandraPost foundPost = cassandraPostRepository.findOne(UUID.fromString(postId)); List<CassandraComment> commentsForPost = cassandraCommentRepository.findByPostId(foundPost.getId()); return foundPost.convertToPost(commentsForPost); }
@Override public List<Post> getPostsWithoutComments() { List<CassandraPost> postReturnedFromDatabase = (List<CassandraPost>) cassandraPostRepository.findAll(); List<Post> collect = postReturnedFromDatabase .stream() .map( cp -> cp.convertToPost( cassandraCommentRepository.getNumberOfCommentsForPost(cp.getId()))) .collect(Collectors.toList()); return collect; }
@Override public List<Post> getExistingPosts() { Iterable<CassandraPost> cassandraPosts = cassandraPostRepository.findAll(); List<CassandraComment> cassandraComments = (List<CassandraComment>) cassandraCommentRepository.findAll(); List<Post> posts = new ArrayList<>(); for (CassandraPost cassandraPost : cassandraPosts) { List<CassandraComment> commentsForPost = cassandraComments .stream() .filter(cc -> cassandraPost.getId().equals(cc.getPostId())) .collect(Collectors.toList()); Post post = new Post( cassandraPost.getId().toString(), cassandraPost.getMessage(), CassandraComment.convertToCommentList(commentsForPost)); posts.add(post); } return posts; }
@Override public Comment saveCommentForPost(String postId, Comment comment) { CassandraComment cassandraComment = new CassandraComment(comment); cassandraComment.setPostId(UUID.fromString(postId)); return cassandraCommentRepository.save(cassandraComment).convert(); }