Conversation
3 tasks
There was a problem hiding this comment.
Pull request overview
질문 목록에서 댓글 미리보기를 함께 내려주고, 댓글 생성 시 SSE를 통해 같은 세션의 질문 목록을 실시간으로 갱신할 수 있도록 이벤트 발행/구독 흐름을 추가한 PR입니다.
Changes:
- 질문 목록 응답에
previewComments(최상위 댓글 3개 미리보기) 포함 GET /api/sessions/{sessionId}/questions/eventsSSE 구독 엔드포인트 및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); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
#️⃣연관된 이슈
#109
📝작업 내용
질문 목록 댓글 미리보기 추가
previewComments추가질문 댓글 이벤트 구독 API 추가
GET /api/sessions/{sessionId}/questions/eventstext/event-stream방식으로 SSE 연결 유지SSE 이벤트 관리 서비스 추가
QuestionEventService추가SseEmitter목록 관리connected이벤트 전송댓글 생성 이벤트 발행 로직 구현
comment-created이벤트 발행트랜잭션 커밋 이후 이벤트 발행 처리