Skip to content

Commit 5ad1ec9

Browse files
committed
Fix bd_ejem9
1 parent 981be86 commit 5ad1ec9

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

bloque_3/spring_database/bd_ejem9/src/main/java/es/codeurjc/db/BlogController.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,22 @@ public Blog deleteBlog(@PathVariable Long id) {
4747
return blog;
4848
}
4949

50-
//A comment only can be deleted if it has no associated blog
50+
// A comment only can be deleted if it has no associated blog
51+
// This method doesn't work
5152
@DeleteMapping("/comments/{id}")
5253
public Comment deleteComment(@PathVariable Long id) {
5354
Comment comment = commentRepository.findById(id).orElseThrow();
5455
commentRepository.deleteById(id);
5556
return comment;
5657
}
5758

59+
@DeleteMapping("/blogs/{blogId}/comments/{commentId}")
60+
public Comment deleteComment(@PathVariable Long blogId, @PathVariable Long commentId) {
61+
Blog blog = blogRepository.findById(blogId).orElseThrow();
62+
Comment comment = commentRepository.findById(commentId).orElseThrow();
63+
blog.getComments().remove(comment);
64+
commentRepository.deleteById(commentId);
65+
return comment;
66+
}
67+
5868
}

0 commit comments

Comments
 (0)