Skip to content

Commit a40529f

Browse files
authored
[feat] 게시글 다건 조회, 작성 구현#43
[feat] 게시글 다건 조회, 작성 구현#43
2 parents f71f41b + 13c3c99 commit a40529f

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/main/java/com/back/domain/post/post/controller/PostController.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.util.List;
99
import lombok.RequiredArgsConstructor;
1010
import org.springframework.web.bind.annotation.GetMapping;
11+
import org.springframework.web.bind.annotation.PathVariable;
1112
import org.springframework.web.bind.annotation.PostMapping;
1213
import org.springframework.web.bind.annotation.RequestBody;
1314
import 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
}

src/main/java/com/back/domain/post/post/service/PostService.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import com.back.domain.user.entity.User;
1212
import com.back.global.rq.Rq;
1313
import java.util.List;
14+
import java.util.stream.Collectors;
1415
import lombok.RequiredArgsConstructor;
1516
import org.springframework.stereotype.Service;
1617
import 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
}

0 commit comments

Comments
 (0)