Skip to content

Commit dde13f6

Browse files
loseminhonamgigun
andauthored
Feat/296 (#296) (#312)
* 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: 테스트코드 수정 * refactor: 스터디룸 파일 업로드 s3 + fileAttachment + Mapping 제거 방식으로 수정 * feat: 방 내 방명록 기능 추가 * hotfix:로젝 내 웹소켓 세션 제거 --------- Co-authored-by: namgigun <[email protected]>
1 parent e682644 commit dde13f6

File tree

2 files changed

+28
-16
lines changed

2 files changed

+28
-16
lines changed

src/main/java/com/back/global/websocket/service/RoomParticipantService.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,27 @@ public void handleSessionDisconnected(SessionDisconnectedEvent event) {
4545

4646
// 사용자 방 입장 (아바타 정보 포함)
4747
public void enterRoom(Long userId, Long roomId, Long avatarId) {
48+
// WebSocket 세션 검증 제거 - REST API와 WebSocket 순서 무관하게 동작
4849
WebSocketSessionInfo sessionInfo = redisSessionStore.getUserSession(userId);
4950

50-
if (sessionInfo == null) {
51-
log.warn("세션 정보가 없어 방 입장 실패 - 사용자: {}, 방: {}", userId, roomId);
52-
throw new CustomException(ErrorCode.WS_SESSION_NOT_FOUND);
53-
}
54-
55-
if (sessionInfo.currentRoomId() != null && !sessionInfo.currentRoomId().equals(roomId)) {
51+
// 기존 방에서 퇴장 처리 (세션이 있고, 다른 방에 있는 경우만)
52+
if (sessionInfo != null && sessionInfo.currentRoomId() != null
53+
&& !sessionInfo.currentRoomId().equals(roomId)) {
5654
exitRoom(userId, sessionInfo.currentRoomId());
5755
log.debug("기존 방에서 퇴장 처리 완료 - 사용자: {}, 이전 방: {}",
5856
userId, sessionInfo.currentRoomId());
5957
}
6058

61-
WebSocketSessionInfo updatedSession = sessionInfo.withRoomId(roomId);
62-
redisSessionStore.saveUserSession(userId, updatedSession);
59+
// 세션 정보 업데이트 (세션이 있는 경우만)
60+
if (sessionInfo != null) {
61+
WebSocketSessionInfo updatedSession = sessionInfo.withRoomId(roomId);
62+
redisSessionStore.saveUserSession(userId, updatedSession);
63+
log.debug("WebSocket 세션 업데이트 완료 - 사용자: {}, 방: {}", userId, roomId);
64+
} else {
65+
log.debug("WebSocket 세션 없이 Redis 등록 - 사용자: {}, 방: {} (REST API 우선 호출)", userId, roomId);
66+
}
67+
68+
// Redis에 방 참가자 등록 (세션 없이도 가능!)
6369
redisSessionStore.addUserToRoom(roomId, userId);
6470

6571
// 아바타 정보 저장

src/test/java/com/back/global/websocket/service/RoomParticipantServiceTest.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -156,18 +156,24 @@ void handleSessionDisconnected_ExitsAllRooms() {
156156
}
157157

158158
@Test
159-
@DisplayName("방 입장 - 세션 정보 없음 (예외 발생)")
160-
void enterRoom_NoSession_ThrowsException() {
159+
@DisplayName("방 입장 - 세션 정보 없음 (REST API 우선 호출, 정상 동작)")
160+
void enterRoom_NoSession_SuccessWithoutSession() {
161161
// given
162162
given(redisSessionStore.getUserSession(userId)).willReturn(null);
163+
given(userRepository.findById(userId)).willReturn(Optional.of(testUser));
163164

164-
// when & then
165-
assertThatThrownBy(() -> roomParticipantService.enterRoom(userId, roomId))
166-
.isInstanceOf(CustomException.class)
167-
.hasFieldOrPropertyWithValue("errorCode", ErrorCode.WS_SESSION_NOT_FOUND);
165+
// when
166+
roomParticipantService.enterRoom(userId, roomId);
168167

169-
verify(redisSessionStore, never()).addUserToRoom(anyLong(), anyLong());
170-
verify(messagingTemplate, never()).convertAndSend(anyString(), any(Object.class));
168+
// then
169+
// 세션 업데이트는 건너뛰지만, Redis 등록은 실행됨
170+
verify(redisSessionStore, never()).saveUserSession(eq(userId), any(WebSocketSessionInfo.class));
171+
verify(redisSessionStore).addUserToRoom(roomId, userId);
172+
173+
// 브로드캐스트는 정상 실행
174+
ArgumentCaptor<UserJoinedEvent> eventCaptor = ArgumentCaptor.forClass(UserJoinedEvent.class);
175+
verify(messagingTemplate).convertAndSend(eq("/topic/room/" + roomId + "/events"), eventCaptor.capture());
176+
assertThat(eventCaptor.getValue().getUserId()).isEqualTo(userId);
171177
}
172178

173179
@Test

0 commit comments

Comments
 (0)