File tree Expand file tree Collapse file tree 2 files changed +10
-6
lines changed
src/main/java/com/back/domain/post/post Expand file tree Collapse file tree 2 files changed +10
-6
lines changed Original file line number Diff line number Diff line change 88import java .util .List ;
99import lombok .RequiredArgsConstructor ;
1010import org .springframework .web .bind .annotation .GetMapping ;
11+ import org .springframework .web .bind .annotation .PathVariable ;
1112import org .springframework .web .bind .annotation .PostMapping ;
1213import org .springframework .web .bind .annotation .RequestBody ;
1314import org .springframework .web .bind .annotation .RequestMapping ;
@@ -37,9 +38,7 @@ public RsData<PostResponseDto> createPost(
3738 * @return 모든 게시글 리스트
3839 */
3940 @ GetMapping
40- public RsData <List <Post >> getAllPosts () {
41- List <Post > posts = postService .getAllPosts ();
42- return RsData .successOf (posts ); // code=200, message="success"
41+ public RsData <List <PostResponseDto >> getAllPosts () {
42+ return RsData .successOf (postService .getAllPosts ()); // code=200, message="success"
4343 }
44-
4544}
Original file line number Diff line number Diff line change 1111import com .back .domain .user .entity .User ;
1212import com .back .global .rq .Rq ;
1313import java .util .List ;
14+ import java .util .stream .Collectors ;
1415import lombok .RequiredArgsConstructor ;
1516import org .springframework .stereotype .Service ;
1617import org .springframework .transaction .annotation .Transactional ;
@@ -61,7 +62,11 @@ public PostResponseDto createPost(PostRequestDto postRequestDto) {
6162
6263 // 게시글 다건 조회 로직
6364 @ Transactional (readOnly = true )
64- public List <Post > getAllPosts () {
65- return postRepository .findAll ();
65+ public List <PostResponseDto > getAllPosts () {
66+ List <Post > posts = postRepository .findAll ();
67+
68+ return posts .stream ()
69+ .map (PostResponseDto ::new )
70+ .collect (Collectors .toList ());
6671 }
6772}
You can’t perform that action at this time.
0 commit comments