diff --git a/src/main/java/team9502/sinchulgwinong/domain/chat/repository/ChatRoomRepository.java b/src/main/java/team9502/sinchulgwinong/domain/chat/repository/ChatRoomRepository.java index 9e0dc8e..dd1b87a 100644 --- a/src/main/java/team9502/sinchulgwinong/domain/chat/repository/ChatRoomRepository.java +++ b/src/main/java/team9502/sinchulgwinong/domain/chat/repository/ChatRoomRepository.java @@ -10,4 +10,6 @@ public interface ChatRoomRepository extends JpaRepository { List findByUser_UserId(Long userId); List findByCompanyUser_CpUserId(Long cpUserId); + + boolean existsByUser_UserIdAndCompanyUser_CpUserId(Long userId, Long cpUserId); } diff --git a/src/main/java/team9502/sinchulgwinong/domain/chat/service/ChatService.java b/src/main/java/team9502/sinchulgwinong/domain/chat/service/ChatService.java index 7152576..c85d3cd 100644 --- a/src/main/java/team9502/sinchulgwinong/domain/chat/service/ChatService.java +++ b/src/main/java/team9502/sinchulgwinong/domain/chat/service/ChatService.java @@ -39,6 +39,10 @@ public ChatRoomResponseDTO createChatRoom(User user, Long cpUserId) { CompanyUser companyUser = companyUserRepository.findById(cpUserId) .orElseThrow(() -> new ApiException(ErrorCode.COMPANY_USER_NOT_FOUND)); + if(chatRoomRepository.existsByUser_UserIdAndCompanyUser_CpUserId(user.getUserId(),cpUserId)){ + throw new ApiException(ErrorCode.ALREADY_CREATE_CHAT); + } + ChatRoom chatRoom = new ChatRoom(); chatRoom.setChatName(companyUser.getCpName()); chatRoom.setUser(user); @@ -63,7 +67,7 @@ public List getChatRooms(UserDetailsImpl userDetails) { chatRooms = chatRoomRepository.findByUser_UserId(userDetails.getUserId()); } break; - case "COMPANY_USER": + case "COMPANY": if (userDetails.getCpUserId() != null) { chatRooms = chatRoomRepository.findByCompanyUser_CpUserId(userDetails.getCpUserId()); } @@ -96,7 +100,7 @@ public List getChatMessages(Long chatRoomId, UserDetails chatRoom.setUserRead(false); } break; - case "COMPANY_USER": + case "COMPANY": if (userDetails.getCpUserId() != null) { chatRoom.setCompanyUserRead(false); } diff --git a/src/main/java/team9502/sinchulgwinong/global/exception/ErrorCode.java b/src/main/java/team9502/sinchulgwinong/global/exception/ErrorCode.java index 393c752..60e082c 100644 --- a/src/main/java/team9502/sinchulgwinong/global/exception/ErrorCode.java +++ b/src/main/java/team9502/sinchulgwinong/global/exception/ErrorCode.java @@ -35,6 +35,7 @@ public enum ErrorCode { //chat CHAT_NOT_FOUND(HttpStatus.NOT_FOUND, "채팅을 찾을 수 없습니다."), + ALREADY_CREATE_CHAT(HttpStatus.NOT_FOUND, "이미 생성된 채팅방 입니다."), // Faq FAQ_NOT_FOUND(HttpStatus.NOT_FOUND, "FAQ를 찾을 수 없습니다."),