Once comments are added, they must be visible when the user opens the blog. This scenario is straightforward. Since comments are nested objects of a blog, when we read a blog with the following API, all its comments are also available as part of the blog object:
Optional<Blog> blogObj = blogRepository.findById(blogId); if(blogObj.isPresent()) { return blogObj.get(); }else { return null; }
The findById method is provided out of the box by a default repository implementation, available during runtime. We pass blogId, and it will fetch all details of the blog along with comments (as nested objects).
The second scenario for reading comment is the admin user opens the manage-comment page, where ...