-
Notifications
You must be signed in to change notification settings - Fork 0
[BE] feat: Quick Room 생성 로직 및 API 구현 (#67) #74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- 기존 로직 삭제 - 생성자에 redis 주입 삭제 - DB 조회 로직 구현 전까지 true 반환하도록 수정
- RoomService에 대한 기본 테스트 구조 추가 - Repository 모킹 설정 및 기본 정의 테스트 작성
- Quick Room 생성 시 기본 정책 설정 검증 테스트 추가 - Repository mock 메서드 확장 (create, save) - Room entity의 HostTransferPolicy, DefaultRolePolicy import 추가⚠️ Code Red: RoomService에 createQuickRoom 메서드 미구현
- createQuickRoom 메서드 구현으로 테스트 통과 (green) - 기본 정책 설정: AUTO_TRANSFER, VIEWER 권한 - 24시간 만료 시간 자동 설정 - Logger 추가로 방 생성 로그 기록 - Room entity의 정책 enum import 추가
- 룸 코드 중복 시 재시도 로직 검증 테스트 추가 - generateRoomCode private 메서드 spy 처리 - findOne mock 동작 시나리오별 설정
- nanoid, uuid ESM 모듈의 Jest 변환을 위한 transformIgnorePatterns 설정 - pnpm 환경에서 ESM 패키지 테스트 실행 오류 해결
- nanoid를 활용한 랜덤 룸 코드 생성 (6자리, 대소문자+숫자) - 중복 검사 및 최대 3번 재시도 로직 구현 - 생성 실패 시 InternalServerErrorException 예외 처리 - roomCode 길이 검증 추가 (6자리 보장) - expiresAt Date 타입 변환 수정
- 3번 재시도 모두 실패 시 InternalServerErrorException 발생 검증 - InternalServerErrorException import 추가 - 중복 발생 시나리오 엣지 케이스 테스트 커버리지 확대
- generateUniqueRoomCode 메서드로 중복 검사 로직 분리 - createQuickRoom의 단일 책임 원칙 준수 (생성만 담당) - generateRoomCode에 roomCodeLength 파라미터 추가로 유연성 향상 - 코드 가독성 및 유지보수성 개선
- DataSource와 QueryRunner mock 추가 - 트랜잭션 시작/커밋/롤백 동작 검증 - 저장 실패 시 롤백 및 리소스 해제 테스트 추가 - Repository 직접 사용에서 QueryRunner.manager 사용으로 변경 - afterEach에서 mock 초기화 추가
- Repository.save에서 QueryRunner를 활용한 트랜잭션 방식으로 변경 - DataSource 의존성 주입 추가 - try-catch-finally로 트랜잭션 롤백 및 리소스 해제 보장 - 추후 추가될 복합 작업을 위한 트랜잭션 인프라 구축 - 에러 발생 시 로그 기록 추가
- PtRole import 추가 - Room과 Pt가 트랜잭션 내에서 함께 저장되는지 검증 - 반환값(roomCode, myPtId) 검증 추가 - Pt 생성 시 HOST 역할, code '0000', nickname, color 설정 검증 - save 호출 순서 검증 (1번: Room, 2번: Pt)
- Room 생성 후 방장 Pt를 트랜잭션 내에서 함께 생성 - Pt entity import 및 HOST 역할로 생성 (code: '0000') - 기본 nickname 'Host', color '#E0E0E0' 설정 - roomCode와 myPtId를 반환하여 클라이언트가 즉시 사용 가능 - 로그 메시지에 Host Pt ID 정보 추가
- Arrange-Act-Assert 패턴 적용으로 테스트 구조 명확화 - 테스트 상수(MOCK_ROOM_CODE, MOCK_ROOM_ID, MOCK_PT_ID) 최상단 선언 - createMockQueryRunner 팩토리 함수로 각 테스트마다 독립적인 mock 생성 - useFactory에서 useValue로 변경하여 mock 관리 단순화 - afterEach 제거 및 beforeEach에서 mockClear로 초기화 방식 개선 - 주석 추가로 검증 의도 명확화 (흐름/데이터/반환값 검증 구분) - 불필요한 검증 제거 (nickname, color 등은 구현 세부사항)
- QuickRoomResponseDto 클래스 생성 (roomCode, myPtId) - createQuickRoom 메서드 반환 타입을 명시적으로 지정 - 타입 안정성 향상 및 API 응답 구조 명확화
- 범용적인 방 생성 응답 DTO로 이름 변경 - Quick Room뿐만 아니라 다른 방 생성 방식에서도 재사용 가능
- 방 생성 옵션을 정의하는 RoomCreationOptions 인터페이스 생성 - hostTransferPolicy, defaultRolePolicy 필수 속성 - roomPassword, hostPassword 선택적 속성 - 추후 다양한 방 생성 방식 확장을 위한 기반 마련
- createQuickRoom이 createRoom을 호출하는 구조로 변경
- RoomCreationOptions를 통한 옵션 전달 방식 도입
- 하드코딩된 정책값을 options 객체로 대체
- roomPassword, hostPassword 옵션 지원 추가
- findOne 쿼리 최적화: select로 roomId만 조회
- 에러 로그 메시지 일반화 ("quick room" → "room")
- POST /api/room/quick 엔드포인트 구현 - RoomService.createQuickRoom 호출 및 결과 반환 - CreateRoomResponseDto 타입 명시 - Post decorator import 추가
- RoomController 테스트 파일 생성 - createQuickRoom 엔드포인트 테스트 구현 - RoomService mock 설정 및 호출 검증 - 반환값(roomCode, myPtId) 검증
Happysttim
approved these changes
Jan 8, 2026
inaemin
approved these changes
Jan 8, 2026
kindsmell
approved these changes
Jan 8, 2026
lnxhigh
approved these changes
Jan 8, 2026
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Note
스케줄러 미구현:
이슈 명세에 있던 '만료된 방 삭제 스케줄러(Cron)' 기능은 기술 검토(NestJS Cron vs pg_cron) 후 구현하기 위해 이번 PR에서는 제외되었습니다. 추후 별도 PR로 진행할 예정입니다.
Warning
현재는 base가 feat/#65 입니다
#71 pr이 머지된 후에, base dev로 변경 후 merge 해야 합니다
📋 작업 범위 (Scope)
🔗 관련 이슈 (Related Issue)
🛠️ 작업 내용 (Description)
1. Quick Room 생성 API 구현 (POST /api/room/quick)
2. Room Code 생성 및 중복 처리 로직
3. 트랜잭션 및 기본 정책 적용
4. 테스트 코드 작성
📦 패키지 변경 사항 (Dependencies)
📸 스크린샷 (Screenshots - Frontend Only)
✅ 체크리스트 (Self Checklist)
💬 추가 논의사항 (Optional)
방장 Pt 자동 생성: Quick Room 생성 시, 요청한 사용자를 해당 방의 Host로 즉시 등록하기 위해 Pt 테이블에 데이터를 함께 Insert 하도록 구현했습니다.