-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCommentAPiController.java
More file actions
45 lines (36 loc) · 1.69 KB
/
Copy pathCommentAPiController.java
File metadata and controls
45 lines (36 loc) · 1.69 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
38
39
40
41
42
43
44
45
package com.catcher.resource;
import com.catcher.core.domain.command.*;
import com.catcher.core.domain.entity.Comment;
import com.catcher.core.domain.request.PostCommentReplyRequest;
import com.catcher.core.domain.request.PostCommentRequest;
import com.catcher.core.domain.response.GetCommentsByPageResponse;
import com.catcher.core.service.CommentService;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RequiredArgsConstructor
@RestController
@RequestMapping("/comment")
public class CommentAPiController {
private final CommentService commentService;
private final CommentCommandExecutor commandExecutor;
@PostMapping
public void postComment(@RequestBody PostCommentRequest postCommentRequest) {
Command<Void> command = new PostCommentCommand(commentService, postCommentRequest);
commandExecutor.run(command);
}
@PostMapping("/reply")
public void replyComment(@RequestBody PostCommentReplyRequest postCommentReplyRequest) {
Command<Void> command = new PostCommentReplyCommand(commentService, postCommentReplyRequest);
commandExecutor.run(command);
}
@GetMapping
public List<GetCommentsByPageResponse> getComments(@PageableDefault(size = 20, sort = {"id"}) Pageable pageable) {
Command<Page<Comment>> command = new GetCommentCommand(commentService, pageable);
Page<Comment> commentPage = commandExecutor.run(command);
return GetCommentsByPageResponse.createGetCommentsByPageResponseList(commentPage);
}
}