Skip to content

Commit 3b954c2

Browse files
loseminhonamgigun
authored andcommitted
Refactor/156 (#156) (#157)
* refactor: RoomMember 엔티티에서 실시간 상태 필드 제거, redis로 이관 * feat:제거 기반 redis 연동 테스트 완료 * refactor: 방 생성 시 webRTC 제어 가능하게 구현
1 parent 2de4b56 commit 3b954c2

File tree

7 files changed

+222
-23
lines changed

7 files changed

+222
-23
lines changed

src/main/java/com/back/domain/studyroom/controller/RoomController.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class RoomController {
4343
@PostMapping
4444
@Operation(
4545
summary = "방 생성",
46-
description = "새로운 스터디 룸을 생성합니다. 방 생성자는 자동으로 방장(HOST)이 됩니다."
46+
description = "새로운 스터디 룸을 생성합니다. 방 생성자는 자동으로 방장(HOST)이 됩니다. useWebRTC로 화상/음성/화면공유 기능을 한 번에 제어할 수 있습니다."
4747
)
4848
@ApiResponses({
4949
@ApiResponse(responseCode = "201", description = "방 생성 성공"),
@@ -61,7 +61,8 @@ public ResponseEntity<RsData<RoomResponse>> createRoom(
6161
request.getIsPrivate() != null ? request.getIsPrivate() : false,
6262
request.getPassword(),
6363
request.getMaxParticipants() != null ? request.getMaxParticipants() : 10,
64-
currentUserId
64+
currentUserId,
65+
request.getUseWebRTC() != null ? request.getUseWebRTC() : true // 디폴트: true
6566
);
6667

6768
RoomResponse response = roomService.toRoomResponse(room);

src/main/java/com/back/domain/studyroom/dto/CreateRoomRequest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,10 @@ public class CreateRoomRequest {
2323
@Min(value = 2, message = "최소 2명 이상이어야 합니다")
2424
@Max(value = 100, message = "최대 100명까지 가능합니다")
2525
private Integer maxParticipants = 10;
26+
27+
// WebRTC 통합 제어 필드 (카메라, 오디오, 화면공유를 한 번에 제어)
28+
// true: WebRTC 기능 전체 활성화
29+
// false: WebRTC 기능 전체 비활성화
30+
// null: 디폴트 true로 처리
31+
private Boolean useWebRTC = true;
2632
}

src/main/java/com/back/domain/studyroom/dto/RoomResponse.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ public class RoomResponse {
1919
private String createdBy;
2020
private LocalDateTime createdAt;
2121

22+
// WebRTC 설정 정보 (프론트엔드에서 UI 제어용)
23+
private Boolean allowCamera;
24+
private Boolean allowAudio;
25+
private Boolean allowScreenShare;
26+
2227
public static RoomResponse from(Room room, long currentParticipants) {
2328
return RoomResponse.builder()
2429
.roomId(room.getId())
@@ -29,6 +34,9 @@ public static RoomResponse from(Room room, long currentParticipants) {
2934
.status(room.getStatus())
3035
.createdBy(room.getCreatedBy().getNickname())
3136
.createdAt(room.getCreatedAt())
37+
.allowCamera(room.isAllowCamera())
38+
.allowAudio(room.isAllowAudio())
39+
.allowScreenShare(room.isAllowScreenShare())
3240
.build();
3341
}
3442
}

src/main/java/com/back/domain/studyroom/entity/Room.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,19 +168,21 @@ public boolean isOwner(Long userId) {
168168
* 방 생성을 위한 정적 팩토리 메서드
169169
새로운 방을 생성할 때 모든 기본값을 설정 해주는 초기 메서드
170170
기본 상태에서 방장이 임의로 변형하고 싶은 부분만 변경해서 사용 가능
171+
* @param useWebRTC WebRTC 사용 여부 (true: 카메라/오디오/화면공유 전체 활성화, false: 전체 비활성화)
171172
*/
172173
public static Room create(String title, String description, boolean isPrivate,
173-
String password, int maxParticipants, User creator, RoomTheme theme) {
174+
String password, int maxParticipants, User creator, RoomTheme theme,
175+
boolean useWebRTC) {
174176
Room room = new Room();
175177
room.title = title;
176178
room.description = description;
177179
room.isPrivate = isPrivate;
178180
room.password = password;
179181
room.maxParticipants = maxParticipants;
180182
room.isActive = true; // 생성 시 기본적으로 활성화
181-
room.allowCamera = true; // 기본적으로 카메라 허용
182-
room.allowAudio = true; // 기본적으로 오디오 허용
183-
room.allowScreenShare = true; // 기본적으로 화면 공유 허용
183+
room.allowCamera = useWebRTC; // WebRTC 사용 여부에 따라 설정
184+
room.allowAudio = useWebRTC; // WebRTC 사용 여부에 따라 설정
185+
room.allowScreenShare = useWebRTC; // WebRTC 사용 여부에 따라 설정
184186
room.status = RoomStatus.WAITING; // 생성 시 대기 상태
185187
room.currentParticipants = 0; // 생성 시 참가자 0명
186188
room.createdBy = creator;

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,26 +52,26 @@ public class RoomService {
5252
5353
* 기본 설정:
5454
- 상태: WAITING (대기 중)
55-
- 카메라/오디오/화면공유: application.yml의 설정값 사용
55+
- WebRTC: useWebRTC 파라미터에 따라 카메라/오디오/화면공유 통합 제어
5656
- 참가자 수: 0명에서 시작 후 방장 추가로 1명
5757
*/
5858
@Transactional
5959
public Room createRoom(String title, String description, boolean isPrivate,
60-
String password, int maxParticipants, Long creatorId) {
60+
String password, int maxParticipants, Long creatorId, boolean useWebRTC) {
6161

6262
User creator = userRepository.findById(creatorId)
6363
.orElseThrow(() -> new CustomException(ErrorCode.USER_NOT_FOUND));
6464

65-
Room room = Room.create(title, description, isPrivate, password, maxParticipants, creator, null);
65+
Room room = Room.create(title, description, isPrivate, password, maxParticipants, creator, null, useWebRTC);
6666
Room savedRoom = roomRepository.save(room);
6767

6868
RoomMember hostMember = RoomMember.createHost(savedRoom, creator);
6969
roomMemberRepository.save(hostMember);
7070

7171
// savedRoom.incrementParticipant(); // Redis로 이관 - DB 업데이트 제거
7272

73-
log.info("방 생성 완료 - RoomId: {}, Title: {}, CreatorId: {}",
74-
savedRoom.getId(), title, creatorId);
73+
log.info("방 생성 완료 - RoomId: {}, Title: {}, CreatorId: {}, WebRTC: {}",
74+
savedRoom.getId(), title, creatorId, useWebRTC);
7575

7676
return savedRoom;
7777
}
@@ -127,7 +127,7 @@ public RoomMember joinRoom(Long roomId, String password, Long userId) {
127127
// TODO: Redis에서 온라인 여부 확인하도록 변경
128128
// 현재는 기존 멤버 재입장 허용
129129
// room.incrementParticipant(); // Redis로 이관 - DB 업데이트 제거
130-
room.incrementParticipant();
130+
131131
return member;
132132
}
133133

src/test/java/com/back/domain/studyroom/controller/RoomControllerTest.java

Lines changed: 130 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,16 @@ void setUp() {
6666
userProfile.setNickname("테스트유저");
6767
testUser.setUserProfile(userProfile);
6868

69-
// 테스트 방 생성
69+
// 테스트 방 생성 (WebRTC 사용)
7070
testRoom = Room.create(
7171
"테스트 방",
7272
"테스트 설명",
7373
false,
7474
null,
7575
10,
7676
testUser,
77-
null
77+
null,
78+
true // useWebRTC
7879
);
7980

8081
// 테스트 멤버 생성
@@ -94,7 +95,8 @@ void createRoom() {
9495
"테스트 설명",
9596
false,
9697
null,
97-
10
98+
10,
99+
true // useWebRTC
98100
);
99101

100102
given(roomService.createRoom(
@@ -103,7 +105,8 @@ void createRoom() {
103105
anyBoolean(),
104106
any(),
105107
anyInt(),
106-
eq(1L)
108+
eq(1L),
109+
anyBoolean() // useWebRTC 파라미터 추가
107110
)).willReturn(testRoom);
108111

109112
RoomResponse roomResponse = RoomResponse.from(testRoom, 1);
@@ -125,7 +128,8 @@ void createRoom() {
125128
anyBoolean(),
126129
any(),
127130
anyInt(),
128-
eq(1L)
131+
eq(1L),
132+
anyBoolean() // useWebRTC 파라미터 추가
129133
);
130134
verify(roomService, times(1)).toRoomResponse(any(Room.class));
131135
}
@@ -365,5 +369,126 @@ void getPopularRooms() {
365369

366370
verify(roomService, times(1)).getPopularRooms(any());
367371
verify(roomService, times(1)).toRoomResponseList(anyList());
372+
373+
}
374+
375+
@Test
376+
@DisplayName("방 생성 API - WebRTC 활성화 테스트")
377+
void createRoom_WithWebRTC() {
378+
// given
379+
given(currentUser.getUserId()).willReturn(1L);
380+
381+
CreateRoomRequest request = new CreateRoomRequest(
382+
"WebRTC 방",
383+
"화상 채팅 가능",
384+
false,
385+
null,
386+
10,
387+
true // WebRTC 활성화
388+
);
389+
390+
Room webRTCRoom = Room.create(
391+
"WebRTC 방",
392+
"화상 채팅 가능",
393+
false,
394+
null,
395+
10,
396+
testUser,
397+
null,
398+
true
399+
);
400+
401+
given(roomService.createRoom(
402+
anyString(),
403+
anyString(),
404+
anyBoolean(),
405+
any(),
406+
anyInt(),
407+
eq(1L),
408+
eq(true) // WebRTC true 검증
409+
)).willReturn(webRTCRoom);
410+
411+
RoomResponse roomResponse = RoomResponse.from(webRTCRoom, 1);
412+
given(roomService.toRoomResponse(any(Room.class))).willReturn(roomResponse);
413+
414+
// when
415+
ResponseEntity<RsData<RoomResponse>> response = roomController.createRoom(request);
416+
417+
// then
418+
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.CREATED);
419+
assertThat(response.getBody()).isNotNull();
420+
assertThat(response.getBody().getData().getAllowCamera()).isTrue();
421+
assertThat(response.getBody().getData().getAllowAudio()).isTrue();
422+
assertThat(response.getBody().getData().getAllowScreenShare()).isTrue();
423+
424+
verify(roomService, times(1)).createRoom(
425+
anyString(),
426+
anyString(),
427+
anyBoolean(),
428+
any(),
429+
anyInt(),
430+
eq(1L),
431+
eq(true)
432+
);
433+
}
434+
435+
@Test
436+
@DisplayName("방 생성 API - WebRTC 비활성화 테스트")
437+
void createRoom_WithoutWebRTC() {
438+
// given
439+
given(currentUser.getUserId()).willReturn(1L);
440+
441+
CreateRoomRequest request = new CreateRoomRequest(
442+
"채팅 전용 방",
443+
"텍스트만 가능",
444+
false,
445+
null,
446+
50,
447+
false // WebRTC 비활성화
448+
);
449+
450+
Room chatOnlyRoom = Room.create(
451+
"채팅 전용 방",
452+
"텍스트만 가능",
453+
false,
454+
null,
455+
50,
456+
testUser,
457+
null,
458+
false
459+
);
460+
461+
given(roomService.createRoom(
462+
anyString(),
463+
anyString(),
464+
anyBoolean(),
465+
any(),
466+
anyInt(),
467+
eq(1L),
468+
eq(false) // WebRTC false 검증
469+
)).willReturn(chatOnlyRoom);
470+
471+
RoomResponse roomResponse = RoomResponse.from(chatOnlyRoom, 1);
472+
given(roomService.toRoomResponse(any(Room.class))).willReturn(roomResponse);
473+
474+
// when
475+
ResponseEntity<RsData<RoomResponse>> response = roomController.createRoom(request);
476+
477+
// then
478+
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.CREATED);
479+
assertThat(response.getBody()).isNotNull();
480+
assertThat(response.getBody().getData().getAllowCamera()).isFalse();
481+
assertThat(response.getBody().getData().getAllowAudio()).isFalse();
482+
assertThat(response.getBody().getData().getAllowScreenShare()).isFalse();
483+
484+
verify(roomService, times(1)).createRoom(
485+
anyString(),
486+
anyString(),
487+
anyBoolean(),
488+
any(),
489+
anyInt(),
490+
eq(1L),
491+
eq(false)
492+
);
368493
}
369494
}

0 commit comments

Comments
 (0)