This commit is contained in:
Guams 2025-01-18 18:36:20 +01:00
parent 48427e757a
commit 0d59829eaf
3 changed files with 18 additions and 16 deletions

View File

@ -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}")

View File

@ -28,9 +28,11 @@ public interface CommentRepository extends CrudRepository<Comment, Long> {
" 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);
" 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")

View File

@ -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) {