Skip to content

Commit 5c77469

Browse files
committed
Feat: 사용자가 참여한 방 조회
1 parent e7620a3 commit 5c77469

File tree

4 files changed

+70
-17
lines changed

4 files changed

+70
-17
lines changed

src/main/java/cmf/commitField/domain/chat/chatRoom/controller/ChatRoomController.java

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,54 @@ public ResponseEntity<Object> getByUserRoomList(Pageable pageable) {
7979
}
8080
}
8181

82+
// 사용자(자신)가 들어가 있는 방 리스트 조회
83+
@GetMapping("/room/part")
84+
@LoginCheck
85+
public ResponseEntity<Object> getByUserRoomPartList(Pageable pageable) {
86+
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
87+
88+
if (authentication instanceof OAuth2AuthenticationToken) {
89+
CustomOAuth2User principal = (CustomOAuth2User) authentication.getPrincipal();
90+
Long userId = principal.getId(); // getId()를 통해 userId를 추출
91+
List<ChatRoomDto> userByRoomPartList = chatRoomService.getUserByRoomPartList(userId, pageable);
92+
return ResponseEntity.ok().body(userByRoomPartList);
93+
} else {
94+
throw new IllegalArgumentException("User not logged in.");
95+
}
96+
}
97+
98+
// // 채팅방 나가기
99+
// @DeleteMapping("/room/out/{roomId}")
100+
// @LoginCheck
101+
// public ResponseEntity<Object> outRoom(
102+
// @PathVariable Long roomId) {
103+
// Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
104+
//
105+
// if (authentication instanceof OAuth2AuthenticationToken) {
106+
// CustomOAuth2User principal = (CustomOAuth2User) authentication.getPrincipal();
107+
// Long userId = principal.getId(); // getId()를 통해 userId를 추출
108+
// chatRoomService.outRoom(userId, roomId);
109+
// return ResponseEntity.ok().body("success");
110+
// } else {
111+
// throw new IllegalArgumentException("User not logged in.");
112+
// }
113+
// }
114+
//
115+
// // 채팅방 삭제
116+
// @DeleteMapping("/room/delete/{roomId}")
117+
// @LoginCheck
118+
// public ResponseEntity<Object> deleteRoom(
119+
// @PathVariable Long roomId) {
120+
// Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
121+
//
122+
// if (authentication instanceof OAuth2AuthenticationToken) {
123+
// CustomOAuth2User principal = (CustomOAuth2User) authentication.getPrincipal();
124+
// Long userId = principal.getId(); // getId()를 통해 userId를 추출
125+
// chatRoomService.deleteRoom(userId, roomId);
126+
// return ResponseEntity.ok().body("success");
127+
// } else {
128+
// throw new IllegalArgumentException("User not logged in.");
129+
// }
130+
// }
131+
82132
}

src/main/java/cmf/commitField/domain/chat/chatRoom/repository/ChatRoomRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public interface ChatRoomRepository extends JpaRepository<ChatRoom, Long> {
2424
@Query("select c from ChatRoom c where c.roomCreator=:userId")
2525
Page<ChatRoom> findAllByUserId(@Param("userId")Long userId,Pageable pageable);
2626

27-
// Page<ChatRoom> findAllByUserChatRoomsUserId(Long userId,Pageable pageable);
27+
Page<ChatRoom> findAllByUserChatRoomsUserId(Long userId,Pageable pageable);
2828

2929
// @Query(value = "SELECT ROOM_CREATOR FROM chat_room WHERE CHAT_ROOM_ID = ?", nativeQuery = true)
3030
// Long findChatRoomByRoomCreator(Long roomId);

src/main/java/cmf/commitField/domain/chat/chatRoom/service/ChatRoomService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public interface ChatRoomService {
1818
// 자신이 생성한 방 리스트 조회
1919
List<ChatRoomDto> getUserByRoomList(Long userId, org.springframework.data.domain.Pageable pageable);
2020

21-
// List<ChatRoomDto> getUserByRoomPartList(Long userId, Pageable pageable);
21+
List<ChatRoomDto> getUserByRoomPartList(Long userId, Pageable pageable);
2222
//
2323
// void outRoom(Long userId, Long roomId);
2424
//

src/main/java/cmf/commitField/domain/chat/chatRoom/service/ChatRoomServiceImpl.java

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,22 @@ public List<ChatRoomDto> getRoomList(Pageable pageable) {
110110
return getChatRoomDtos(all);
111111
}
112112

113-
// // 자신이 참여한 방 리스트 조회
114-
// @Override
115-
// public List<ChatRoomDto> getUserByRoomPartList(Long userId, Pageable pageable) {
116-
// Page<ChatRoom> allByUserIdAndUserChatRooms = chatRoomRepository
117-
// .findAllByUserChatRoomsUserId(userId, pageable);
118-
// return getChatRoomDtos(allByUserIdAndUserChatRooms);
119-
// }
113+
// 자신이 생성한 방 리스트 조회
114+
@Override
115+
@Transactional(readOnly = true)
116+
public List<ChatRoomDto> getUserByRoomList(Long userId, Pageable pageable) {
117+
Page<ChatRoom> all = chatRoomRepository.findAllByUserId(userId, pageable);
118+
return getChatRoomDtos(all);
119+
}
120+
121+
// 자신이 참여한 방 리스트 조회
122+
@Override
123+
@Transactional(readOnly = true)
124+
public List<ChatRoomDto> getUserByRoomPartList(Long userId, Pageable pageable) {
125+
Page<ChatRoom> allByUserIdAndUserChatRooms = chatRoomRepository
126+
.findAllByUserChatRoomsUserId(userId, pageable);
127+
return getChatRoomDtos(allByUserIdAndUserChatRooms);
128+
}
120129

121130
// @Override
122131
// @Transactional
@@ -143,15 +152,9 @@ public List<ChatRoomDto> getRoomList(Pageable pageable) {
143152
// }
144153
// userChatRoomRepository.deleteUserChatRoomByChatRoom_Id(roomId);
145154
// chatRoomRepository.deleteById(roomId);
146-
// // todo : 채팅 메시지 구현 시, 방 삭제할 때 메시지도 같이 삭제되는 메서드 구현
155+
// 채팅 메시지 구현 시, 방 삭제할 때 메시지도 같이 삭제되는 메서드 구현
156+
147157

148-
// 자신이 생성한 방 리스트 조회
149-
@Override
150-
@Transactional(readOnly = true)
151-
public List<ChatRoomDto> getUserByRoomList(Long userId, Pageable pageable) {
152-
Page<ChatRoom> all = chatRoomRepository.findAllByUserId(userId, pageable);
153-
return getChatRoomDtos(all);
154-
}
155158

156159

157160
}

0 commit comments

Comments
 (0)