From ac03361d8e35595e6acae757da8e7a2723d2eb2b Mon Sep 17 00:00:00 2001 From: de123456sdf Date: Tue, 2 Jul 2024 01:51:56 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EC=B1=84=ED=8C=85=EB=B0=A9=20=EC=98=88?= =?UTF-8?q?=EC=99=B8=20=EC=B2=98=EB=A6=AC=20=EC=B6=94=EA=B0=80,=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9=EC=9E=90=20=ED=83=80=EC=9E=85=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/chat/repository/ChatRoomRepository.java | 2 ++ .../sinchulgwinong/domain/chat/service/ChatService.java | 8 ++++++-- .../sinchulgwinong/global/exception/ErrorCode.java | 1 + 3 files changed, 9 insertions(+), 2 deletions(-) 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를 찾을 수 없습니다."),