Skip to content

[Feat] 질문 댓글 미리보기 및 SSE 실시간 갱신 이벤트 구현#110

Merged
issuejong merged 5 commits into
developfrom
feat/#109
May 24, 2026
Merged

[Feat] 질문 댓글 미리보기 및 SSE 실시간 갱신 이벤트 구현#110
issuejong merged 5 commits into
developfrom
feat/#109

Conversation

@issuejong

Copy link
Copy Markdown
Collaborator

#️⃣연관된 이슈

#109

📝작업 내용

질문방 목록에서 댓글 미리보기를 함께 조회하고, 댓글 생성 시 SSE를 통해 실시간으로 목록 갱신 이벤트를 받을 수 있도록 구현했습니다.

  • 질문 목록 댓글 미리보기 추가

    • 질문 목록 응답에 previewComments 추가
    • 댓글이 없는 경우 빈 배열로 반환
    • 최신 최상위 댓글 3개를 조회하되, 화면에서는 작성 순서대로 보이도록 정렬
  • 질문 댓글 이벤트 구독 API 추가

    • GET /api/sessions/{sessionId}/questions/events
    • text/event-stream 방식으로 SSE 연결 유지
    • 세션별 질문방 구독자에게 댓글 생성 이벤트 전달
  • SSE 이벤트 관리 서비스 추가

    • QuestionEventService 추가
    • 세션 ID별 SseEmitter 목록 관리
    • 연결 완료, 타임아웃, 오류 발생 시 emitter 정리
    • 최초 연결 확인용 connected 이벤트 전송
  • 댓글 생성 이벤트 발행 로직 구현

    • 댓글 생성 후 comment-created 이벤트 발행
    • 이벤트에는 세션 ID, 질문 ID, 댓글 수, 댓글 미리보기 목록 포함
    • 프론트에서 전체 질문 목록을 다시 조회하지 않고 해당 질문만 갱신할 수 있도록 최소 데이터 전달
  • 트랜잭션 커밋 이후 이벤트 발행 처리

    • 댓글 저장 트랜잭션이 정상 커밋된 뒤 SSE 이벤트 발행
    • 롤백된 댓글이 실시간 화면에 먼저 노출되지 않도록 처리

@issuejong issuejong requested a review from Copilot May 24, 2026 07:44
@issuejong issuejong self-assigned this May 24, 2026
@issuejong issuejong linked an issue May 24, 2026 that may be closed by this pull request
3 tasks

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

질문 목록에서 댓글 미리보기를 함께 내려주고, 댓글 생성 시 SSE를 통해 같은 세션의 질문 목록을 실시간으로 갱신할 수 있도록 이벤트 발행/구독 흐름을 추가한 PR입니다.

Changes:

  • 질문 목록 응답에 previewComments(최상위 댓글 3개 미리보기) 포함
  • GET /api/sessions/{sessionId}/questions/events SSE 구독 엔드포인트 및 QuestionEventService(세션별 emitter 관리) 추가
  • 댓글 생성 트랜잭션 커밋 이후 comment-created 이벤트 발행

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
backend/src/main/java/com/example/Piroin/project/domain/question/service/QuestionService.java 목록용 댓글 미리보기 구성 및 댓글 생성 후 커밋-이후 SSE 이벤트 발행 로직 추가
backend/src/main/java/com/example/Piroin/project/domain/question/service/QuestionEventService.java 세션별 SSE emitter 구독/정리 및 댓글 생성 이벤트 브로드캐스트 구현
backend/src/main/java/com/example/Piroin/project/domain/question/repository/QuestionCommentRepository.java 목록 미리보기용 “최신 최상위 댓글 3개” 조회 메서드 추가
backend/src/main/java/com/example/Piroin/project/domain/question/dto/QuestionResDTO.java previewComments 및 SSE 이벤트 DTO 추가
backend/src/main/java/com/example/Piroin/project/domain/question/controller/QuestionController.java SSE 구독 API 라우팅 추가

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +498 to +504
private List<QuestionResDTO.PreviewCommentResponse> getPreviewComments(Question question) {
// 최신 댓글 3개를 미리보기 대상으로 삼되, 화면 표시는 댓글이 달린 순서대로 보이게 오래된 순으로 정렬한다.
return questionCommentRepository
.findTop3ByQuestionAndParentCommentIsNullAndDeletedAtIsNullOrderByCreatedAtDesc(question)
.stream()
.sorted(Comparator.comparing(QuestionComment::getCreatedAt))
.map(comment -> new QuestionResDTO.PreviewCommentResponse(
Comment on lines 485 to 494
questionCommentRepository.countByQuestionAndDeletedAtIsNull(question),
// 목록 화면에서 바로 렌더링할 댓글 미리보기 3개를 함께 내려준다.
getPreviewComments(question),
question.getCreatedAt()
Comment on lines +528 to +532
// 롤백된 댓글이 실시간 화면에 먼저 보이지 않도록 트랜잭션 커밋 이후에만 이벤트를 발행한다.
private void publishAfterCommit(Runnable action) {
if (!TransactionSynchronizationManager.isSynchronizationActive()) {
action.run();
return;
Comment on lines +35 to +38
@GetMapping(value = "/api/sessions/{sessionId}/questions/events", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
public SseEmitter subscribeQuestionEvents(@PathVariable Long sessionId) {
return questionService.subscribeQuestionEvents(sessionId);
}
@issuejong issuejong merged commit e631667 into develop May 24, 2026
1 check passed
@issuejong issuejong deleted the feat/#109 branch June 7, 2026 02:04
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.

[Feat] 질문 메인 페이지에서 댓글 명시 기능 구현

2 participants