Skip to content

SISC-BE-FEAT-게시판-댓글-반환값-추가#153

Merged
Kosw6 merged 18 commits intomainfrom
SIsC1-151-BE-게시판-추가
Nov 29, 2025

Hidden character warning

The head ref may contain hidden characters: "SIsC1-151-BE-\uac8c\uc2dc\ud310-\ucd94\uac00"
Merged

SISC-BE-FEAT-게시판-댓글-반환값-추가#153
Kosw6 merged 18 commits intomainfrom
SIsC1-151-BE-게시판-추가

Conversation

@nayoung04
Copy link
Contributor

@nayoung04 nayoung04 commented Nov 29, 2025

Summary by CodeRabbit

릴리스 노트

  • 버그 수정
    • 댓글 스레드 구조 개선: 대댓글과 원댓글의 관계를 정확하게 추적하도록 수정했습니다. 사용자는 이제 각 댓글이 어느 댓글에 대한 답글인지 명확하게 확인할 수 있습니다. 댓글의 계층 구조가 보다 안정적으로 표시됩니다.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Nov 29, 2025

워크스루

댓글의 부모-자식 관계를 명시적으로 처리하기 위해 CommentResponse DTO에 parentCommentId 필드를 추가하고, PostServiceImplgetPostDetail 메서드에서 자식 댓글의 부모 참조를 명확히 설정한 후 DTO 변환을 수행하는 로직을 추가했습니다.

변경사항

그룹 / 파일(들) 변경 요약
댓글 응답 DTO 확장
backend/src/main/java/org/sejongisc/backend/board/dto/CommentResponse.java
parentCommentId (UUID) 필드 추가 및 두 개의 from() 메서드에서 부모 댓글 ID 계산 및 설정 로직 구현
게시물 상세 조회 로직 개선
backend/src/main/java/org/sejongisc/backend/board/service/PostServiceImpl.java
getPostDetail 메서드에서 자식 댓글 조회 시 각 자식의 부모 참조를 명시적으로 설정한 후 DTO로 변환하는 로직 추가

예상 코드 리뷰 노력

🎯 2 (Simple) | ⏱️ ~10분

  • DTO에 새로운 필드 추가 및 매핑 로직이 일관된 패턴으로 적용됨
  • PostServiceImpl의 부모-자식 참조 설정 로직이 명확하고 단순함
  • 전체적으로 반복적이고 일관된 패턴의 변경으로 구성됨

🐰 부모의 ID를 담아서, 댓글들이 손잡았네요!
자식들은 이제 뿌리를 알고, 대화의 나무가 자랍니다.
명확한 관계, 명확한 흐름—
코드 정원에 봄이 왔어요! 🌱

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 76.19% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed PR 제목이 변경사항의 주요 내용을 명확하게 설명합니다. 댓글 반환값 추가라는 핵심 변경사항을 정확히 나타냅니다.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch SIsC1-151-BE-게시판-추가

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8148349 and 770901e.

