-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathCommentController.java
More file actions
37 lines (31 loc) · 1.08 KB
/
CommentController.java
File metadata and controls
37 lines (31 loc) · 1.08 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
34
35
36
37
package com.example.devSns.comment;
import com.example.devSns.comment.dto.CommentRequest;
import com.example.devSns.comment.dto.CommentResponse;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/api/tasks/{taskId}/comments")
public class CommentController {
private final CommentService service;
public CommentController(CommentService service) {
this.service = service;
}
@PostMapping
public ResponseEntity<CommentResponse> create(
@PathVariable Long taskId,
@RequestBody CommentRequest req) {
return ResponseEntity.ok(service.create(taskId, req));
}
@GetMapping
public List<CommentResponse> list(@PathVariable Long taskId) {
return service.findByTask(taskId);
}
@DeleteMapping("/{commentId}")
public ResponseEntity<Void> delete(
@PathVariable Long taskId,
@PathVariable Long commentId) {
service.delete(commentId);
return ResponseEntity.noContent().build();
}
}