Skip to content

Commit 3ffaa7a

Browse files
loseminhonamgigun
andauthored
Hotfix: 추방된 유저에게 개인 메세지 전송 (#302) (#306)
* refactor: 스더티룸 권한에 대한 로직 개선 * fix: ci에서 통과 못한 테스트코드 수정 * fix:rest api와 웹소켓 중간 경로 통합 * fix:rest api와 웹소켓 중간 경로 통합 * fix: 에러 확인을 위한 통합테스트 추가, Room.create()메서드 수정 * refactor, feat : 조회 분할 * refactor: redis 로직 최적화 및 중복 검증 로직 제거 * fix: 에러 번호 수정 * feat: 스터디룸 방 비밀번호 변경 및 삭제 기능 구현 * fix:app-dev 제거 * feat: 웹소켓 기반 소극적 하트비트 * feat: 스터디룸 썸네일 기능 추가 및 webrtc 설정 변경에서 주석처리 * fix:소극적 하트비트 사용 주석처리 * Feat: 스터디 룸 내에 고양이 아바타 시스템과 프로필 이미지 url 연동 * fix: 기존 작성되어있던 test 코드 수정 * test: 아바타 테스트 코드 완료 * refactor: 프론트엔드 요청 사항에 따른 스터디룸 조회 마스킹 제거 * feat: 스터디룸 방 초대 코드 시스템 * Infra: main branch 로컬 환경과 운영 환경 동기화 * Infra: docker-compose 파일 수정 - Redis 버전 업그레이드 기존: 6.2 -> 변경: 7.0 * Fix: 백엔드 CD 파일 수정 - 자동화 시, 잘못된 도메인으로 호스트 ID 검증하는 오류 해결 * Infra: EC2 환경변수 수정 - 잘못 표기한 도메인 네임 변경 * Chore: CD 파일 수정 - Github Actions commandLine 인식 문제로 인해 set -Eeuo pipefail 줄바꿈 * Chore: 백엔드 CD 파일 수정 - 인스턴스 ID 체크 삭제 * Infra: 백엔드 CD 파일 수정 - .env 파일 추가시, $DOT_ENV_PROD -> $DOT_ENV 로 변경 * Infra: 도커 컴포즈 수정 - mysql 사용자 정보 변경 * Infra: 운영환경 설정 - application-prod.yml 과 application.yml 동기화 * Fix: SecurityConfig 수정 - H2 DB 허용 X * test,fix: 방 초대에 대한 테스트 코드 작성 및 에러 수정 * fix: 스터디룸 파일 업로드 맵핑 형식으로 변환 * fix: 병합충돌 제어 수정 * fix: 병합충돌 제어 * fix: 스터디 룸 내 프론트엔드 요구 사항 및 오류사항 수정 * feat: 방 즐겨찾기, 방 공지사항 구현 * fix: mockbean 수정 * fix: 테스트에서 빠진 비로그인 사용자 추가 * hotfix: 누락된 사용자 추방에 대한 컨트롤러 추가 * hotfix: VISITOR도 추방 가능하도록 수정 * fix: 누락된 테스트코드 추가 및 테스트코드 로직 수정 * refactor: 아바타 시스템 db와 분리 및 테스트 코드 수정 * fix: 턴서버 dev에 맞춤 * hotfix: 추방 후 추방당한 유저에게 개인 메시지 전송 로직 추가 * fix: 웹소켓 메세지 전송 * fix: 병합 오류 제어 * test: 테스트코드 수정 --------- Co-authored-by: namgigun <[email protected]>
1 parent e9a1c5a commit 3ffaa7a

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

src/main/java/com/back/domain/studyroom/service/RoomService.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,8 +719,22 @@ public void kickMember(Long roomId, Long targetUserId, Long requesterId) {
719719

720720
// 4. Redis에서 제거 (강제 퇴장) - VISITOR 포함 모든 사용자
721721
roomParticipantService.exitRoom(targetUserId, roomId);
722+
723+
// 5. 추방당한 유저에게 개인 WebSocket 메시지 전송
724+
java.util.Map<String, Object> kickNotification = new java.util.HashMap<>();
725+
kickNotification.put("type", "MEMBER_KICKED");
726+
kickNotification.put("roomId", roomId);
727+
kickNotification.put("message", "방에서 추방되었습니다");
728+
729+
messagingTemplate.convertAndSendToUser(
730+
targetUserId.toString(),
731+
"/queue/kick",
732+
kickNotification
733+
);
734+
735+
log.info("추방 알림 전송 완료 - RoomId: {}, TargetUserId: {}", roomId, targetUserId);
722736

723-
// 5. 멤버 추방 이벤트 발행
737+
// 6. 멤버 추방 이벤트 발행 (알림 시스템용)
724738
Room room = roomRepository.findById(roomId)
725739
.orElseThrow(() -> new CustomException(ErrorCode.ROOM_NOT_FOUND));
726740

src/test/java/com/back/domain/studyroom/service/RoomServiceTest.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ class RoomServiceTest {
6464

6565
@Mock
6666
private RoomThumbnailService roomThumbnailService;
67+
68+
@Mock
69+
private org.springframework.messaging.simp.SimpMessagingTemplate messagingTemplate;
6770

6871
@InjectMocks
6972
private RoomService roomService;
@@ -400,13 +403,15 @@ void kickMember_Success() {
400403
given(roomMemberRepository.findByRoomIdAndUserId(1L, 1L)).willReturn(Optional.of(hostMember));
401404
given(roomParticipantService.getParticipants(1L)).willReturn(java.util.Set.of(2L)); // 온라인 사용자 목록
402405
given(roomMemberRepository.findByRoomIdAndUserId(1L, 2L)).willReturn(Optional.empty()); // VISITOR는 DB에 없음
403-
given(roomRepository.findById(1L)).willReturn(Optional.of(testRoom));
406+
given(roomRepository.findById(1L)).willReturn(Optional.of(testRoom)); // Room 조회 추가
404407

405408
// when
406409
roomService.kickMember(1L, 2L, 1L);
407410

408411
// then
409412
verify(roomParticipantService, times(1)).exitRoom(2L, 1L); // Redis 퇴장 확인
413+
verify(messagingTemplate, times(1)).convertAndSendToUser(eq("2"), eq("/queue/kick"), any()); // WebSocket 메시지 전송 확인
414+
verify(eventPublisher, times(1)).publishEvent(any(com.back.domain.notification.event.studyroom.MemberKickedEvent.class)); // 이벤트 발행 확인
410415
}
411416

412417
@Test
@@ -418,13 +423,15 @@ void kickMember_VisitorSuccess() {
418423
given(roomMemberRepository.findByRoomIdAndUserId(1L, 1L)).willReturn(Optional.of(hostMember));
419424
given(roomParticipantService.getParticipants(1L)).willReturn(java.util.Set.of(2L)); // VISITOR가 온라인 상태
420425
given(roomMemberRepository.findByRoomIdAndUserId(1L, 2L)).willReturn(Optional.empty()); // DB에 없음
421-
given(roomRepository.findById(1L)).willReturn(Optional.of(testRoom));
426+
given(roomRepository.findById(1L)).willReturn(Optional.of(testRoom)); // Room 조회 추가
422427

423428
// when
424429
roomService.kickMember(1L, 2L, 1L);
425430

426431
// then
427432
verify(roomParticipantService, times(1)).exitRoom(2L, 1L);
433+
verify(messagingTemplate, times(1)).convertAndSendToUser(eq("2"), eq("/queue/kick"), any()); // WebSocket 메시지 전송 확인
434+
verify(eventPublisher, times(1)).publishEvent(any(com.back.domain.notification.event.studyroom.MemberKickedEvent.class)); // 이벤트 발행 확인
428435
}
429436

430437
@Test
@@ -448,13 +455,15 @@ void kickMember_MemberSuccess() {
448455
given(roomMemberRepository.findByRoomIdAndUserId(1L, 1L)).willReturn(Optional.of(hostMember));
449456
given(roomParticipantService.getParticipants(1L)).willReturn(java.util.Set.of(2L)); // MEMBER가 온라인 상태
450457
given(roomMemberRepository.findByRoomIdAndUserId(1L, 2L)).willReturn(Optional.of(targetMember)); // DB에 있음
451-
given(roomRepository.findById(1L)).willReturn(Optional.of(testRoom));
458+
given(roomRepository.findById(1L)).willReturn(Optional.of(testRoom)); // Room 조회 추가
452459

453460
// when
454461
roomService.kickMember(1L, 2L, 1L);
455462

456463
// then
457464
verify(roomParticipantService, times(1)).exitRoom(2L, 1L);
465+
verify(messagingTemplate, times(1)).convertAndSendToUser(eq("2"), eq("/queue/kick"), any()); // WebSocket 메시지 전송 확인
466+
verify(eventPublisher, times(1)).publishEvent(any(com.back.domain.notification.event.studyroom.MemberKickedEvent.class)); // 이벤트 발행 확인
458467
}
459468

460469
@Test

0 commit comments

Comments
 (0)