-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPostController.java
More file actions
44 lines (37 loc) · 1.41 KB
/
PostController.java
File metadata and controls
44 lines (37 loc) · 1.41 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
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.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RequestMapping("/posts")
@RestController
@RequiredArgsConstructor
public class PostController {
private final PostService postService;
// 글 작성
@PostMapping
public PostDto createPost(@ModelAttribute PostDto postDto, Long userId) {
return postService.createPost(postDto, userId);
}
// 최신순 글 조회
@GetMapping
public List<PostDto> finaAllByCreatedAtDesc() {
return postService.finaAllByCreatedAtDesc();
}
// 작성자 글 조회
@GetMapping("/{writer}")
public List<PostDto> findAllByUsername(@PathVariable("writer") String username) {
return postService.findAllByUsername(username);
}
// 댓글 많은 순 글 조회
@GetMapping("/comments")
public List<PostDto> findAllByOrderByCommentCountDesc() {
return postService.findAllByOrderByCommentCountDesc();
}
}