Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class RoomController {
@PostMapping
@Operation(
summary = "λ°© 생성",
description = "μƒˆλ‘œμš΄ μŠ€ν„°λ”” 룸을 μƒμ„±ν•©λ‹ˆλ‹€. λ°© μƒμ„±μžλŠ” μžλ™μœΌλ‘œ λ°©μž₯(HOST)이 λ©λ‹ˆλ‹€."
description = "μƒˆλ‘œμš΄ μŠ€ν„°λ”” 룸을 μƒμ„±ν•©λ‹ˆλ‹€. λ°© μƒμ„±μžλŠ” μžλ™μœΌλ‘œ λ°©μž₯(HOST)이 λ©λ‹ˆλ‹€. useWebRTC둜 화상/μŒμ„±/ν™”λ©΄κ³΅μœ  κΈ°λŠ₯을 ν•œ λ²ˆμ— μ œμ–΄ν•  수 μžˆμŠ΅λ‹ˆλ‹€."
)
@ApiResponses({
@ApiResponse(responseCode = "201", description = "λ°© 생성 성곡"),
Expand All @@ -61,7 +61,8 @@ public ResponseEntity<RsData<RoomResponse>> createRoom(
request.getIsPrivate() != null ? request.getIsPrivate() : false,
request.getPassword(),
request.getMaxParticipants() != null ? request.getMaxParticipants() : 10,
currentUserId
currentUserId,
request.getUseWebRTC() != null ? request.getUseWebRTC() : true // λ””ν΄νŠΈ: true
);

RoomResponse response = roomService.toRoomResponse(room);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,10 @@ public class CreateRoomRequest {
@Min(value = 2, message = "μ΅œμ†Œ 2λͺ… 이상이어야 ν•©λ‹ˆλ‹€")
@Max(value = 100, message = "μ΅œλŒ€ 100λͺ…κΉŒμ§€ κ°€λŠ₯ν•©λ‹ˆλ‹€")
private Integer maxParticipants = 10;

// WebRTC 톡합 μ œμ–΄ ν•„λ“œ (카메라, μ˜€λ””μ˜€, ν™”λ©΄κ³΅μœ λ₯Ό ν•œ λ²ˆμ— μ œμ–΄)
// true: WebRTC κΈ°λŠ₯ 전체 ν™œμ„±ν™”
// false: WebRTC κΈ°λŠ₯ 전체 λΉ„ν™œμ„±ν™”
// null: λ””ν΄νŠΈ true둜 처리
private Boolean useWebRTC = true;
}
8 changes: 8 additions & 0 deletions src/main/java/com/back/domain/studyroom/dto/RoomResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ public class RoomResponse {
private String createdBy;
private LocalDateTime createdAt;

// WebRTC μ„€μ • 정보 (ν”„λ‘ νŠΈμ—”λ“œμ—μ„œ UI μ œμ–΄μš©)
private Boolean allowCamera;
private Boolean allowAudio;
private Boolean allowScreenShare;

public static RoomResponse from(Room room, long currentParticipants) {
return RoomResponse.builder()
.roomId(room.getId())
Expand All @@ -29,6 +34,9 @@ public static RoomResponse from(Room room, long currentParticipants) {
.status(room.getStatus())
.createdBy(room.getCreatedBy().getNickname())
.createdAt(room.getCreatedAt())
.allowCamera(room.isAllowCamera())
.allowAudio(room.isAllowAudio())
.allowScreenShare(room.isAllowScreenShare())
.build();
}
}
10 changes: 6 additions & 4 deletions src/main/java/com/back/domain/studyroom/entity/Room.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,19 +168,21 @@ public boolean isOwner(Long userId) {
* λ°© 생성을 μœ„ν•œ 정적 νŒ©ν† λ¦¬ λ©”μ„œλ“œ
μƒˆλ‘œμš΄ 방을 생성할 λ•Œ λͺ¨λ“  기본값을 μ„€μ • ν•΄μ£ΌλŠ” 초기 λ©”μ„œλ“œ
κΈ°λ³Έ μƒνƒœμ—μ„œ λ°©μž₯이 μž„μ˜λ‘œ λ³€ν˜•ν•˜κ³  싢은 λΆ€λΆ„λ§Œ λ³€κ²½ν•΄μ„œ μ‚¬μš© κ°€λŠ₯
* @param useWebRTC WebRTC μ‚¬μš© μ—¬λΆ€ (true: 카메라/μ˜€λ””μ˜€/ν™”λ©΄κ³΅μœ  전체 ν™œμ„±ν™”, false: 전체 λΉ„ν™œμ„±ν™”)
*/
public static Room create(String title, String description, boolean isPrivate,
String password, int maxParticipants, User creator, RoomTheme theme) {
String password, int maxParticipants, User creator, RoomTheme theme,
boolean useWebRTC) {
Room room = new Room();
room.title = title;
room.description = description;
room.isPrivate = isPrivate;
room.password = password;
room.maxParticipants = maxParticipants;
room.isActive = true; // 생성 μ‹œ 기본적으둜 ν™œμ„±ν™”
room.allowCamera = true; // 기본적으둜 카메라 ν—ˆμš©
room.allowAudio = true; // 기본적으둜 μ˜€λ””μ˜€ ν—ˆμš©
room.allowScreenShare = true; // 기본적으둜 ν™”λ©΄ 곡유 ν—ˆμš©
room.allowCamera = useWebRTC; // WebRTC μ‚¬μš© 여뢀에 따라 μ„€μ •
room.allowAudio = useWebRTC; // WebRTC μ‚¬μš© 여뢀에 따라 μ„€μ •
room.allowScreenShare = useWebRTC; // WebRTC μ‚¬μš© 여뢀에 따라 μ„€μ •
room.status = RoomStatus.WAITING; // 생성 μ‹œ λŒ€κΈ° μƒνƒœ
room.currentParticipants = 0; // 생성 μ‹œ μ°Έκ°€μž 0λͺ…
room.createdBy = creator;
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/com/back/domain/studyroom/service/RoomService.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,26 +52,26 @@ public class RoomService {

* κΈ°λ³Έ μ„€μ •:
- μƒνƒœ: WAITING (λŒ€κΈ° 쀑)
- 카메라/μ˜€λ””μ˜€/ν™”λ©΄κ³΅μœ : application.yml의 μ„€μ •κ°’ μ‚¬μš©
- WebRTC: useWebRTC νŒŒλΌλ―Έν„°μ— 따라 카메라/μ˜€λ””μ˜€/ν™”λ©΄κ³΅μœ  톡합 μ œμ–΄
- μ°Έκ°€μž 수: 0λͺ…μ—μ„œ μ‹œμž‘ ν›„ λ°©μž₯ μΆ”κ°€λ‘œ 1λͺ…
*/
@Transactional
public Room createRoom(String title, String description, boolean isPrivate,
String password, int maxParticipants, Long creatorId) {
String password, int maxParticipants, Long creatorId, boolean useWebRTC) {

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

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

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

// savedRoom.incrementParticipant(); // Redis둜 이관 - DB μ—…λ°μ΄νŠΈ 제거

log.info("λ°© 생성 μ™„λ£Œ - RoomId: {}, Title: {}, CreatorId: {}",
savedRoom.getId(), title, creatorId);
log.info("λ°© 생성 μ™„λ£Œ - RoomId: {}, Title: {}, CreatorId: {}, WebRTC: {}",
savedRoom.getId(), title, creatorId, useWebRTC);

return savedRoom;
}
Expand Down Expand Up @@ -127,7 +127,7 @@ public RoomMember joinRoom(Long roomId, String password, Long userId) {
// TODO: Redisμ—μ„œ 온라인 μ—¬λΆ€ ν™•μΈν•˜λ„λ‘ λ³€κ²½
// ν˜„μž¬λŠ” κΈ°μ‘΄ 멀버 μž¬μž…μž₯ ν—ˆμš©
// room.incrementParticipant(); // Redis둜 이관 - DB μ—…λ°μ΄νŠΈ 제거
room.incrementParticipant();

return member;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,16 @@ void setUp() {
userProfile.setNickname("ν…ŒμŠ€νŠΈμœ μ €");
testUser.setUserProfile(userProfile);

// ν…ŒμŠ€νŠΈ λ°© 생성
// ν…ŒμŠ€νŠΈ λ°© 생성 (WebRTC μ‚¬μš©)
testRoom = Room.create(
"ν…ŒμŠ€νŠΈ λ°©",
"ν…ŒμŠ€νŠΈ μ„€λͺ…",
false,
null,
10,
testUser,
null
null,
true // useWebRTC
);

// ν…ŒμŠ€νŠΈ 멀버 생성
Expand All @@ -94,7 +95,8 @@ void createRoom() {
"ν…ŒμŠ€νŠΈ μ„€λͺ…",
false,
null,
10
10,
true // useWebRTC
);

given(roomService.createRoom(
Expand All @@ -103,7 +105,8 @@ void createRoom() {
anyBoolean(),
any(),
anyInt(),
eq(1L)
eq(1L),
anyBoolean() // useWebRTC νŒŒλΌλ―Έν„° μΆ”κ°€
)).willReturn(testRoom);

RoomResponse roomResponse = RoomResponse.from(testRoom, 1);
Expand All @@ -125,7 +128,8 @@ void createRoom() {
anyBoolean(),
any(),
anyInt(),
eq(1L)
eq(1L),
anyBoolean() // useWebRTC νŒŒλΌλ―Έν„° μΆ”κ°€
);
verify(roomService, times(1)).toRoomResponse(any(Room.class));
}
Expand Down Expand Up @@ -365,5 +369,126 @@ void getPopularRooms() {

verify(roomService, times(1)).getPopularRooms(any());
verify(roomService, times(1)).toRoomResponseList(anyList());

}

@Test
@DisplayName("λ°© 생성 API - WebRTC ν™œμ„±ν™” ν…ŒμŠ€νŠΈ")
void createRoom_WithWebRTC() {
// given
given(currentUser.getUserId()).willReturn(1L);

CreateRoomRequest request = new CreateRoomRequest(
"WebRTC λ°©",
"화상 μ±„νŒ… κ°€λŠ₯",
false,
null,
10,
true // WebRTC ν™œμ„±ν™”
);

Room webRTCRoom = Room.create(
"WebRTC λ°©",
"화상 μ±„νŒ… κ°€λŠ₯",
false,
null,
10,
testUser,
null,
true
);

given(roomService.createRoom(
anyString(),
anyString(),
anyBoolean(),
any(),
anyInt(),
eq(1L),
eq(true) // WebRTC true 검증
)).willReturn(webRTCRoom);

RoomResponse roomResponse = RoomResponse.from(webRTCRoom, 1);
given(roomService.toRoomResponse(any(Room.class))).willReturn(roomResponse);

// when
ResponseEntity<RsData<RoomResponse>> response = roomController.createRoom(request);

// then
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.CREATED);
assertThat(response.getBody()).isNotNull();
assertThat(response.getBody().getData().getAllowCamera()).isTrue();
assertThat(response.getBody().getData().getAllowAudio()).isTrue();
assertThat(response.getBody().getData().getAllowScreenShare()).isTrue();

verify(roomService, times(1)).createRoom(
anyString(),
anyString(),
anyBoolean(),
any(),
anyInt(),
eq(1L),
eq(true)
);
}

@Test
@DisplayName("λ°© 생성 API - WebRTC λΉ„ν™œμ„±ν™” ν…ŒμŠ€νŠΈ")
void createRoom_WithoutWebRTC() {
// given
given(currentUser.getUserId()).willReturn(1L);

CreateRoomRequest request = new CreateRoomRequest(
"μ±„νŒ… μ „μš© λ°©",
"ν…μŠ€νŠΈλ§Œ κ°€λŠ₯",
false,
null,
50,
false // WebRTC λΉ„ν™œμ„±ν™”
);

Room chatOnlyRoom = Room.create(
"μ±„νŒ… μ „μš© λ°©",
"ν…μŠ€νŠΈλ§Œ κ°€λŠ₯",
false,
null,
50,
testUser,
null,
false
);

given(roomService.createRoom(
anyString(),
anyString(),
anyBoolean(),
any(),
anyInt(),
eq(1L),
eq(false) // WebRTC false 검증
)).willReturn(chatOnlyRoom);

RoomResponse roomResponse = RoomResponse.from(chatOnlyRoom, 1);
given(roomService.toRoomResponse(any(Room.class))).willReturn(roomResponse);

// when
ResponseEntity<RsData<RoomResponse>> response = roomController.createRoom(request);

// then
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.CREATED);
assertThat(response.getBody()).isNotNull();
assertThat(response.getBody().getData().getAllowCamera()).isFalse();
assertThat(response.getBody().getData().getAllowAudio()).isFalse();
assertThat(response.getBody().getData().getAllowScreenShare()).isFalse();

verify(roomService, times(1)).createRoom(
anyString(),
anyString(),
anyBoolean(),
any(),
anyInt(),
eq(1L),
eq(false)
);
}
}
Loading