-
Notifications
You must be signed in to change notification settings - Fork 1
refactor: 어드민 채팅 API 삭제 & 통합 #205
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
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.
Pull request overview
기존에 분리되어 있던 어드민 채팅 API(admin/chat)를 제거하고, 관련 기능을 일반 채팅 API(domain/chat)로 통합하는 리팩터링입니다. 통합 과정에서 채팅방 조회/메시지 조회 로직이 확장되고, 일부 응답 스펙이 변경됩니다.
Changes:
- 어드민 채팅 전용 Controller/Service/DTO 제거 및 일반 채팅 서비스로 기능 이관
- 존재하지 않는 채팅방 접근/메시지 전송 시 사용할 에러 코드(
NOT_FOUND_CHAT_ROOM) 추가 및 Repository 조회 방식(Optional)로 변경 - 채팅방 목록/메시지 응답 스펙 확장(채팅방 타입, 메시지 senderId 처리) 및 유저 조회 응답에
role포함
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/main/java/gg/agit/konect/global/code/ApiResponseCode.java | 채팅 관련 응답 코드 추가 |
| src/main/java/gg/agit/konect/domain/user/dto/UserInfoResponse.java | 유저 정보 응답에 role 필드 추가 |
| src/main/java/gg/agit/konect/domain/chat/service/ChatService.java | 어드민/일반 채팅 통합 로직 반영(목록/메시지/미읽음 처리) |
| src/main/java/gg/agit/konect/domain/chat/repository/ChatRoomRepository.java | 채팅방 조회 API를 Optional 기반으로 변경 |
| src/main/java/gg/agit/konect/domain/chat/enums/ChatRoomType.java | 채팅방 타입(NORMAL/ADMIN) enum 신설 |
| src/main/java/gg/agit/konect/domain/chat/dto/ChatRoomsResponse.java | 채팅방 타입 필드 추가 및 응답 생성 방식 변경 |
| src/main/java/gg/agit/konect/domain/chat/dto/ChatRoomCreateRequest.java | 채팅방 생성 요청 스펙 변경(clubId → userId) |
| src/main/java/gg/agit/konect/domain/chat/dto/ChatMessagesResponse.java | 메시지 응답 생성 시 senderId 처리 로직 확장 |
| src/main/java/gg/agit/konect/domain/chat/controller/ChatApi.java | 채팅방 생성 API 설명/스펙 변경 반영 |
| src/main/java/gg/agit/konect/admin/chat/service/AdminChatService.java | (삭제) 어드민 채팅 서비스 제거 |
| src/main/java/gg/agit/konect/admin/chat/dto/AdminChatRoomsResponse.java | (삭제) 어드민 채팅방 목록 DTO 제거 |
| src/main/java/gg/agit/konect/admin/chat/dto/AdminChatMessagesResponse.java | (삭제) 어드민 메시지 목록 DTO 제거 |
| src/main/java/gg/agit/konect/admin/chat/controller/AdminChatController.java | (삭제) 어드민 채팅 컨트롤러 제거 |
| src/main/java/gg/agit/konect/admin/chat/controller/AdminChatApi.java | (삭제) 어드민 채팅 API 인터페이스 제거 |
| public ChatRoomsResponse getChatRooms(Integer userId) { | ||
| User user = userRepository.getById(userId); | ||
| List<InnerChatRoomResponse> chatRoomResponses = new ArrayList<>(); | ||
|
|
||
| List<ChatRoom> personalChatRooms = chatRoomRepository.findByUserId(userId); | ||
| Map<Integer, Integer> personalUnreadCountMap = getUnreadCountMap( | ||
| extractChatRoomIds(personalChatRooms), userId | ||
| ); | ||
|
|
Copilot
AI
Feb 12, 2026
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.
현재 로직에서는 ADMIN 사용자인 경우에도 personalChatRooms 조회 + personalUnreadCountMap 계산을 먼저 수행하지만, ADMIN 사용자가 참여한 모든 채팅방은 findAllAdminChatRooms(UserRole.ADMIN) 결과에 포함되므로(해당 사용자의 role이 ADMIN) 아래 루프에서 전부 중복으로 스킵되어 사실상 불필요한 DB 조회/카운트 쿼리가 됩니다. ADMIN일 때는 개인 목록/미읽음 카운트를 생략하거나, 한 번의 조회 결과를 재사용하도록 분기하는 편이 성능상 안전합니다.
| User user = userRepository.getById(userId); | ||
| if (user.getRole() == UserRole.ADMIN || !isAdminChatRoom(chatRoom)) { | ||
| return null; | ||
| } | ||
| return getAdminFromChatRoom(chatRoom).getId(); |
Copilot
AI
Feb 12, 2026
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.
getChatRoomMessages() 경로에서 userRepository.getById(userId)를 markUnreadMessagesAsRead(), getMaskedAdminId() 내부에서 각각 다시 조회하고 있어 동일 요청에서 User를 2회 조회하게 됩니다. 상단에서 User를 한 번만 로드한 뒤 role 판단/마스킹/읽음처리에 재사용하도록 파라미터를 정리하면 불필요한 쿼리를 줄일 수 있습니다.
| User user = userRepository.getById(userId); | |
| if (user.getRole() == UserRole.ADMIN || !isAdminChatRoom(chatRoom)) { | |
| return null; | |
| } | |
| return getAdminFromChatRoom(chatRoom).getId(); | |
| // Admin이 참여한 방이 아니면 마스킹할 Admin이 없으므로 null 반환 | |
| if (!isAdminChatRoom(chatRoom)) { | |
| return null; | |
| } | |
| // 채팅방 참여자 중 Admin 유저를 찾는다. | |
| User admin = getAdminFromChatRoom(chatRoom); | |
| // 현재 사용자가 Admin이라면 마스킹이 필요 없으므로 null 반환 | |
| if (admin.getId().equals(userId)) { | |
| return null; | |
| } | |
| // 일반 유저가 Admin 채팅방을 볼 때는 Admin의 id를 반환하여 마스킹에 사용 | |
| return admin.getId(); |
| public record ChatRoomCreateRequest( | ||
| @NotNull(message = "동아리 ID는 필수입니다.") | ||
| @Schema(description = "동아리 ID", example = "1", requiredMode = REQUIRED) | ||
| Integer clubId | ||
| @NotNull(message = "유저 ID는 필수입니다.") | ||
| @Schema(description = "채팅 대상 유저 ID", example = "10", requiredMode = REQUIRED) | ||
| Integer userId |
Copilot
AI
Feb 12, 2026
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.
ChatRoomCreateRequest가 clubId에서 userId로 변경되면서 기존 클라이언트/문서 기준 요청 바디와 호환되지 않는(브레이킹) API 변경이 발생합니다. PR 설명에는 어드민 채팅 API 통합이 मुख्य인데, 일반 채팅방 생성이 "임의 유저 지정"으로 바뀌는 범위 확장이 포함되어 있으므로(권한/대상 제한 포함) 의도된 변경인지 명확히 하고, 필요하면 별도 엔드포인트/버저닝 또는 하위 호환 DTO(예: clubId 지원 유지)를 고려하는 게 좋습니다.
| FAILED_EXTRACT_EMAIL(HttpStatus.BAD_REQUEST, "OAuth 로그인 과정에서 이메일 정보를 가져올 수 없습니다."), | ||
| FAILED_EXTRACT_PROVIDER_ID(HttpStatus.BAD_REQUEST, "OAuth 로그인 과정에서 제공자 식별자를 가져올 수 없습니다."), | ||
| CANNOT_CREATE_CHAT_ROOM_WITH_SELF(HttpStatus.BAD_REQUEST, "자기 자신과는 채팅방을 만들 수 없습니다."), | ||
| INVALID_CHAT_ROOM_CREATE_REQUEST(HttpStatus.BAD_REQUEST, "clubId 또는 targetUserId 중 하나만 전달해야 합니다."), |
Copilot
AI
Feb 12, 2026
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.
새로 추가된 INVALID_CHAT_ROOM_CREATE_REQUEST의 메시지가 아직 "clubId 또는 targetUserId"를 전제로 하고 있는데, 이번 PR에서는 ChatRoomCreateRequest가 userId만 받도록 변경되었습니다. 실제 사용처도 검색상 보이지 않으니(미사용) 메시지를 현재 요청 스펙에 맞게 수정하거나, 더 이상 필요 없으면 코드 자체를 제거하는 편이 혼동을 줄입니다.
| INVALID_CHAT_ROOM_CREATE_REQUEST(HttpStatus.BAD_REQUEST, "clubId 또는 targetUserId 중 하나만 전달해야 합니다."), | |
| INVALID_CHAT_ROOM_CREATE_REQUEST(HttpStatus.BAD_REQUEST, "잘못된 채팅방 생성 요청입니다."), |
| for (ChatRoom chatRoom : personalChatRooms) { | ||
| if (!addedChatRoomIds.contains(chatRoom.getId())) { | ||
| chatRoomResponses.add(InnerChatRoomResponse.from( | ||
| chatRoom, user, personalUnreadCountMap, ChatRoomType.NORMAL | ||
| )); | ||
| } |
Copilot
AI
Feb 12, 2026
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.
getChatRooms()에서 개인 채팅방을 추가할 때 chatRoomType을 항상 NORMAL로 고정하고 있어, 일반 유저가 어드민과의 채팅방을 조회하더라도 ADMIN 타입을 받을 수 없습니다. chatRoom이 어드민 참여 채팅방인지(role 기반) 판별해서 ChatRoomType을 ADMIN/NORMAL로 설정하도록 수정하는 게 필요합니다.
ac82088 to
906adb5
Compare
🔍 개요
🚀 주요 변경 내용
domain/chat)에 통합했습니다.GET /users/id를 통해 회원 조회할 시Role도 반환하도록 했습니다.💬 참고 사항
✅ Checklist (완료 조건)