Skip to content

Commit e2c0482

Browse files
committed
hotfix: 방 조회 시 terminated 상태는 조회 안되도록
1 parent 0747c30 commit e2c0482

File tree

1 file changed

+40
-21
lines changed

1 file changed

+40
-21
lines changed

src/main/java/com/back/domain/studyroom/repository/RoomRepositoryImpl.java

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ public class RoomRepositoryImpl implements RoomRepositoryCustom {
3333
private final QUser user = QUser.user;
3434

3535
/**
36-
* 공개 방 중 입장 가능한 방들 조회 (페이징)
36+
* 공개 방 중 입장 가능한 방들 조회 (페이징, TERMINATED 제외)
3737
* 조회 조건:
3838
* - 비공개가 아닌 방 (isPrivate = false)
3939
* - 활성화된 방 (isActive = true)
4040
* - 입장 가능한 상태 (WAITING 또는 ACTIVE)
41-
*
41+
*
4242
* 참고: 정원 체크는 Redis 기반으로 프론트엔드/서비스에서 수행
4343
* @param pageable 페이징 정보
4444
* @return 페이징된 방 목록
@@ -52,7 +52,8 @@ public Page<Room> findJoinablePublicRooms(Pageable pageable) {
5252
.where(
5353
room.isPrivate.eq(false),
5454
room.isActive.eq(true),
55-
room.status.in(RoomStatus.WAITING, RoomStatus.ACTIVE)
55+
room.status.in(RoomStatus.WAITING, RoomStatus.ACTIVE), // WAITING, ACTIVE만 (TERMINATED, PAUSED 제외)
56+
room.status.ne(RoomStatus.TERMINATED) // TERMINATED 명시적 제외
5657
)
5758
.orderBy(room.createdAt.desc())
5859
.offset(pageable.getOffset())
@@ -66,15 +67,16 @@ public Page<Room> findJoinablePublicRooms(Pageable pageable) {
6667
.where(
6768
room.isPrivate.eq(false),
6869
room.isActive.eq(true),
69-
room.status.in(RoomStatus.WAITING, RoomStatus.ACTIVE)
70+
room.status.in(RoomStatus.WAITING, RoomStatus.ACTIVE),
71+
room.status.ne(RoomStatus.TERMINATED)
7072
)
7173
.fetchOne();
7274

7375
return new PageImpl<>(rooms, pageable, totalCount != null ? totalCount : 0);
7476
}
7577

7678
/**
77-
* 사용자가 참여 중인 방 조회 (MEMBER 이상만)
79+
* 사용자가 참여 중인 방 조회 (MEMBER 이상만, TERMINATED 제외)
7880
* 조회 조건:
7981
* - 특정 사용자가 MEMBER 이상으로 등록된 방 (VISITOR 제외)
8082
* - DB에 저장된 멤버십만 조회
@@ -89,7 +91,8 @@ public List<Room> findRoomsByUserId(Long userId) {
8991
.join(room.roomMembers, roomMember) // 멤버 조인
9092
.where(
9193
roomMember.user.id.eq(userId),
92-
roomMember.role.ne(com.back.domain.studyroom.entity.RoomRole.VISITOR) // VISITOR 제외
94+
roomMember.role.ne(com.back.domain.studyroom.entity.RoomRole.VISITOR), // VISITOR 제외
95+
room.status.ne(RoomStatus.TERMINATED) // TERMINATED 제외
9396
)
9497
.fetch();
9598
}
@@ -160,7 +163,7 @@ public Page<Room> findRoomsWithFilters(String title, RoomStatus status, Boolean
160163
}
161164

162165
/**
163-
* 인기 방 조회 (참가자 수 기준) - 공개+비공개 포함
166+
* 인기 방 조회 (참가자 수 기준, TERMINATED 제외)
164167
*
165168
* 참고: 참가자 수는 Redis에서 조회하므로 DB에서는 정렬 불가
166169
* 서비스 레이어에서 Redis 데이터로 정렬 필요
@@ -177,7 +180,8 @@ public Page<Room> findPopularRooms(Pageable pageable) {
177180
.selectFrom(room)
178181
.leftJoin(room.createdBy, user).fetchJoin() // N+1 방지
179182
.where(
180-
room.isActive.eq(true)
183+
room.isActive.eq(true),
184+
room.status.ne(RoomStatus.TERMINATED) // TERMINATED 제외
181185
)
182186
.orderBy(room.createdAt.desc()) // 최신순 (서비스에서 Redis 기반으로 재정렬)
183187
.offset(pageable.getOffset())
@@ -189,7 +193,8 @@ public Page<Room> findPopularRooms(Pageable pageable) {
189193
.select(room.count())
190194
.from(room)
191195
.where(
192-
room.isActive.eq(true)
196+
room.isActive.eq(true),
197+
room.status.ne(RoomStatus.TERMINATED) // TERMINATED 제외
193198
)
194199
.fetchOne();
195200

@@ -272,23 +277,26 @@ public Optional<Room> findByIdWithLock(Long roomId) {
272277
}
273278

274279
/**
275-
* 모든 방 조회 (공개 + 비공개 전체)
280+
* 모든 방 조회 (공개 + 비공개 전체, TERMINATED 제외)
276281
* 조회 조건:
277282
* - 모든 방 (공개 + 비공개)
278283
* 정렬:
279284
* 1. 열린 방(WAITING, ACTIVE) 우선
280285
* 2. 닫힌 방(PAUSED, TERMINATED) 뒤로
281286
* 3. 최신 생성순
282-
*
287+
*
283288
* 비공개 방은 컨트롤러/서비스 레이어에서 정보 마스킹 합니당
284289
*/
285290
@Override
286291
public Page<Room> findAllRooms(Pageable pageable) {
287292
List<Room> rooms = queryFactory
288293
.selectFrom(room)
289294
.leftJoin(room.createdBy, user).fetchJoin()
295+
.where(
296+
room.status.ne(RoomStatus.TERMINATED) // TERMINATED 제외
297+
)
290298
.orderBy(
291-
// 열린 방 우선 (0), 닫힌 방 뒤로 (1)
299+
// 열린 방 우선 (0), 일시정지 방 뒤로 (1)
292300
room.status.when(RoomStatus.WAITING).then(0)
293301
.when(RoomStatus.ACTIVE).then(0)
294302
.otherwise(1).asc(),
@@ -302,23 +310,27 @@ public Page<Room> findAllRooms(Pageable pageable) {
302310
Long totalCount = queryFactory
303311
.select(room.count())
304312
.from(room)
313+
.where(
314+
room.status.ne(RoomStatus.TERMINATED) // TERMINATED 제외
315+
)
305316
.fetchOne();
306317

307318
return new PageImpl<>(rooms, pageable, totalCount != null ? totalCount : 0);
308319
}
309320

310321
/**
311-
* 공개 방 전체 조회
322+
* 공개 방 전체 조회 (TERMINATED 제외)
312323
* 조회 조건:
313324
* - isPrivate = false
314325
* - includeInactive에 따라 닫힌 방 포함 여부 결정
315326
* 정렬: 열린 방 우선 → 최신순
316327
*/
317328
@Override
318329
public Page<Room> findPublicRoomsWithStatus(boolean includeInactive, Pageable pageable) {
319-
BooleanExpression whereClause = room.isPrivate.eq(false);
330+
BooleanExpression whereClause = room.isPrivate.eq(false)
331+
.and(room.status.ne(RoomStatus.TERMINATED)); // TERMINATED 제외
320332

321-
// 닫힌 방 제외 옵션
333+
// 일시정지 방 제외 옵션
322334
if (!includeInactive) {
323335
whereClause = whereClause.and(
324336
room.status.in(RoomStatus.WAITING, RoomStatus.ACTIVE)
@@ -349,7 +361,7 @@ public Page<Room> findPublicRoomsWithStatus(boolean includeInactive, Pageable pa
349361
}
350362

351363
/**
352-
* 내가 멤버인 비공개 방 조회
364+
* 내가 멤버인 비공개 방 조회 (TERMINATED 제외)
353365
* 조회 조건:
354366
* - isPrivate = true
355367
* - 내가 멤버로 등록된 방
@@ -359,9 +371,10 @@ public Page<Room> findPublicRoomsWithStatus(boolean includeInactive, Pageable pa
359371
@Override
360372
public Page<Room> findMyPrivateRooms(Long userId, boolean includeInactive, Pageable pageable) {
361373
BooleanExpression whereClause = room.isPrivate.eq(true)
362-
.and(roomMember.user.id.eq(userId));
374+
.and(roomMember.user.id.eq(userId))
375+
.and(room.status.ne(RoomStatus.TERMINATED)); // TERMINATED 제외
363376

364-
// 닫힌 방 제외 옵션
377+
// 일시정지 방 제외 옵션
365378
if (!includeInactive) {
366379
whereClause = whereClause.and(
367380
room.status.in(RoomStatus.WAITING, RoomStatus.ACTIVE)
@@ -394,7 +407,7 @@ public Page<Room> findMyPrivateRooms(Long userId, boolean includeInactive, Pagea
394407
}
395408

396409
/**
397-
* 내가 호스트(방장)인 방 조회
410+
* 내가 호스트(방장)인 방 조회 (TERMINATED 제외)
398411
* 조회 조건:
399412
* - room.createdBy.id = userId
400413
* 정렬: 열린 방 우선 → 최신순
@@ -404,7 +417,10 @@ public Page<Room> findRoomsByHostId(Long userId, Pageable pageable) {
404417
List<Room> rooms = queryFactory
405418
.selectFrom(room)
406419
.leftJoin(room.createdBy, user).fetchJoin()
407-
.where(room.createdBy.id.eq(userId))
420+
.where(
421+
room.createdBy.id.eq(userId),
422+
room.status.ne(RoomStatus.TERMINATED) // TERMINATED 제외
423+
)
408424
.orderBy(
409425
room.status.when(RoomStatus.WAITING).then(0)
410426
.when(RoomStatus.ACTIVE).then(0)
@@ -418,7 +434,10 @@ public Page<Room> findRoomsByHostId(Long userId, Pageable pageable) {
418434
Long totalCount = queryFactory
419435
.select(room.count())
420436
.from(room)
421-
.where(room.createdBy.id.eq(userId))
437+
.where(
438+
room.createdBy.id.eq(userId),
439+
room.status.ne(RoomStatus.TERMINATED) // TERMINATED 제외
440+
)
422441
.fetchOne();
423442

424443
return new PageImpl<>(rooms, pageable, totalCount != null ? totalCount : 0);

0 commit comments

Comments
 (0)