-
Notifications
You must be signed in to change notification settings - Fork 2
feat(be): Add ChatRoom REST API #88
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
Conversation
beekeeper24
commented
Oct 2, 2025
- Added the listRooms GET endpoint so authenticated users can page through their chat rooms, handling limit and cursor parameters safely.
- Implemented cursor-based pagination in the service layer, parsing the incoming cursor, querying the page, and constructing the next-cursor token for the response.
- Extended the repository with a JPQL query that orders by updatedAt and id, applying cursor bounds to fetch a member’s chat rooms page by page.
- Introduced the ChatRoomListResponse DTO to return the paged room data along with the next cursor value.
- Expanded the controller integration test to seed multiple rooms and assert that sequential requests honor the cursor-driven pagination flow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤖 AI 리뷰 - src/main/kotlin/com/back/koreaTravelGuide/domain/userChat/chatroom/controller/ChatRoomController.kt
🟢 좋은점:
- ApiResponse 사용: listRooms 메서드에서 ApiResponse로 응답을 감싸서 반환하고 있으며, msg와 data 필드를 적절히 사용. 이는 모든 API 응답 규칙을 준수함.
- Kotlin 최적화: null safety를 잘 활용 (requesterId ?: throw ...). coerceIn(1, 100)을 사용해 limit 값을 안전하게 제한하는 Kotlin idiomatic 코드. DTO (ChatRoomListResponse) import와 사용도 적절.
- ktlint 규칙: 네이밍 컨벤션 (e.g., listRooms, safeLimit, authenticatedId)이 camelCase로 일관되며, import 순서와 들여쓰기가 표준적. 포맷팅 문제 없음.
🟡 개선사항:
- Kotlin 최적화: cursor 파라미터가 String?으로 null safety를 사용하지만, 서비스 레이어에서 cursor 파싱/유효성 검증 로직이 명확히 보이지 않음. 필요 시 when 표현식으로 cursor 유효성 (e.g., null/빈 문자열 처리)을 추가하면 더 안전할 수 있음.
- 글로벌 익셉션 처리: AccessDeniedException을 직접 throw하는 것은 괜찮지만, @ControllerAdvice에서 표준 에러 응답 (e.g., 401 Unauthorized with ApiResponse)으로 매핑되는지 확인 필요. 만약 startChat 메서드도 비슷한 예외를 던진다면 일관성 있게 처리.
- ktlint 규칙: 메서드 본문이 간결하지만, limit과 cursor 파라미터의 기본값/옵션성을 Javadoc이나 KDoc으로 문서화하면 가독성 향상 (ktlint는 강제하지 않으나 베스트 프랙티스).
🔴 문제점:
- 없음. 변경된 코드가 필수 검토 항목을 모두 만족하며, 기존 startChat 메서드 부분도 ApiResponse를 import하고 있으므로 일관성 있음. 다만 전체 컨트롤러에서 @validated나 @RequestParam 유효성 검증 어노테이션을 추가로 고려 (e.g., @min(1) @max(100) on limit).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤖 AI 리뷰 - src/main/kotlin/com/back/koreaTravelGuide/domain/userChat/chatroom/dto/ChatRoomListResponse.kt
🟢 좋은점:
- Kotlin 최적화 측면에서 data class를 적절히 사용하며, equals(), hashCode(), toString() 등의 자동 생성을 통해 DTO로서 효율적임. null safety도 잘 적용되어 nextCursor를 String?으로 선언하여 옵셔널한 커서 기반 페이징을 지원함.
- ktlint 규칙 준수: 패키지 선언, 클래스명(명확하고 PascalCase), 프로퍼티명(camelCase), 들여쓰기와 포맷팅이 표준적임. 간결하고 읽기 쉬운 구조.
🟡 개선사항:
- ApiResponse 사용 규칙을 고려할 때, 이 DTO가 API 응답의 최상위 래퍼가 아닌 내부 응답 객체로 보이므로, 실제 컨트롤러에서 ApiResponse로 감싸서 반환하는지 확인 필요. 만약 이 DTO가 직접 API 응답으로 사용된다면, ApiResponse로 확장하는 것을 고려 (예: data class를 상속하거나 래핑).
- Kotlin 최적화 추가: rooms 리스트가 비어 있을 때의 기본 동작(예: emptyList() 초기화)을 고려하거나, 확장 함수로 커서 처리 로직을 별도 정의하면 더 유연할 수 있음. 하지만 현재 구조상 큰 문제는 아님.
🔴 문제점:
- 없음. 글로벌 익셉션 처리(@ControllerAdvice)는 이 DTO 파일과 직접 관련 없으나, 사용 시 표준 에러 응답과 일관되게 적용될 것으로 보임. 전체적으로 규칙 위반 없음.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤖 AI 리뷰 - src/main/kotlin/com/back/koreaTravelGuide/domain/userChat/chatroom/repository/ChatRoomRepository.kt
🟢 좋은점:
- Kotlin의 null safety를 잘 활용:
cursorUpdatedAt: java.time.ZonedDateTime?와cursorRoomId: Long?로 nullable 파라미터를 명확히 처리하며, 쿼리 조건에서is null체크를 통해 안전하게 동작. - @query 어노테이션으로 복잡한 커서 기반 페이징 쿼리를 JPA 네이티브하게 정의하여, Kotlin의 간결함을 유지하면서도 성능 최적화(예: updatedAt와 id 복합 정렬).
- ktlint 규칙 준수: 쿼리 문자열이 멀티라인으로 잘 포맷팅되어 있으며, 네이밍 컨벤션(예: findPagedByMember, 파라미터명 memberId 등)이 일관적이고 읽기 쉽다. import 문도 필요한 것만 추가되어 깔끔함.
🟡 개선사항:
- 반환 타입을
List<ChatRoom>대신Page<ChatRoom>또는Slice<ChatRoom>으로 변경 고려: Pageable을 받지만 List를 반환하면 페이징 메타데이터(총 개수, 다음 페이지 여부 등)가 손실되어 서비스 레이어에서 추가 처리가 필요할 수 있음. cursor 기반 페이징이라 List로 충분하다면 문서화(예: KDoc)로 의도를 명확히 하거나, 메서드명에 'Cursor' 키워드 추가(예: findCursorPagedByMember)로 의도를 더 드러낼 수 있음. - 쿼리 조건에서 null 처리 로직을 더 명확히:
:cursorUpdatedAt is null or ...는 JPA에서 잘 동작하지만, cursorRoomId의 null 케이스(예: 첫 페이지 호출 시)를 테스트 케이스나 주석으로 보강하면 유지보수성 향상. 또한, ZonedDateTime import가 변경사항에 명시되지 않았으나 기존 파일에 없으면 추가 필요(ktlint에서 import 순서 준수). - 네이밍 최적화: 'findPagedByMember'는 적절하지만, 'member'가 guideId/userId 중 하나를 의미하므로 KDoc으로 "memberId가 guideId 또는 userId와 매칭되는 채팅룸을 커서 페이징으로 조회"처럼
YangHJ2415
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
확인했습니다.