3 endpoints complete for comments -> get all comments, get by id, get by slug

This commit is contained in:
2026-01-03 22:13:13 +00:00
parent 95286ae6dd
commit 1358b8981c
2 changed files with 33 additions and 27 deletions

View File

@@ -20,9 +20,8 @@ public class CommentsController {
@GetMapping("/{page_slug}")
public List<Comments> getAllCommentsBySlug(@PathVariable String page_slug) {
List<Comments> allComments = commentsService;
List<Comments> allComments = commentsService.getAllCommentsBySlug(page_slug);
return allComments;
}
@@ -31,4 +30,9 @@ public class CommentsController {
return commentsService.getCommentById(id);
}
@GetMapping("/comments/items")
public List<Comments> getAllComments() {
return commentsService.getAllComments();
}
}

View File

@@ -23,9 +23,11 @@ public class CommentsService {
public List<Comments> getAllCommentsBySlug(String 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()))
.toList();
.collect(Collectors.toList());
return filteredComments;
}
public Comments getCommentById(Long id) {