Skip to content

Commit a110f3a

Browse files
authored
Merge pull request #130 from Dugout-Developers/feat/#129
[FEAT] 채팅방 단일 정보 조회 기능 구현
2 parents dcaccd4 + 8ebf7ce commit a110f3a

File tree

5 files changed

+31
-4
lines changed

5 files changed

+31
-4
lines changed

src/main/java/com/back/catchmate/domain/chat/controller/ChatRoomController.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ public ChatResponse.PagedChatRoomInfo getChatRoomList(@JwtValidation Long userId
4040
return chatRoomService.getChatRoomList(userId, pageable);
4141
}
4242

43+
@GetMapping("/{chatRoomId}}")
44+
@Operation(summary = "채팅방 정보 조회 API", description = "체팅방 정보를 조회하는 API 입니다.")
45+
public ChatResponse.ChatRoomInfo getChatRoom(@JwtValidation Long userId,
46+
@PathVariable Long chatRoomId) {
47+
return chatRoomService.getChatRoom(userId, chatRoomId);
48+
}
49+
4350
@DeleteMapping("/{chatRoomId}")
4451
@Operation(summary = "내가 속한 채팅방 나가기 API", description = "내가 속해있는 채팅방을 나가는 API 입니다.")
4552
public StateResponse leaveChatRoom(@JwtValidation Long userId,

src/main/java/com/back/catchmate/domain/chat/repository/ChatRoomRepository.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
import java.util.Optional;
77

88
public interface ChatRoomRepository extends JpaRepository<ChatRoom, Long> {
9-
Optional<ChatRoom> findByBoardId(Long boardId);
9+
Optional<ChatRoom> findByIdAndDeletedAtIsNull(Long chatRoomId);
10+
11+
Optional<ChatRoom> findByBoardIdAndDeletedAtIsNull(Long boardId);
1012

1113
boolean existsByBoardId(Long boardId);
1214
}

src/main/java/com/back/catchmate/domain/chat/service/ChatRoomService.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.back.catchmate.domain.chat.service;
22

3+
import com.back.catchmate.domain.chat.dto.ChatResponse.ChatRoomInfo;
34
import com.back.catchmate.domain.chat.dto.ChatResponse.PagedChatRoomInfo;
45
import com.back.catchmate.global.dto.StateResponse;
56
import org.springframework.data.domain.Pageable;
@@ -12,6 +13,8 @@ public interface ChatRoomService {
1213

1314
PagedChatRoomInfo getChatRoomList(Long userId, Pageable pageable);
1415

16+
ChatRoomInfo getChatRoom(Long userId, Long chatRoomId);
17+
1518
StateResponse updateChatRoomImage(Long userId, Long chatRoomId, MultipartFile image) throws IOException;
1619

1720
StateResponse kickUserFromChatRoom(Long adminId, Long chatRoomId, Long userId);

src/main/java/com/back/catchmate/domain/chat/service/ChatRoomServiceImpl.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import com.back.catchmate.domain.chat.converter.ChatRoomConverter;
44
import com.back.catchmate.domain.chat.dto.ChatResponse;
5+
import com.back.catchmate.domain.chat.dto.ChatResponse.ChatRoomInfo;
6+
import com.back.catchmate.domain.chat.dto.ChatResponse.PagedChatRoomInfo;
57
import com.back.catchmate.domain.chat.entity.ChatRoom;
68
import com.back.catchmate.domain.chat.entity.UserChatRoom;
79
import com.back.catchmate.domain.chat.repository.ChatRoomRepository;
@@ -35,19 +37,32 @@ public class ChatRoomServiceImpl implements ChatRoomService {
3537

3638
@Override
3739
@Transactional(readOnly = true)
38-
public ChatResponse.PagedChatRoomInfo getChatRoomList(Long userId, Pageable pageable) {
40+
public PagedChatRoomInfo getChatRoomList(Long userId, Pageable pageable) {
3941
Page<UserChatRoom> userChatRoomList = userChatRoomRepository.findAllByUserId(userId, pageable);
4042
return chatRoomConverter.toPagedChatRoomInfo(userChatRoomList);
4143
}
4244

45+
@Override
46+
@Transactional(readOnly = true)
47+
public ChatRoomInfo getChatRoom(Long userId, Long chatRoomId) {
48+
ChatRoom chatRoom = chatRoomRepository.findByIdAndDeletedAtIsNull(chatRoomId)
49+
.orElseThrow(() -> new BaseException(ErrorCode.CHATROOM_NOT_FOUND));
50+
51+
if (!userChatRoomRepository.existsByUserIdAndChatRoomIdAndDeletedAtIsNull(userId, chatRoomId)) {
52+
throw new BaseException(ErrorCode.USER_CHATROOM_NOT_FOUND);
53+
}
54+
55+
return chatRoomConverter.toChatRoomInfo(chatRoom, chatRoom.getBoard());
56+
}
57+
4358
@Override
4459
@Transactional
4560
public StateResponse leaveChatRoom(Long userId, Long chatRoomId) {
4661
// 채팅방과 사용자 정보 조회
4762
User user = userRepository.findById(userId)
4863
.orElseThrow(() -> new BaseException(ErrorCode.USER_NOT_FOUND));
4964

50-
ChatRoom chatRoom = chatRoomRepository.findById(chatRoomId)
65+
ChatRoom chatRoom = chatRoomRepository.findByIdAndDeletedAtIsNull(chatRoomId)
5166
.orElseThrow(() -> new BaseException(ErrorCode.CHATROOM_NOT_FOUND));
5267

5368
// UserChatRoom 엔티티를 찾아서 나가기

src/main/java/com/back/catchmate/domain/enroll/service/EnrollServiceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ public UpdateEnrollInfo acceptEnroll(Long enrollId, Long userId) throws IOExcept
195195
}
196196

197197
private void enterChatRoom(User user, Board board) {
198-
ChatRoom chatRoom = chatRoomRepository.findByBoardId(board.getId())
198+
ChatRoom chatRoom = chatRoomRepository.findByBoardIdAndDeletedAtIsNull(board.getId())
199199
.orElseThrow(() -> new BaseException(ErrorCode.CHATROOM_NOT_FOUND));
200200

201201
chatRoom.incrementParticipantCount();

0 commit comments

Comments
 (0)