File tree 1 file changed +11
-1
lines changed
bloque_3/spring_database/bd_ejem9/src/main/java/es/codeurjc/db
1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -47,12 +47,22 @@ public Blog deleteBlog(@PathVariable Long id) {
47
47
return blog ;
48
48
}
49
49
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
51
52
@ DeleteMapping ("/comments/{id}" )
52
53
public Comment deleteComment (@ PathVariable Long id ) {
53
54
Comment comment = commentRepository .findById (id ).orElseThrow ();
54
55
commentRepository .deleteById (id );
55
56
return comment ;
56
57
}
57
58
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
+
58
68
}
You can’t perform that action at this time.
0 commit comments