-
Notifications
You must be signed in to change notification settings - Fork 8
feat: 채팅방 partner 정보를 조회하는 API 추가 #457
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: 채팅방 partner 정보를 조회하는 API 추가 #457
Conversation
Walkthrough
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Suggested reviewers
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 unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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/test/java/com/example/solidconnection/chat/service/ChatServiceTest.java (1)
313-334: 3) 보안/권한 검증 경로의 테스트도 추가해 주세요.
성공 케이스는 좋습니다만, 비참여자 접근 차단 및 그룹방 예외 등 실패 경로를 함께 검증하면 회귀를 방지할 수 있습니다.
- 제안: 아래 두 케이스를 같은 Nested 블록에 추가해 주세요.
- 비참여자가 파트너 조회 시도 시 CHAT_PARTICIPANT_NOT_FOUND 예외
- 그룹 채팅방에서 파트너 조회 시 INVALID_CHAT_ROOM_STATE 예외
적용 diff 예시:
@Nested class 채팅방_파트너_정보를_조회한다 { @Test void 채팅방_파트너를_정상_조회한다() { // given ChatRoom chatRoom = chatRoomFixture.채팅방(false); chatParticipantFixture.참여자(user.getId(), chatRoom); chatParticipantFixture.참여자(mentor1.getId(), chatRoom); // when ChatParticipantResponse response = chatService.getChatPartner(user.getId(), chatRoom.getId()); // then assertAll( () -> assertThat(response.partnerId()).isEqualTo(mentor1.getId()), () -> assertThat(response.nickname()).isEqualTo(mentor1.getNickname()), () -> assertThat(response.profileUrl()).isEqualTo(mentor1.getProfileImageUrl()) ); } + + @Test + void 비참여자는_파트너를_조회할_수_없다() { + // given + ChatRoom chatRoom = chatRoomFixture.채팅방(false); + chatParticipantFixture.참여자(user.getId(), chatRoom); + chatParticipantFixture.참여자(mentor1.getId(), chatRoom); + + // when & then + assertThatCode(() -> chatService.getChatPartner(mentor2.getId(), chatRoom.getId())) + .isInstanceOf(CustomException.class) + .hasMessage(CHAT_PARTICIPANT_NOT_FOUND.getMessage()); + } + + @Test + void 그룹_채팅방에서는_예외가_발생한다() { + // given + ChatRoom groupRoom = chatRoomFixture.채팅방(true); + chatParticipantFixture.참여자(user.getId(), groupRoom); + chatParticipantFixture.참여자(mentor1.getId(), groupRoom); + chatParticipantFixture.참여자(mentor2.getId(), groupRoom); + + // when & then + assertThatCode(() -> chatService.getChatPartner(user.getId(), groupRoom.getId())) + .isInstanceOf(CustomException.class) + .hasMessage(INVALID_CHAT_ROOM_STATE.getMessage()); + } }원하시면 위 테스트 추가분을 포함해 PR에 맞춰 전체 테스트 정리본을 드릴게요.
src/main/java/com/example/solidconnection/chat/controller/ChatController.java (1)
45-52: 3) (선택) roomId 타입을 long으로 정규화하면 일관성이 좋아집니다.
동일 컨트롤러의 다른 메서드들과 파라미터 타입 일관성 유지에 도움이 됩니다.- public ResponseEntity<ChatParticipantResponse> getChatPartner( - @AuthorizedUser long siteUserId, - @PathVariable("room-id") Long roomId - ) { + public ResponseEntity<ChatParticipantResponse> getChatPartner( + @AuthorizedUser long siteUserId, + @PathVariable("room-id") long roomId + ) {src/main/java/com/example/solidconnection/chat/service/ChatService.java (2)
110-118: 2) (선택) findPartner 내부에 ‘요청자 참여 여부’ 체크를 포함하면 응집도가 높아집니다.
대안으로, findPartner가 그룹 예외뿐 아니라 비참여자 접근도 즉시 차단하게 만들면 호출부 실수를 방지할 수 있습니다.private ChatParticipant findPartner(ChatRoom chatRoom, long siteUserId) { if (chatRoom.isGroup()) { throw new CustomException(INVALID_CHAT_ROOM_STATE); } + boolean isMember = chatRoom.getChatParticipants().stream() + .anyMatch(participant -> participant.getSiteUserId() == siteUserId); + if (!isMember) { + throw new CustomException(CHAT_PARTICIPANT_NOT_FOUND); + } return chatRoom.getChatParticipants().stream() .filter(participant -> participant.getSiteUserId() != siteUserId) .findFirst() .orElseThrow(() -> new CustomException(CHAT_PARTNER_NOT_FOUND)); }
100-101: 3) (선택) roomId를 long으로 변경해 메서드 시그니처 일관성을 높여주세요.
동일 클래스 내 다른 메서드(getChatMessages, markChatMessagesAsRead 등)는 원시 타입(long)을 사용합니다.- public ChatParticipantResponse getChatPartner(long siteUserId, Long roomId) { + public ChatParticipantResponse getChatPartner(long siteUserId, long roomId) {
📜 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.
📒 Files selected for processing (3)
src/main/java/com/example/solidconnection/chat/controller/ChatController.java(2 hunks)src/main/java/com/example/solidconnection/chat/service/ChatService.java(1 hunks)src/test/java/com/example/solidconnection/chat/service/ChatServiceTest.java(2 hunks)
🔇 Additional comments (4)
src/test/java/com/example/solidconnection/chat/service/ChatServiceTest.java (2)
17-17: 1) ChatParticipantResponse 임포트 추가, 잘 연결되었습니다.
한 문장으로 요약하면, 서비스/컨트롤러 변경과 테스트 타입이 일치해 좋습니다.
313-334: 2) 파트너 정보 정상 조회 테스트 케이스, 시나리오 적합합니다.
성공 경로를 실제 도메인 흐름(1:1 방, 두 명 참여자, 요청자 기준 파트너 도출)으로 검증해 신뢰도를 높입니다.src/main/java/com/example/solidconnection/chat/controller/ChatController.java (2)
4-4: 1) 컨트롤러에서 DTO 임포트 경로 일관성 유지, 좋습니다.
서비스/컨트롤러가 동일한 DTO 패키지를 사용해 타입 충돌 여지가 없습니다.
45-52: 2) 엔드포인트 경로에 선행 슬래시 누락 — 실제 매핑이 깨집니다.
현재 @GetMapping("rooms/{room-id}/partner")는 클래스 레벨 "/chats"와 문자열 결합되어 "/chatsrooms/{room-id}/partner"로 매핑될 수 있습니다.
- 수정안: 선행 슬래시를 추가해 "/chats/rooms/{room-id}/partner"가 되도록 고쳐주세요.
- @GetMapping("rooms/{room-id}/partner") + @GetMapping("/rooms/{room-id}/partner") public ResponseEntity<ChatParticipantResponse> getChatPartner( @AuthorizedUser long siteUserId, @PathVariable("room-id") Long roomId ) { ChatParticipantResponse response = chatService.getChatPartner(siteUserId, roomId); return ResponseEntity.ok(response); }Likely an incorrect or invalid review comment.
src/main/java/com/example/solidconnection/chat/controller/ChatController.java
Show resolved
Hide resolved
whqtker
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
좋습니다 ! 빠른 반영 감사합니다 👏
관련 이슈
작업 내용
만욱님께서 요청해주신 기능을 구현한 pr입니다.
bruno 관련
특이 사항
리뷰 요구사항 (선택)