Skip to content

Conversation

@Gyuhyeok99
Copy link
Contributor

관련 이슈

작업 내용

AS-IS

  • 멘토링 승인 시 비동기로 채팅방 생성

TO-BE

  • 멘토링 승인 시 동기식으로 채팅방 생성
  • 멘토링 승인 응답시 채팅방 id를 추가적으로 응답

특이 사항

리뷰 요구사항 (선택)

@coderabbitai
Copy link

coderabbitai bot commented Aug 24, 2025

Walkthrough

  1. ChatRoomRepository에서 existsByMentoringId(boolean) 메서드를 findByMentoringId(ChatRoom)으로 교체했습니다.
  2. ChatService의 createMentoringChatRoom이 Long을 반환하도록 변경되고, 기존 방 조회 후 없으면 생성하여 ID를 반환하도록 흐름이 수정되었습니다.
  3. MentoringApprovedEvent 레코드를 삭제했습니다.
  4. MentoringEventHandler 클래스를 삭제했습니다.
  5. MentoringCommandService가 ApplicationEventPublisher 대신 ChatService를 주입받아 승인 시 바로 채팅방을 생성하고, MentoringConfirmResponse에 chatRoomId를 포함해 반환합니다.
  6. MentoringConfirmResponse 레코드에 @JsonInclude(NON_NULL) chatRoomId 필드를 추가하고, 정적 팩토리를 from(mentoring, chatRoomId)로 변경했습니다.
  7. MentoringCommandServiceTest를 동기 흐름과 반환값 검증으로 업데이트했습니다.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Suggested reviewers

  • wibaek
  • whqtker
  • lsy1307

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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: 2

🧹 Nitpick comments (4)
src/main/java/com/example/solidconnection/mentor/dto/MentoringConfirmResponse.java (1)

3-4: 2) chatRoomId 추가 및 NON_NULL 직렬화 처리 좋습니다

  • 설명: 레코드 컴포넌트에 @JsonInclude(NON_NULL)을 국소 적용해 역호환을 유지했습니다. 팩토리 메서드도 명확합니다.
  • 제안:
    1. 외부 API 스펙 문서에 chatRoomId 조건부 반환을 명시하세요.
    2. 필드 설명을 스웨거/스키마(@Schema)로 보강하면 클라이언트 이해도가 높아집니다.

API 문서에 승인 시 chatRoomId가 포함됨을 반영해 주시겠어요?

Also applies to: 9-12, 15-16

src/main/java/com/example/solidconnection/chat/service/ChatService.java (1)

177-181: 3) Optional 기반 조회로 null 분기 제거 및 가독성 개선

  • 설명: 현재는 null 체크로 존재 유무를 판별합니다. Optional로 계약을 표현하면 의도가 선명해집니다.
  • 제안: Repository를 Optional로 바꾼 뒤, 아래처럼 early-return을 간결화하세요.
-    public Long createMentoringChatRoom(Long mentoringId, Long mentorId, Long menteeId) {
-        ChatRoom existingChatRoom = chatRoomRepository.findByMentoringId(mentoringId);
-        if (existingChatRoom != null) {
-            return existingChatRoom.getId();
-        }
+    public Long createMentoringChatRoom(Long mentoringId, Long mentorId, Long menteeId) {
+        var existingId = chatRoomRepository.findByMentoringId(mentoringId)
+                .map(ChatRoom::getId)
+                .orElse(null);
+        if (existingId != null) {
+            return existingId;
+        }
src/main/java/com/example/solidconnection/mentor/service/MentoringCommandService.java (1)

8-9: 5) 동기식 생성으로 목표 달성 확인 + 트랜잭션 경계 재검토 제안

  • 설명: 승인 시 즉시 ChatService를 호출해 chatRoomId를 반환하는 흐름은 PR 목적에 부합합니다. 같은 트랜잭션에서 menteeCount 증가와 방 생성이 함께 롤백되는 점도 안전합니다.

  • 제안:

    1. 동시 승인 레이스를 막기 위해 Mentoring 행을 비관적 잠금으로 조회하는 findById(PESSIMISTIC_WRITE) 도입을 고려하세요.
    2. ChatService에서 유니크 충돌 복구 로직을 적용했다면, 여기서는 현재 코드로 충분합니다.
  • 참고: 파라미터로 전달하는 식별자는 SiteUser 기준이며 ChatParticipant와 스키마가 일치합니다. 네이밍도 명확합니다.

Also applies to: 29-29, 51-55, 57-58

src/test/java/com/example/solidconnection/mentor/service/MentoringCommandServiceTest.java (1)

137-137: 6) 순서 의존성 제거로 테스트 안정화

  • 설명: participantIds 비교가 containsExactly를 사용해 컬렉션 순서에 의존합니다. JPA 컬렉션 순서는 매핑에 따라 달라질 수 있어 취약합니다.
  • 제안: 순서 무관 비교로 변경하세요.
-            assertAll(
-                    () -> assertThat(afterChatRoom.isGroup()).isFalse(),
-                    () -> assertThat(participantIds).containsExactly(mentorUser1.getId(), menteeUser.getId()),
-                    () -> assertThat(response.chatRoomId()).isEqualTo(afterChatRoom.getId())
-            );
+            assertAll(
+                    () -> assertThat(afterChatRoom.isGroup()).isFalse(),
+                    () -> assertThat(participantIds)
+                          .containsExactlyInAnyOrder(mentorUser1.getId(), menteeUser.getId()),
+                    () -> assertThat(response.chatRoomId()).isEqualTo(afterChatRoom.getId())
+            );

Also applies to: 140-148

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between accbc93 and 8ae9473.

📒 Files selected for processing (7)
  • src/main/java/com/example/solidconnection/chat/repository/ChatRoomRepository.java (1 hunks)
  • src/main/java/com/example/solidconnection/chat/service/ChatService.java (1 hunks)
  • src/main/java/com/example/solidconnection/mentor/dto/MentoringApprovedEvent.java (0 hunks)
  • src/main/java/com/example/solidconnection/mentor/dto/MentoringConfirmResponse.java (1 hunks)
  • src/main/java/com/example/solidconnection/mentor/service/MentoringCommandService.java (3 hunks)
  • src/main/java/com/example/solidconnection/mentor/service/MentoringEventHandler.java (0 hunks)
  • src/test/java/com/example/solidconnection/mentor/service/MentoringCommandServiceTest.java (2 hunks)
💤 Files with no reviewable changes (2)
  • src/main/java/com/example/solidconnection/mentor/service/MentoringEventHandler.java
  • src/main/java/com/example/solidconnection/mentor/dto/MentoringApprovedEvent.java
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
🔇 Additional comments (1)
src/test/java/com/example/solidconnection/mentor/service/MentoringCommandServiceTest.java (1)

183-191: 7) 거절 플로우 검증 명확하고 충분합니다

  • 설명: chatRoomId null과 방 미생성 보장을 함께 확인합니다. 반환 객체 기반의 즉시 검증으로 테스트가 간결해졌습니다.

@Gyuhyeok99 Gyuhyeok99 merged commit dbcfea3 into solid-connection:develop Aug 25, 2025
2 checks passed
@Gyuhyeok99 Gyuhyeok99 deleted the refactor/473-sync-chatroom-creation branch November 9, 2025 09:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor: 채팅방 생성 동기식으로 변경

2 participants