Skip to content

Commit

Permalink
Merge pull request #274 from team9502/dev
Browse files Browse the repository at this point in the history
๋ฐฐํฌ
  • Loading branch information
daeundada authored Jul 1, 2024
2 parents 2802ad1 + 0f9ee64 commit 12cd590
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ public interface ChatRoomRepository extends JpaRepository<ChatRoom, Long> {
List<ChatRoom> findByUser_UserId(Long userId);

List<ChatRoom> findByCompanyUser_CpUserId(Long cpUserId);

boolean existsByUser_UserIdAndCompanyUser_CpUserId(Long userId, Long cpUserId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -63,7 +67,7 @@ public List<ChatRoomResponseDTO> 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());
}
Expand Down Expand Up @@ -96,7 +100,7 @@ public List<ChatMessageResponseDTO> getChatMessages(Long chatRoomId, UserDetails
chatRoom.setUserRead(false);
}
break;
case "COMPANY_USER":
case "COMPANY":
if (userDetails.getCpUserId() != null) {
chatRoom.setCompanyUserRead(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."),
Expand Down

0 comments on commit 12cd590

Please sign in to comment.