-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathCommentController.java
More file actions
31 lines (25 loc) · 928 Bytes
/
CommentController.java
File metadata and controls
31 lines (25 loc) · 928 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package com.example.devSns.controller;
import com.example.devSns.entity.Comment;
import com.example.devSns.service.CommentService;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("post/{postId}/comment")
public class CommentController {
private CommentService commentService;
public CommentController(CommentService commentService) {
this.commentService = commentService;
}
@GetMapping
public List<Comment> getComments(@PathVariable Long postId) {
return commentService.getCommentByPost(postId);
}
@PostMapping
public Comment createComment(@PathVariable Long postId, @RequestBody Comment comment) {
return commentService.addComment(postId, comment);
}
@DeleteMapping("/{commentId}")
public void deleteComment(@PathVariable Long commentId) {
commentService.deleteComment(commentId);
}
}