-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathCommentController.java
More file actions
31 lines (26 loc) · 1.04 KB
/
CommentController.java
File metadata and controls
31 lines (26 loc) · 1.04 KB
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.dto.CommentRequest;
import com.example.devSns.entity.CommentEntity;
import com.example.devSns.service.CommentService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
@Controller
@RequestMapping("/comments")
public class CommentController {
private final CommentService commentService;
public CommentController(CommentService commentService) {
this.commentService = commentService;
}
// 댓글 생성
@PostMapping("/{postId}")
public String createComment(@PathVariable Long postId, @ModelAttribute CommentRequest request) {
commentService.createComment(postId, request);
return "redirect:/posts/" + postId;
}
// 댓글 삭제
@PostMapping("/{commentId}/delete")
public String deleteComment(@PathVariable Long commentId, @RequestParam Long postId) {
commentService.deleteComment(commentId);
return "redirect:/posts/" + postId;
}
}