@@ -21,14 +21,16 @@ public class PostController {
21
21
private final UpdatePost updatePost ;
22
22
private final FindPostById findPostById ;
23
23
private final SearchPosts searchPosts ;
24
+ private final DeletePostById deletePostById ;
24
25
private final PostWebMapper postWebMapper ;
25
26
private final ObjectMapper objectMapper ;
26
27
27
- public PostController (CreatePost createPost , UpdatePost updatePost , FindPostById findPostById , SearchPosts searchPosts , PostWebMapper postWebMapper , ObjectMapper objectMapper ) {
28
+ public PostController (CreatePost createPost , UpdatePost updatePost , FindPostById findPostById , SearchPosts searchPosts , DeletePostById deletePostById , PostWebMapper postWebMapper , ObjectMapper objectMapper ) {
28
29
this .createPost = createPost ;
29
30
this .updatePost = updatePost ;
30
31
this .findPostById = findPostById ;
31
32
this .searchPosts = searchPosts ;
33
+ this .deletePostById = deletePostById ;
32
34
this .postWebMapper = postWebMapper ;
33
35
this .objectMapper = objectMapper ;
34
36
}
@@ -72,6 +74,12 @@ public ResponseEntity<List<PostDTO>> searchPosts(
72
74
return ResponseEntity .ok (postDTOs );
73
75
}
74
76
77
+ @ DeleteMapping ("/{id}" )
78
+ public ResponseEntity deletePost (@ PathVariable ("id" ) Long id ) {
79
+ deletePostById .execute (id );
80
+ return ResponseEntity .noContent ().build ();
81
+ }
82
+
75
83
private Post getPatchedPost (JsonNode patch , Post existingPost ) throws JsonProcessingException {
76
84
PostDTO existingPostToPatch = postWebMapper .toDTO (existingPost );
77
85
JsonNode postNode = objectMapper .valueToTree (existingPostToPatch );
0 commit comments