debug de la requete GET http://localhost:8080/api/comments/posts/{post-id}
This commit is contained in:
parent
48427e757a
commit
0d59829eaf
@ -58,7 +58,7 @@ public class CommentController {
|
||||
@GetMapping("/posts/{post-id}")
|
||||
public List<CommentWithAuthor> 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}")
|
||||
|
@ -18,19 +18,21 @@ public interface CommentRepository extends CrudRepository<Comment, Long> {
|
||||
@Query("select post_fk, comment_fk, author_fk from comment_association where comment_fk = :commentId")
|
||||
Optional<CommentIds> 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<CommentWithAuthor> 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<CommentWithAuthor> getCommentsByPostId(Long postId);
|
||||
|
||||
@Modifying
|
||||
@Query("delete from comment_association where comment_fk = :commentId")
|
||||
|
@ -33,8 +33,8 @@ public class CommentService {
|
||||
return commentRepository.findAll();
|
||||
}
|
||||
|
||||
public List<CommentWithAuthor> getCommentsByCommentId(Long commentId) {
|
||||
return commentRepository.getCommentsByCommentId(commentId);
|
||||
public List<CommentWithAuthor> getCommentsByPostId(Long postId) {
|
||||
return commentRepository.getCommentsByPostId(postId);
|
||||
}
|
||||
|
||||
public void associateCommentToPostAndAuthor(UUID authorId, Long postId, Long commentId) {
|
||||
|
Loading…
Reference in New Issue
Block a user