-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPostController.java
More file actions
47 lines (31 loc) · 1.06 KB
/
PostController.java
File metadata and controls
47 lines (31 loc) · 1.06 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
46
47
package com.example.springhw32.controller;
import com.example.springhw32.dto.CommentDto;
import com.example.springhw32.dto.PostDto;
import com.example.springhw32.dto.UserDto;
import com.example.springhw32.service.PostService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RequiredArgsConstructor
@RestController
@RequestMapping("/posts")
public class PostController {
private final PostService postService;
@PostMapping("")
public PostDto create(Long userId,
@ModelAttribute PostDto postDto){
return postService.create(userId,postDto);
}
@GetMapping("")
public List<PostDto> getRecentPosts(){
return postService.getRecentPosts();
}
@GetMapping("/{writer}")
public List<PostDto> getPostsByWriter(@PathVariable("writer")String nickName){
return postService.getPostsByWriter(nickName);
}
@GetMapping("/comments")
public List<PostDto> getPopularPosts(){
return postService.getPopularPosts();
}
}