Skip to content

fix: 커뮤니티 게시글 조회 응답 dto에 작성자 필드 추가#123

Merged
chaechaepower merged 1 commit intomainfrom
fix/post-writer
Apr 23, 2026
Merged

fix: 커뮤니티 게시글 조회 응답 dto에 작성자 필드 추가#123
chaechaepower merged 1 commit intomainfrom
fix/post-writer

Conversation

@chaechaepower
Copy link
Copy Markdown
Member

@chaechaepower chaechaepower commented Apr 23, 2026

🧷 이슈

  • close #

🔨 작업 내용

  • 커뮤니티 게시글 조회(목록, 단건) 응답 dto에 작성자 필드 추가

👀 리뷰 요구사항

Summary by CodeRabbit

  • New Features
    • 게시물의 상세 정보 페이지와 목록 조회 시 작성자 정보가 표시되도록 개선되었습니다.

@chaechaepower chaechaepower self-assigned this Apr 23, 2026
@chaechaepower chaechaepower added the 🔨 Fix 기능 수정 label Apr 23, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 23, 2026

개요

두 개의 게시물 응답 DTO(PostDetailResponse, PostListResponse)에 writer 필드가 추가되었으며, 팩토리 메서드가 게시물 작성자 이름을 기반으로 이 필드를 채우도록 업데이트되었습니다.

변경사항

응집도 / 파일(들) 요약
게시물 응답 DTO
src/main/java/kr/co/webee/presentation/post/dto/response/PostDetailResponse.java, src/main/java/kr/co/webee/presentation/post/dto/response/PostListResponse.java
각 응답 DTO에 writer 필드(String) 추가 및 Swagger 주석 추가. from() 팩토리 메서드가 post.getUser().getName()에서 작성자 정보를 매핑하도록 업데이트됨.

예상 코드 리뷰 노력

🎯 2 (Simple) | ⏱️ ~8분

🐰 필드 하나 둘, 작성자를 담고,
팩토리 메서드 슬쩍 손을 댓고,
응답에 이름을 새겨 넣으니,
누가 쓴 글인지 이제 또렷하네!
작지만 소중한 변화 여기 있네요.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed PR 제목은 변경사항의 핵심을 명확하게 설명합니다. 커뮤니티 게시글 조회 응답 DTO에 작성자 필드를 추가한 것이 주요 변경사항이며, 제목이 이를 정확하게 반영합니다.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/post-writer

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@src/main/java/kr/co/webee/presentation/post/dto/response/PostListResponse.java`:
- Line 36: getAllPosts() causes an N+1 because PostRepository.findAll(pageable)
returns Posts with user lazily loaded and PostListResponse.from() calls
post.getUser().getName() for each row; fix by loading user together with
posts—e.g., add a repository method like findAllWithUser(Pageable) using a fetch
join or annotate PostRepository.findAll(...) with `@EntityGraph`(attributePaths =
"user"), or switch to a DTO projection that selects p and u.name together—then
update getAllPosts() to call the new findAllWithUser / projection so
PostListResponse.from(...) no longer triggers extra queries.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c53161d0-b275-498d-99f2-8fcfdc539e68

📥 Commits

Reviewing files that changed from the base of the PR and between a30355f and f221f68.

📒 Files selected for processing (2)
  • src/main/java/kr/co/webee/presentation/post/dto/response/PostDetailResponse.java
  • src/main/java/kr/co/webee/presentation/post/dto/response/PostListResponse.java

public static PostListResponse from(Post post, int likeCount, int commentCount) {
return PostListResponse.builder()
.postId(post.getId())
.writer(post.getUser().getName())
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: PostListResponse.from 호출부와 게시글 목록 조회 쿼리가 user를 선로딩하는지 확인합니다.
# Expect: 목록 조회 경로에서 fetch join user, `@EntityGraph`(attributePaths = "user"), 또는 DTO/projection으로 writer를 함께 조회하는 코드가 있어야 합니다.

echo "== PostListResponse.from 호출부 =="
rg -n -C3 'PostListResponse\.from\s*\('

echo
echo "== 게시글 repository/service의 user fetch 관련 코드 =="
rg -n -C4 'fetch\s+join\s+.*user|join\s+fetch\s+.*user|@EntityGraph|attributePaths\s*=\s*\{?\s*"user"|find.*Post|postRepository' --type=java

Repository: BeeKeeprs/was

Length of output: 14978


🏁 Script executed:

# PostRepository 확인
find . -name "PostRepository.java" -type f | head -1 | xargs cat

# Post 엔티티의 user 필드 확인
find . -name "Post.java" -path "*/domain/post/*" -type f | head -1 | xargs cat -n | grep -A5 -B5 "user"

Repository: BeeKeeprs/was

Length of output: 2227


getAllPosts() 메서드에서 N+1 쿼리가 발생합니다.

PostRepository.findAll(pageable)은 Post만 로드하고 user는 LAZY이므로, PostListResponse.from() 호출 시 각 게시글마다 post.getUser().getName()이 추가 쿼리를 발생시킵니다.

게시글 목록 조회 시 user를 함께 로드하도록 수정하세요. 예를 들어:

  • PostRepository에 fetch join을 사용한 커스텀 메서드 추가
  • Post 엔티티에 @EntityGraph(attributePaths = "user") 적용
  • 또는 DTO projection으로 user 정보를 함께 조회
`@Query`("SELECT new dto(p.id, p.title, u.name) FROM Post p JOIN FETCH p.user u")
Slice<PostListResponse> findAllWithUser(Pageable pageable);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/main/java/kr/co/webee/presentation/post/dto/response/PostListResponse.java`
at line 36, getAllPosts() causes an N+1 because PostRepository.findAll(pageable)
returns Posts with user lazily loaded and PostListResponse.from() calls
post.getUser().getName() for each row; fix by loading user together with
posts—e.g., add a repository method like findAllWithUser(Pageable) using a fetch
join or annotate PostRepository.findAll(...) with `@EntityGraph`(attributePaths =
"user"), or switch to a DTO projection that selects p and u.name together—then
update getAllPosts() to call the new findAllWithUser / projection so
PostListResponse.from(...) no longer triggers extra queries.

@chaechaepower chaechaepower merged commit c1a1990 into main Apr 23, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🔨 Fix 기능 수정

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant