3 endpoints complete for comments -> get all comments, get by id, get by slug
This commit is contained in:
@@ -18,17 +18,21 @@ public class CommentsController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private CommentsService commentsService;
|
private CommentsService commentsService;
|
||||||
|
|
||||||
@GetMapping("/{page_slug}")
|
@GetMapping("/{page_slug}")
|
||||||
public List<Comments> getAllCommentsBySlug(@PathVariable String page_slug) {
|
public List<Comments> getAllCommentsBySlug(@PathVariable String page_slug) {
|
||||||
|
List<Comments> allComments = commentsService.getAllCommentsBySlug(page_slug);
|
||||||
List<Comments> allComments = commentsService;
|
return allComments;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/comments/item/{id}")
|
@GetMapping("/comments/item/{id}")
|
||||||
public Comments getCommentById(@PathVariable Long id) {
|
public Comments getCommentById(@PathVariable Long id) {
|
||||||
return commentsService.getCommentById(id);
|
return commentsService.getCommentById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/comments/items")
|
||||||
|
public List<Comments> getAllComments() {
|
||||||
|
return commentsService.getAllComments();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,26 +11,28 @@ import java.util.stream.*;
|
|||||||
public class CommentsService {
|
public class CommentsService {
|
||||||
private static final Logger logger = System.getLogger(CommentsService.class.getName());
|
private static final Logger logger = System.getLogger(CommentsService.class.getName());
|
||||||
|
|
||||||
private final CommentsRepository commentsRepository;
|
private final CommentsRepository commentsRepository;
|
||||||
|
|
||||||
public CommentsService(CommentsRepository commentsRepository) {
|
public CommentsService(CommentsRepository commentsRepository) {
|
||||||
this.commentsRepository = commentsRepository;
|
this.commentsRepository = commentsRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Comments> getAllComments() {
|
public List<Comments> getAllComments() {
|
||||||
return commentsRepository.findAll();
|
return commentsRepository.findAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Comments> getAllCommentsBySlug(String page_slug) {
|
public List<Comments> getAllCommentsBySlug(String page_slug) {
|
||||||
logger.log(System.Logger.Level.INFO, "Entering getAllCommentsBySlug with slug: " + page_slug);
|
logger.log(System.Logger.Level.INFO, "Entering getAllCommentsBySlug with slug: " + page_slug);
|
||||||
return commentsRepository.findAll().stream()
|
List<Comments> allComments = commentsRepository.findAll();
|
||||||
|
List<Comments> filteredComments = allComments.stream()
|
||||||
.filter(comment -> page_slug.equals(comment.getPageSlug()))
|
.filter(comment -> page_slug.equals(comment.getPageSlug()))
|
||||||
.toList();
|
.collect(Collectors.toList());
|
||||||
}
|
return filteredComments;
|
||||||
|
}
|
||||||
public Comments getCommentById(Long id) {
|
|
||||||
logger.log(System.Logger.Level.INFO, "Entering getCommentById with id: " + id);
|
public Comments getCommentById(Long id) {
|
||||||
return commentsRepository.findById(id).get();
|
logger.log(System.Logger.Level.INFO, "Entering getCommentById with id: " + id);
|
||||||
}
|
return commentsRepository.findById(id).get();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user