-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPostController.java
More file actions
40 lines (33 loc) · 1.12 KB
/
PostController.java
File metadata and controls
40 lines (33 loc) · 1.12 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
package com.example.springhw32.controller;
import com.example.springhw32.dto.PostDto;
import com.example.springhw32.service.PostService;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequiredArgsConstructor
@RequestMapping("/posts")
public class PostController {
private final PostService postService;
//글작성
@PostMapping("")
public PostDto save(@ModelAttribute PostDto postDto, Long userId) {
return postService.save(postDto, userId);
}
//최신순으로 글 조회
@GetMapping("")
public List<PostDto> findAllByOrderByCreatedAtDesc() {
return postService.findAllByOrderByCreatedAtDesc();
}
//작성자 글 조회
@GetMapping("/{writer}")
public List<PostDto> findAllByWriter(@PathVariable("writer") Long userId) {
return postService.findAllByWriter(userId);
}
//댓글 많은 순 조회
@GetMapping("/comments")
public List<PostDto> findAllByOrderByCommentNumberDesc() {
return postService.findAllByOrderByCommentNumberDesc();
}
}