Skip to content

Refactor/chat entity - #4

Open
sejung2 wants to merge 21 commits into
developfrom
refactor/chatEntity
Open

Refactor/chat entity#4
sejung2 wants to merge 21 commits into
developfrom
refactor/chatEntity

Conversation

@sejung2

@sejung2 sejung2 commented Jun 21, 2026

Copy link
Copy Markdown
Owner

PR 요약 — Chat 도메인 리팩토링

구조 정리

  • DAO 5개 삭제, Repository 직접 주입으로 전환
  • ChatUserEntity 삭제 → UserEntity 재사용 (USERS 테이블 중복 매핑 제거)
  • Entity 연관관계 매핑 (@ManyToOne LAZY), Date → LocalDateTime 전환
  • toEntity()/toDto() 제거 → Service에서 Builder 직접 생성

예외 처리

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 제거)
친구 삭제 파라미터: friendshipIdfriendId

@sejung2
sejung2 requested a review from Copilot June 21, 2026 11:15
@sejung2 sejung2 self-assigned this Jun 21, 2026
@sejung2
sejung2 marked this pull request as ready for review June 21, 2026 11:15

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 to UserEntity + repository injection and @ManyToOne(fetch = LAZY) relationships.
  • Migrated Date/Timestamp usages to LocalDateTime across 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants