Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
Expand Down Expand Up @@ -37,9 +38,7 @@ public RsData<PostResponseDto> createPost(
* @return 모든 게시글 리스트
*/
@GetMapping
public RsData<List<Post>> getAllPosts() {
List<Post> posts = postService.getAllPosts();
return RsData.successOf(posts); // code=200, message="success"
public RsData<List<PostResponseDto>> getAllPosts() {
return RsData.successOf(postService.getAllPosts()); // code=200, message="success"
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.back.domain.user.entity.User;
import com.back.global.rq.Rq;
import java.util.List;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand Down Expand Up @@ -61,7 +62,11 @@ public PostResponseDto createPost(PostRequestDto postRequestDto) {

// 게시글 다건 조회 로직
@Transactional(readOnly = true)
public List<Post> getAllPosts() {
return postRepository.findAll();
public List<PostResponseDto> getAllPosts() {
List<Post> posts = postRepository.findAll();

return posts.stream()
.map(PostResponseDto::new)
.collect(Collectors.toList());
}
}