Skip to content

Commit

Permalink
HOTFIX: 컨트롤러 인자 모두 customId로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
koreaioi committed Nov 13, 2024
1 parent 8066e38 commit efe10f3
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ public ResponseDto<ChattingDto> findChatting(@PathVariable Long roomId, @PathVar
}


@GetMapping("/chattingList/{userId}")
@GetMapping("/chattingList/{customId}")
@Operation(summary = "유저가 속한 모든 채팅방 조회")
public ResponseDto<List<ChattingListResponseDto>> findChattingList(@PathVariable Long userId, @AuthenticationPrincipal String email){
List<ChattingListResponseDto> response = chattingService.getChattingList(userId, email);
public ResponseDto<List<ChattingListResponseDto>> findChattingList(@PathVariable String customId, @AuthenticationPrincipal String email){
List<ChattingListResponseDto> response = chattingService.getChattingList(customId, email);
return ResponseDto.response(CHATTINGLIST_GET.getCode(), CHATTINGLIST_GET.getMessage(), response);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ public interface ChatRoomRepository extends JpaRepository<ChatRoom, Long> {
*/

@Query("SELECT c.id FROM ChatRoom c WHERE " +
"(c.user1.customId = :custom1Id AND c.user2.customId = :custom2Id) OR " +
"(c.user1.customId = :custom2Id AND c.user2.customId = :custom1Id)")
Optional<Long> findRoomIdByUserIds(@Param("custom1Id") String custom1Id, @Param("custom2Id") String custom2Id);
"(c.user1.id = :user1Id AND c.user2.id = :user2Id) OR " +
"(c.user1.id = :user2Id AND c.user2.id = :user1Id)")
Optional<Long> findRoomIdByUserIds(@Param("user1Id") Long user1Id, @Param("user2Id") Long user2Id);

/*
* SELECT room_id FROM chat_room WHERE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,17 @@ public ChatRoomResponseDto saveChatRoom(FindChatRoomRequestDto findChatRoomReque
User user1 = userService.findByCustomId(findChatRoomRequestDto.custom1Id());
User user2 = userService.findByCustomId(findChatRoomRequestDto.custom2Id());

checkChatRoom(user1.getCustomId(), user2.getCustomId());
checkChatRoom(user1.getId(), user2.getId());
ChatRoom savedRoom = chatRoomRepository.save(ChatRoom.of(user1, user2)); // 채팅방 RDB에 저장

redisMessageListener.adaptMessageListener(savedRoom.getId()); // 리스너 등록
return new ChatRoomResponseDto(savedRoom.getId());
}

public ChatRoomResponseDto findUser1User2ChatRoom(String custom1Id,String custom2Id) {
return new ChatRoomResponseDto(findUsersChatRoom(custom1Id, custom2Id));
User user1 = userService.findByCustomId(custom1Id);
User user2 = userService.findByCustomId(custom2Id);
return new ChatRoomResponseDto(findUsersChatRoom(user1.getId(),user2.getId()));
}

// 테스트를 위해서 만들어둠. 추후 삭제
Expand All @@ -48,14 +50,14 @@ public void addListener(Long roomId) {



private void checkChatRoom(String custom1Id,String custom2Id) {
chatRoomRepository.findRoomIdByUserIds(custom1Id, custom2Id).ifPresent(c->{
private void checkChatRoom(Long user1Id, Long user2Id) {
chatRoomRepository.findRoomIdByUserIds(user1Id, user2Id).ifPresent(c->{
throw new ChatRoomExistException();
});
}

private Long findUsersChatRoom(String custom1Id,String custom2Id) {
return chatRoomRepository.findRoomIdByUserIds(custom1Id, custom2Id)
private Long findUsersChatRoom(Long user1Id, Long user2Id) {
return chatRoomRepository.findRoomIdByUserIds(user1Id, user2Id)
.orElseThrow(NotFoundChatRoomException::new);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ public ChattingDto getChatRoom(Long roomId, Integer page, Integer size, String e
return findOpponent(sender, findRoom.getUser1(), findRoom.getUser2(), chatMessageList);
}

public List<ChattingListResponseDto> getChattingList(Long userId, String email) { // 추후 JWT 파싱으로 받아내기.
List<ChatRoom> chatRooms = validateChatRommList(userId);
public List<ChattingListResponseDto> getChattingList(String customId, String email) { // 추후 JWT 파싱으로 받아내기.
User findUser = userService.findByCustomId(customId);
List<ChatRoom> chatRooms = validateChatRommList(findUser.getId());

return chatRooms.stream()
.map(chatRoom -> {
Expand Down

0 comments on commit efe10f3

Please sign in to comment.