From 0d59829eaffc52fef2a35eb424163405ac4bfd1c Mon Sep 17 00:00:00 2001 From: Guams Date: Sat, 18 Jan 2025 18:36:20 +0100 Subject: [PATCH] debug de la requete GET http://localhost:8080/api/comments/posts/{post-id} --- .../review/controller/CommentController.java | 2 +- .../guams/review/model/CommentRepository.java | 28 ++++++++++--------- .../guams/review/service/CommentService.java | 4 +-- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/guams/review/controller/CommentController.java b/src/main/java/com/guams/review/controller/CommentController.java index c602d13..86f71eb 100644 --- a/src/main/java/com/guams/review/controller/CommentController.java +++ b/src/main/java/com/guams/review/controller/CommentController.java @@ -58,7 +58,7 @@ public class CommentController { @GetMapping("/posts/{post-id}") public List listCommentsByPostId(@PathVariable("post-id") Long postId) { postService.findById(postId).orElseThrow(() -> new NotFoundException("Post not found")); - return commentService.getCommentsByCommentId(postId); + return commentService.getCommentsByPostId(postId); } @PutMapping("/{id}") diff --git a/src/main/java/com/guams/review/model/CommentRepository.java b/src/main/java/com/guams/review/model/CommentRepository.java index 18fea4b..c10d42a 100644 --- a/src/main/java/com/guams/review/model/CommentRepository.java +++ b/src/main/java/com/guams/review/model/CommentRepository.java @@ -18,19 +18,21 @@ public interface CommentRepository extends CrudRepository { @Query("select post_fk, comment_fk, author_fk from comment_association where comment_fk = :commentId") Optional getCommentIdsByCommentId(Long commentId); - @Query(value = " SELECT DISTINCT " + - "c.id AS id, " + - "a.id AS author_id, " + - "a.name AS author_name, " + - "a.profile_picture AS profile_picture, " + - "a.role AS author_role, " + - "c.content AS content, " + - "c.comment_date AS comment_date, " + - "c.is_updated AS is_updated " + - "FROM comment c " + - "JOIN comment_association ca ON ca.post_fk = :postId " + - "JOIN author a ON ca.author_fk = a.id") - List getCommentsByCommentId(Long postId); + @Query(value = "SELECT DISTINCT " + + " c.id AS id, " + + " a.id AS author_id, " + + " a.name AS author_name, " + + " a.profile_picture AS profile_picture, " + + " a.role AS author_role, " + + " c.content AS content, " + + " c.comment_date AS comment_date, " + + " c.is_updated AS is_updated " + + " FROM comment c" + + " JOIN comment_association ca ON ca.comment_fk = c.id" + + " JOIN post p ON p.id = ca.post_fk" + + " JOIN author a ON ca.author_fk = a.id" + + " WHERE p.id = 3") + List getCommentsByPostId(Long postId); @Modifying @Query("delete from comment_association where comment_fk = :commentId") diff --git a/src/main/java/com/guams/review/service/CommentService.java b/src/main/java/com/guams/review/service/CommentService.java index a1a8b08..49ab0fc 100644 --- a/src/main/java/com/guams/review/service/CommentService.java +++ b/src/main/java/com/guams/review/service/CommentService.java @@ -33,8 +33,8 @@ public class CommentService { return commentRepository.findAll(); } - public List getCommentsByCommentId(Long commentId) { - return commentRepository.getCommentsByCommentId(commentId); + public List getCommentsByPostId(Long postId) { + return commentRepository.getCommentsByPostId(postId); } public void associateCommentToPostAndAuthor(UUID authorId, Long postId, Long commentId) {