Skip to content

Commit a5645d5

Browse files
committed
feat: 방 참가자 관리 동시성 수정 및 비밀코드 방 참가 수정
1 parent 35bc0b5 commit a5645d5

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

src/main/java/com/oronaminc/join/room/api/RoomController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public CreateRoomResponse createRoom(
6363
description = "비밀코드를 통해 해당 발표방에 참가자로 등록합니다. 시작 전 상태이면 참가할 수 없습니다.",
6464
security = @SecurityRequirement(name = "sessionAuth")
6565
)
66-
@GetMapping("/code")
66+
@PostMapping("/code")
6767
@ResponseStatus(HttpStatus.OK)
6868
public JoinRoomResponse joinRoom(
6969
@RequestBody JoinRoomRequest joinRoomRequest,

src/main/java/com/oronaminc/join/websocket/session/CurrentParticipantManager.java

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,36 @@ public void createRoom(Long roomId) {
2323
roomParticipants.computeIfAbsent(roomId, k -> ConcurrentHashMap.newKeySet());
2424
}
2525

26+
// public void addParticipant(Long roomId, Long memberId, int limit) {
27+
// Set<Long> participants = getRoomParticipants(roomId);
28+
//
29+
// if (participants.contains(memberId)) return;
30+
//
31+
// synchronized (participants) {
32+
// if (participants.size() >= limit) {
33+
// throw new ErrorException(UNAUTHORIZED_LIMIT_PARTICIPANT);
34+
// }
35+
// participants.add(memberId);
36+
// }
37+
// }
38+
2639
public void addParticipant(Long roomId, Long memberId, int limit) {
27-
Set<Long> participants = getRoomParticipants(roomId);
40+
roomParticipants.compute(roomId, (id, participants) -> {
41+
participants = getRoomParticipants(roomId);
2842

29-
if (participants.contains(memberId)) return;
43+
// 중복 참가자일 경우 그대로 반환 (변화 없음)
44+
if (participants.contains(memberId)) {
45+
return participants;
46+
}
3047

31-
synchronized (participants) {
48+
// 인원 초과 시 예외 발생
3249
if (participants.size() >= limit) {
3350
throw new ErrorException(UNAUTHORIZED_LIMIT_PARTICIPANT);
3451
}
52+
3553
participants.add(memberId);
36-
}
54+
return participants;
55+
});
3756
}
3857

3958
public void removeParticipant(Long memberId, Long roomId) {

0 commit comments

Comments
 (0)