diff --git a/backend/chatroom-service/src/main/java/com/tadak/chatroomservice/domain/chatmember/service/ChatMemberService.java b/backend/chatroom-service/src/main/java/com/tadak/chatroomservice/domain/chatmember/service/ChatMemberService.java index ae5f30c..17b8a2b 100644 --- a/backend/chatroom-service/src/main/java/com/tadak/chatroomservice/domain/chatmember/service/ChatMemberService.java +++ b/backend/chatroom-service/src/main/java/com/tadak/chatroomservice/domain/chatmember/service/ChatMemberService.java @@ -81,4 +81,8 @@ public ChatMember getChatMemberByChatRoomAndUsername(ChatRoom chatRoom, String u return chatMember; } + public ChatMember findByChatRoomAndChatUsername(ChatRoom chatRoom, String kickedUsername) { + return chatMemberRepository.findByChatRoomAndUsername(chatRoom, kickedUsername) + .orElseThrow(() -> new NotFoundChatMemberException(ErrorCode.NOT_FOUND_CHAT_MEMBER_ERROR)); + } } diff --git a/backend/chatroom-service/src/main/java/com/tadak/chatroomservice/domain/chatroom/controller/ChatRoomController.java b/backend/chatroom-service/src/main/java/com/tadak/chatroomservice/domain/chatroom/controller/ChatRoomController.java index 4686038..af1e708 100644 --- a/backend/chatroom-service/src/main/java/com/tadak/chatroomservice/domain/chatroom/controller/ChatRoomController.java +++ b/backend/chatroom-service/src/main/java/com/tadak/chatroomservice/domain/chatroom/controller/ChatRoomController.java @@ -61,10 +61,10 @@ public ResponseEntity> getAllChatRoom() { /** * 강퇴 */ - @PostMapping("/rooms/{roomId}/kicked/{chatMemberId}") - public ResponseEntity kickedMember(@PathVariable Long roomId, @PathVariable Long chatMemberId, + @PostMapping("/rooms/{roomId}/kicked/{username}") + public ResponseEntity kickedMember(@PathVariable Long roomId, @PathVariable String username, @RequestBody ChatRoomRequest chatRoomRequest){ - KickMemberResponse kickMemberResponse = chatRoomService.kickMember(roomId, chatMemberId, chatRoomRequest.getUsername()); + KickMemberResponse kickMemberResponse = chatRoomService.kickMember(roomId, username, chatRoomRequest.getUsername()); return ResponseEntity.status(HttpStatus.OK).body(kickMemberResponse); } @@ -79,11 +79,20 @@ public ResponseEntity changeOwner(@PathVariable Long roomId } /** - * 개별 방 조회 + * 개별 방 조회 (채팅방 제목) */ - @GetMapping("/rooms/{roomId}") - public ResponseEntity getChatRoom(@PathVariable Long roomId){ - OneChatRoomResponse getChatRoom = chatRoomService.findChatRoom(roomId); + @GetMapping("/rooms/{roomId}/roomName") + public ResponseEntity getChatRoomName(@PathVariable Long roomId){ + ChatRoomNameResponse getChatRoom = chatRoomService.findChatRoom(roomId); return ResponseEntity.status(HttpStatus.OK).body(getChatRoom); } + + /** + * 개별 방 조회 (참여자 수, 방장, 참여 멤버) + */ + @GetMapping("/rooms/{roomId}/roomInformation") + public ResponseEntity getChatRoomInfo(@PathVariable Long roomId){ + ChatRoomInfoResponse getChatRoomInfo = chatRoomService.findChatRoomInfo(roomId); + return ResponseEntity.status(HttpStatus.OK).body(getChatRoomInfo); + } } diff --git a/backend/chatroom-service/src/main/java/com/tadak/chatroomservice/domain/chatroom/dto/response/OneChatRoomResponse.java b/backend/chatroom-service/src/main/java/com/tadak/chatroomservice/domain/chatroom/dto/response/ChatRoomInfoResponse.java similarity index 73% rename from backend/chatroom-service/src/main/java/com/tadak/chatroomservice/domain/chatroom/dto/response/OneChatRoomResponse.java rename to backend/chatroom-service/src/main/java/com/tadak/chatroomservice/domain/chatroom/dto/response/ChatRoomInfoResponse.java index 2d85a52..1249ef7 100644 --- a/backend/chatroom-service/src/main/java/com/tadak/chatroomservice/domain/chatroom/dto/response/OneChatRoomResponse.java +++ b/backend/chatroom-service/src/main/java/com/tadak/chatroomservice/domain/chatroom/dto/response/ChatRoomInfoResponse.java @@ -13,16 +13,14 @@ @Builder @AllArgsConstructor @NoArgsConstructor -public class OneChatRoomResponse { +public class ChatRoomInfoResponse { - private String roomName; private Integer participation; private String owner; private List chatMemberResponses; - public static OneChatRoomResponse of(ChatRoom chatRoom, List chatMemberResponses){ - return OneChatRoomResponse.builder() - .roomName(chatRoom.getRoomName()) + public static ChatRoomInfoResponse of(ChatRoom chatRoom, List chatMemberResponses){ + return ChatRoomInfoResponse.builder() .participation(chatRoom.getParticipation()) .owner(chatRoom.getOwner()) .chatMemberResponses(chatMemberResponses) diff --git a/backend/chatroom-service/src/main/java/com/tadak/chatroomservice/domain/chatroom/dto/response/ChatRoomNameResponse.java b/backend/chatroom-service/src/main/java/com/tadak/chatroomservice/domain/chatroom/dto/response/ChatRoomNameResponse.java new file mode 100644 index 0000000..d6e9951 --- /dev/null +++ b/backend/chatroom-service/src/main/java/com/tadak/chatroomservice/domain/chatroom/dto/response/ChatRoomNameResponse.java @@ -0,0 +1,25 @@ +package com.tadak.chatroomservice.domain.chatroom.dto.response; + +import com.tadak.chatroomservice.domain.chatmember.dto.response.ChatMemberResponse; +import com.tadak.chatroomservice.domain.chatroom.entity.ChatRoom; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.util.List; + +@Getter +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class ChatRoomNameResponse { + + private String roomName; + + public static ChatRoomNameResponse from(ChatRoom chatRoom){ + return ChatRoomNameResponse.builder() + .roomName(chatRoom.getRoomName()) + .build(); + } +} diff --git a/backend/chatroom-service/src/main/java/com/tadak/chatroomservice/domain/chatroom/service/ChatRoomService.java b/backend/chatroom-service/src/main/java/com/tadak/chatroomservice/domain/chatroom/service/ChatRoomService.java index 072fd98..1943a36 100644 --- a/backend/chatroom-service/src/main/java/com/tadak/chatroomservice/domain/chatroom/service/ChatRoomService.java +++ b/backend/chatroom-service/src/main/java/com/tadak/chatroomservice/domain/chatroom/service/ChatRoomService.java @@ -78,11 +78,11 @@ public void deleteChatRoom(Long roomId, String username) { } @Transactional - public KickMemberResponse kickMember(Long roomId, Long chatMemberId, String username) { + public KickMemberResponse kickMember(Long roomId, String kickedUsername, String owner) { ChatRoom chatRoom = findByChatRoom(roomId); - ChatMember chatMember = chatMemberService.findByChatMember(chatMemberId); + ChatMember chatMember = chatMemberService.findByChatRoomAndChatUsername(chatRoom, kickedUsername); // 방장 검증 - validOwner(username, chatRoom.getOwner()); + validOwner(owner, chatRoom.getOwner()); // 상태를 KICKED로 변경 chatMember.updateState(); @@ -126,12 +126,20 @@ public ChangeOwnerResponse changeOwner(Long roomId, String username, String owne return ChangeOwnerResponse.from(chatRoom); } - public OneChatRoomResponse findChatRoom(Long roomId) { + // 방 제목 엔드포인트 + public ChatRoomNameResponse findChatRoom(Long roomId) { + ChatRoom chatRoom = findByChatRoom(roomId); + + return ChatRoomNameResponse.from(chatRoom); + } + + // 방장, 참여자 수, 참여 멤버 엔드포인트 + public ChatRoomInfoResponse findChatRoomInfo(Long roomId) { ChatRoom chatRoom = findByChatRoom(roomId); List chatMemberResponses = chatRoom.getChatMembers().stream() .map(ChatMemberResponse::from).toList(); - return OneChatRoomResponse.of(chatRoom, chatMemberResponses); + return ChatRoomInfoResponse.of(chatRoom, chatMemberResponses); } }