-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCommentController.java
More file actions
33 lines (28 loc) · 1.09 KB
/
CommentController.java
File metadata and controls
33 lines (28 loc) · 1.09 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
32
33
package com.study.springbootstudy.controller;
import com.study.springbootstudy.common.ApiResponse;
import com.study.springbootstudy.dto.CommentRequestDto;
import com.study.springbootstudy.service.CommentService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
@RestController
@RequiredArgsConstructor
public class CommentController {
private final CommentService commentService;
// 댓글 생성
@PostMapping("/api/posts/{postId}/comments")
public ApiResponse<Long> createComment(
@PathVariable Long postId,
@RequestBody @Valid CommentRequestDto request) {
Long commentId = commentService.createComment(postId, request);
return ApiResponse.onSuccess(commentId);
}
// 댓글 삭제
@DeleteMapping("/api/comments/{commentId}")
public ApiResponse<Void> deleteComment(
@PathVariable Long commentId,
@RequestParam String password) {
commentService.deleteComment(commentId, password);
return ApiResponse.onSuccess(null);
}
}