📒 Files selected for processing (1)
  • backend/src/main/java/org/sejongisc/backend/board/service/PostServiceImpl.java (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • backend/src/main/java/org/sejongisc/backend/board/service/PostServiceImpl.java

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

@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: 0

🧹 Nitpick comments (5)
backend/src/test/java/org/sejongisc/backend/board/service/PostServiceImplTest.java (1)

277-336: 대댓글 테스트에 parentCommentId 검증 추가 제안

부모/자식 댓글의 내용과 replies 사이즈는 잘 검증되고 있는데, 이번 PR에서 핵심으로 추가된 parentCommentId까지 함께 검증해 두면 더 좋을 것 같습니다. 예를 들어:

  • parentResponse.getReplies().get(0).getParentCommentId()parentResponse.getCommentId()와 동일한지,
  • 혹은 실제 parentComment.getCommentId()와 동일한지

를 assert하면, DTO 계층 관계가 정확히 맵핑되는지까지 테스트에서 잡아줄 수 있습니다.

backend/src/main/java/org/sejongisc/backend/board/service/PostServiceImpl.java (3)

174-196: 게시판 삭제 시 삭제 순서 및 다단계 계층 처리 검토 제안

현재 targetBoardIdsStream.of(boardId) → 자식 보드 순으로 구성되어 deleteById가 부모 → 자식 순으로 호출됩니다. DB에서 부모-자식 FK 제약이 걸려 있다면, 부모를 먼저 삭제할 때 제약 위반이 날 수 있어서 자식 보드를 먼저 삭제하거나, JPA 매핑의 cascade 설정을 한 번 확인해 보는 게 안전합니다.

또한 findAllByParentBoard_BoardId(boardId)는 직계 자식만 포함하므로, 트리가 2단계 이상인 경우 손자 보드가 남을 수 있습니다. 필요하다면 재귀적으로 하위 보드의 ID를 모두 수집하는 헬퍼를 두는 것도 고려해 볼 만합니다.


201-220: 게시글 조회 공통 빌더 사용은 좋지만 User 조회/전달 패턴 정리 여지

getPosts, searchPosts, getPostDetail에서 모두 userRepository.findById(userId)User를 조회한 뒤 getCommonPostBuilder(post, user)에 넘겨 isLiked/isBookmarked를 계산하는 패턴이 잘 통일되어 있습니다.

다만 getCommonPostBuilder 안에서는 실제로 user.getUserId()만 사용하고 있으므로,

  • 공통으로 private User getUserOrThrow(UUID userId) 같은 헬퍼를 두거나,
  • 아예 getCommonPostBuilder(Post post, UUID userId)로 바꿔 User 엔티티가 꼭 필요 없는 경우 쿼리를 줄이는 방향

을 고려해 볼 수 있습니다. 성능 이슈는 크지 않겠지만, 코드 의도를 더 분명하게 드러낼 수 있습니다.

Also applies to: 225-245, 353-372


343-351: getChildBoards에도 @OverRide 추가 권장

PostService 인터페이스에 getChildBoards()가 정의되어 있으므로, 구현부 메서드에도 @Override를 붙여 두면 시그니처 변경 시 컴파일 타임에 더 빨리 잡을 수 있고, getParentBoards와의 일관성도 좋아집니다.

backend/src/main/java/org/sejongisc/backend/board/controller/BoardController.java (1)

158-167: 부모/하위 게시판 조회에서 인증 파라미터 사용 여부 명확화 제안

getParentBoards, getChildBoards 두 메서드가 @AuthenticationPrincipal CustomUserDetails를 파라미터로 받지만, 현재 구현에서는 userId나 role을 사용하지 않고 바로 postService.getParentBoards()/getChildBoards()만 호출합니다.

  • 완전히 공개해도 되는 목록 API라면 @AuthenticationPrincipal 파라미터를 제거하거나,
  • 특정 권한만 접근해야 한다면 서비스/시큐리티 설정 쪽에서 role 체크를 추가

하는 식으로 의도를 코드에 더 드러내면, 나중에 읽을 때 혼란이나 정적 분석 도구의 unused-parameter 경고를 줄일 수 있을 것 같습니다.

Also applies to: 170-179

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7f33b80 and 8148349.

📒 Files selected for processing (6)
  • backend/src/main/java/org/sejongisc/backend/board/controller/BoardController.java (6 hunks)
  • backend/src/main/java/org/sejongisc/backend/board/dto/CommentResponse.java (1 hunks)
  • backend/src/main/java/org/sejongisc/backend/board/dto/PostResponse.java (1 hunks)
  • backend/src/main/java/org/sejongisc/backend/board/service/PostService.java (1 hunks)
  • backend/src/main/java/org/sejongisc/backend/board/service/PostServiceImpl.java (8 hunks)
  • backend/src/test/java/org/sejongisc/backend/board/service/PostServiceImplTest.java (6 hunks)
🔇 Additional comments (8)
backend/src/main/java/org/sejongisc/backend/board/dto/CommentResponse.java (1)

28-35: parentCommentId 추가 및 매핑 로직 적절

parentCommentId를 필드로 추가하고, 두 from(...) 팩토리 메서드에서 parentComment가 없을 때 null 처리까지 포함해 UUID를 세팅하는 구조가 명확합니다. 프런트에서 트리 구조를 복원하기에도 충분한 정보라 보이고, NPE 리스크도 없어 보입니다.

Also applies to: 36-45, 47-60

backend/src/main/java/org/sejongisc/backend/board/dto/PostResponse.java (1)

31-32: 사용자별 상태 필드(isLiked, isBookmarked) 추가 타이밍 적절

isLiked, isBookmarked를 DTO에 추가해 서비스 레이어에서 per-user 상태를 내려줄 수 있게 한 방향이 좋습니다. Boolean으로 선언해 상태 미정(null)도 표현 가능해 확장성도 괜찮아 보입니다.

backend/src/test/java/org/sejongisc/backend/board/service/PostServiceImplTest.java (2)

41-43: 테스트 setUp에서 필수 필드 세팅으로 DTO 변환 안정성 확보

mockUserrole, email, name을 채우고, mockBoard/mockParentBoardcreatedBy를 설정해 둔 덕분에 UserInfoResponse.from 등 DTO 변환 시 NPE 가능성을 잘 제거했습니다. 실제 도메인 제약(Role.TEAM_MEMBER 등)에 맞춘 값이라 테스트 신뢰성도 높습니다.

Also applies to: 90-111


246-267: getPosts 테스트에서 per-user 상태 검증 추가 좋음

userRepository.findById(userId) mocking과 함께 postLikeRepository.existsByUserUserIdAndPostPostId, postBookmarkRepository.existsByUserUserIdAndPostPostId를 설정하고, 결과 DTO에서 isLiked, isBookmarked 값을 직접 assert 하는 부분이 새 로직을 정확히 커버하고 있습니다. 목록 조회 시에도 사용자별 상태가 잘 내려가는지 보장해 줍니다.

backend/src/main/java/org/sejongisc/backend/board/service/PostService.java (1)

22-30: PostService 시그니처 확장 방향 일관성 있음

게시글 조회/검색/상세 조회에 userId를 추가하고, 게시판 조회/삭제용 메서드를 인터페이스에 정의한 구조가 Controller·Impl 코드와 잘 맞습니다. per-user DTO 필드(isLiked/isBookmarked) 계산을 서비스 레이어에서 책임지도록 설계한 점도 자연스럽습니다.

Also applies to: 34-41

backend/src/main/java/org/sejongisc/backend/board/service/PostServiceImpl.java (1)

262-284: 댓글/대댓글 DTO 변환 로직이 parentCommentId·replies 요구사항을 충족

부모 댓글을 페이징으로 조회한 뒤, 각 부모에 대해 findByParentComment로 자식 목록을 가져와 CommentResponse::fromCommentResponse.from(parent, replyResponses) 조합으로 DTO를 만드는 구조가 요구사항(부모 댓글 + 대댓글 + parentCommentId 전달)을 잘 반영하고 있습니다.

childComments.forEach(child -> child.setParentComment(parent));를 통해 DTO 변환 시 parentCommentId가 확실히 채워지도록 한 방어 로직도, 실제로 parent 연관 정보가 누락되는 케이스를 겪었다면 실용적인 해결책이라고 보입니다.

Also applies to: 292-300

backend/src/main/java/org/sejongisc/backend/board/controller/BoardController.java (2)

97-105: 게시글 조회/검색/상세에서 userId 전달로 per-user 필드 계산이 가능해짐

getPosts, searchPosts, getPostDetail@AuthenticationPrincipal CustomUserDetails를 추가하고, 여기서 얻은 userId를 서비스 레이어에 넘겨주는 구조가 PostService/PostServiceImpl 변경과 잘 맞습니다. 이로 인해 각 PostResponse에서 isLiked/isBookmarked 같은 사용자별 상태를 일관되게 내려줄 수 있게 된 점이 좋습니다.

Also applies to: 114-123, 132-140


181-195: 게시판 삭제 엔드포인트와 서비스 연동이 명확함

DELETE /api/board/{boardId}에서 인증 사용자 ID를 추출해 postService.deleteBoard(boardId, userId)로 넘기는 구조가 서비스 구현의 Role.PRESIDENT 체크와 잘 맞습니다. 응답 메시지도 한글로 명확하게 내려 주고 있어, 클라이언트 입장에서 처리하기 수월해 보입니다.

@Kosw6 Kosw6 merged commit f7230bd into main Nov 29, 2025
1 check passed
@Kosw6 Kosw6 deleted the SIsC1-151-BE-게시판-추가 branch November 29, 2025 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants