-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPostController.java
More file actions
39 lines (32 loc) · 1.08 KB
/
PostController.java
File metadata and controls
39 lines (32 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
38
39
package com.example.springhw32.controller;
import com.example.springhw32.dto.PostDto;
import com.example.springhw32.service.PostService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/posts")
@RequiredArgsConstructor
public class PostController {
private final PostService postService;
// 글 작성
@PostMapping
public PostDto createPost(@RequestBody PostDto postDto, @RequestParam String writer) {
return postService.createPost(postDto, writer);
}
// 최신순 글 조회
@GetMapping
public List<PostDto> getPostsSortedByDate() {
return postService.getPostsSortedByDate();
}
// 작성자 글 조회
@GetMapping("/{writer}")
public List<PostDto> getPostsByWriter(@PathVariable String writer) {
return postService.getPostsByWriter(writer);
}
// 댓글 많은 순 글 조회
@GetMapping("/comments")
public List<PostDto> getPostsSortedByComments() {
return postService.getPostsSortedByComments();
}
}