Refactor/chat entity - #4
Open
sejung2 wants to merge 21 commits into
Open
Conversation
- unreadCount 서브쿼리로 통합
There was a problem hiding this comment.
Pull request overview
This PR refactors the Chat domain to rely on Spring Data JPA repositories directly (removing DAO + duplicated chat-specific entities), modernizes time handling to LocalDateTime, and reorganizes DTOs into clearer request/response/projection packages while simplifying controller exception flow toward global handling.
Changes:
- Removed Chat DAOs and chat-specific
ChatUserEntity, switching toUserEntity+ repository injection and@ManyToOne(fetch = LAZY)relationships. - Migrated
Date/Timestampusages toLocalDateTimeacross chat entities/services/repositories and updated query/projection contracts accordingly. - Reworked friend/chatroom/message APIs + DTO naming/packaging, and introduced a lazy-loading regression test.
Reviewed changes
Copilot reviewed 55 out of 55 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| Shift/src/test/resources/application.properties | Adds test Spring Boot configuration (DB/JPA/JWT/S3 placeholders). |
| Shift/src/test/java/com/project/shift/chat/ChatroomUserLazyLoadingTest.java | New integration-style test to verify lazy loading behavior and SQL counts. |
| Shift/src/main/resources/application.properties | Adjusts JPA ddl-auto behavior. |
| Shift/src/main/java/com/project/shift/user/service/UserService.java | Swaps Chat DAOs for repositories in withdrawal cleanup. |
| Shift/src/main/java/com/project/shift/user/entity/UserEntity.java | Adds updatePoints() domain method. |
| Shift/src/main/java/com/project/shift/shop/service/OrderService.java | Uses LocalDateTime and updated ChatroomUserService API; uses updatePoints(). |
| Shift/src/main/java/com/project/shift/chat/service/MessageService.java | Refactors message persistence/broadcast logic to repositories + LocalDateTime. |
| Shift/src/main/java/com/project/shift/chat/service/FriendService.java | Refactors friendship operations to repositories + request/response DTOs. |
| Shift/src/main/java/com/project/shift/chat/service/ChatUserService.java | Refactors chat user lookup/mypage + S3 upload validation/exception types. |
| Shift/src/main/java/com/project/shift/chat/service/ChatroomUserService.java | Refactors chatroom-user lifecycle to repositories and new DTO mappings. |
| Shift/src/main/java/com/project/shift/chat/service/ChatroomService.java | Refactors chatroom CRUD/search/list to repositories + new response DTOs. |
| Shift/src/main/java/com/project/shift/chat/repository/MessageRepository.java | Updates message queries for entity relationships + LocalDateTime. |
| Shift/src/main/java/com/project/shift/chat/repository/FriendRepository.java | Updates friend queries to new response DTO and entity relationships. |
| Shift/src/main/java/com/project/shift/chat/repository/ChatUserRepository.java | Rebinds chat-user repository to UserEntity and adds phone lookup. |
| Shift/src/main/java/com/project/shift/chat/repository/ChatroomUserRepository.java | Updates chatroom-user queries for relationships + unreadCount subquery + withdrawal updates. |
| Shift/src/main/java/com/project/shift/chat/repository/ChatroomRepository.java | Updates chatroom native queries + unreadCount subquery; updates last message timestamp type. |
| Shift/src/main/java/com/project/shift/chat/exception/UserNotFoundException.java | Removes chat-specific exception in favor of global NotFoundException. |
| Shift/src/main/java/com/project/shift/chat/entity/ReplyEmoticonEntity.java | Removes unused/legacy reply emoticon entity. |
| Shift/src/main/java/com/project/shift/chat/entity/MessageEntity.java | Converts to relationship-based mapping (chatroom, user) + LocalDateTime. |
| Shift/src/main/java/com/project/shift/chat/entity/FriendEntity.java | Converts to relationship-based mapping (user, friend). |
| Shift/src/main/java/com/project/shift/chat/entity/ChatUserEntity.java | Removes duplicate USERS mapping in favor of UserEntity. |
| Shift/src/main/java/com/project/shift/chat/entity/ChatroomUserEntity.java | Converts to relationship-based mapping (chatroom, user) + LocalDateTime. |
| Shift/src/main/java/com/project/shift/chat/entity/ChatroomEntity.java | Converts last message timestamp to LocalDateTime and removes DTO converter. |
| Shift/src/main/java/com/project/shift/chat/dto/response/MessageSearchResultResponse.java | Adds response DTO for message-search results. |
| Shift/src/main/java/com/project/shift/chat/dto/response/FriendInfoResponse.java | Renames/moves friend info DTO into response package. |
| Shift/src/main/java/com/project/shift/chat/dto/response/ChatUserSearchResponse.java | Adds record response for chat user search. |
| Shift/src/main/java/com/project/shift/chat/dto/response/ChatUserMyPageInfoResponse.java | Adds record response for chat user mypage info. |
| Shift/src/main/java/com/project/shift/chat/dto/response/ChatroomResponse.java | Adds response DTO for chatroom info. |
| Shift/src/main/java/com/project/shift/chat/dto/response/ChatroomListResponse.java | Adds response DTO for chatroom list items (incl. unreadCount). |
| Shift/src/main/java/com/project/shift/chat/dto/request/FriendRequest.java | Adds request DTO for creating friendship. |
| Shift/src/main/java/com/project/shift/chat/dto/request/DeletedChatroomUserInfoRequest.java | Adds request DTO for restoring deleted chatroom relationships. |
| Shift/src/main/java/com/project/shift/chat/dto/ReplyEmoticonDTO.java | Removes legacy reply emoticon DTO. |
| Shift/src/main/java/com/project/shift/chat/dto/projection/MessageSearchResultProjection.java | Adds projection interface using LocalDateTime. |
| Shift/src/main/java/com/project/shift/chat/dto/projection/ChatroomListProjection.java | Moves/updates chatroom list projection and adds unreadCount field. |
| Shift/src/main/java/com/project/shift/chat/dto/MessageSearchResultProjection.java | Removes legacy projection interface. |
| Shift/src/main/java/com/project/shift/chat/dto/MessageSearchResultDTO.java | Removes legacy DTO. |
| Shift/src/main/java/com/project/shift/chat/dto/MessageDTO.java | Converts sendDate to LocalDateTime and removes entity converter. |
| Shift/src/main/java/com/project/shift/chat/dto/FriendDTO.java | Removes legacy DTO. |
| Shift/src/main/java/com/project/shift/chat/dto/DeletedChatroomUserInfoDTO.java | Removes legacy DTO. |
| Shift/src/main/java/com/project/shift/chat/dto/ChatUserSearchResultDTO.java | Removes legacy DTO. |
| Shift/src/main/java/com/project/shift/chat/dto/ChatUserMyPageInfoDTO.java | Removes legacy DTO. |
| Shift/src/main/java/com/project/shift/chat/dto/ChatUserDTO.java | Removes legacy DTO. |
| Shift/src/main/java/com/project/shift/chat/dto/ChatroomUserDTO.java | Converts timestamps to LocalDateTime and removes entity converter. |
| Shift/src/main/java/com/project/shift/chat/dto/ChatroomListDTO.java | Removes legacy DTO. |
| Shift/src/main/java/com/project/shift/chat/dto/ChatroomDTO.java | Removes legacy DTO. |
| Shift/src/main/java/com/project/shift/chat/dao/MessageDAO.java | Removes DAO layer. |
| Shift/src/main/java/com/project/shift/chat/dao/FriendDAO.java | Removes DAO layer. |
| Shift/src/main/java/com/project/shift/chat/dao/ChatUserDAO.java | Removes DAO layer. |
| Shift/src/main/java/com/project/shift/chat/dao/ChatroomUserDAO.java | Removes DAO layer. |
| Shift/src/main/java/com/project/shift/chat/dao/ChatroomDAO.java | Removes DAO layer. |
| Shift/src/main/java/com/project/shift/chat/controller/MessageController.java | Updates WebSocket + history API to new DTOs and LocalDateTime. |
| Shift/src/main/java/com/project/shift/chat/controller/FriendController.java | Changes friend API route and adds validation/current-user usage. |
| Shift/src/main/java/com/project/shift/chat/controller/ChatUserController.java | Removes try/catch and migrates auth to CurrentUser; updates response DTOs. |
| Shift/src/main/java/com/project/shift/chat/controller/ChatroomUserController.java | Removes try/catch and migrates auth to CurrentUser; updates DTOs. |
| Shift/src/main/java/com/project/shift/chat/controller/ChatroomController.java | Removes try/catch and migrates auth to CurrentUser; updates response DTOs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| WHERE u.userId IN :userIds | ||
| ORDER BY u.name ASC | ||
| """) | ||
| List<UserEntity> findUserInfoByIds(@Param("friendIds") List<Long> userIds); |
| from messages m | ||
| where m.chatroom_id = cu.chatroom_id | ||
| and m.send_date >= greatest(cu.last_connection_time, cu.created_time) | ||
| and m.user_id <> cu2.user_id |
Comment on lines
+29
to
+31
| LocalDateTime now = dto.getMessageDTO().getSendDate(); | ||
| messageService.checkAndUpdateReceiverConnectionStatus(dto, now); | ||
| messageService.sendAndSaveMessage(dto.getMessageDTO(), dto.getChatroomUserDTO()); |
Comment on lines
+29
to
+33
| @PostMapping | ||
| public ResponseEntity<Void> addFriendship(@RequestBody @Valid FriendRequest friendInfo) { | ||
| friendService.addFriendship(friendInfo); | ||
| return ResponseEntity.ok().build(); | ||
| } |
Comment on lines
+4
to
+7
| spring.datasource.driver-class-name=oracle.jdbc.OracleDriver | ||
| spring.datasource.url=jdbc:oracle:thin:@localhost:1521:XE | ||
| spring.datasource.username=test | ||
| spring.datasource.password=test |
Comment on lines
+11
to
+14
| spring.jpa.database-platform=org.hibernate.dialect.OracleDialect | ||
| spring.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl | ||
| spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl | ||
| spring.jpa.hibernate.ddl-auto=none |
| spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl | ||
|
|
||
| spring.jpa.hibernate.ddl-auto=validate | ||
| spring.jpa.hibernate.ddl-auto=none |
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
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.
PR 요약 — Chat 도메인 리팩토링
구조 정리
@ManyToOne LAZY), Date → LocalDateTime 전환예외 처리
chat 전용 예외 삭제,
NotFoundException으로 통일Controller try-catch 전부 제거 →
GlobalExceptionHandler위임WebSocket은 전역 처리 불가 확인 → try-catch 유지
DTO
request/response/projection패키지 분리, 네이밍 통일(~Request/~Response)request DTO record +
@Valid적용버그 수정 & 성능
SQL 콤마 누락,
@Transactional누락 2건 수정채팅방 unreadCount N+1 → 서브쿼리 통합으로 SQL 1회 해결
API 변경 (확인 필요)
/friends/users/{userId}→/users/friends(보안 이슈로PathVariable제거)친구 삭제 파라미터:
friendshipId→friendId