diff --git a/src/main/java/space/space_spring/controller/ChatRoomController.java b/src/main/java/space/space_spring/controller/ChatRoomController.java index 5bec4e26..6e188068 100644 --- a/src/main/java/space/space_spring/controller/ChatRoomController.java +++ b/src/main/java/space/space_spring/controller/ChatRoomController.java @@ -82,4 +82,16 @@ public BaseResponse joinChatRoom( @RequestBody JoinChatRoomRequest joinChatRoomRequest) { return new BaseResponse<>(chatRoomService.joinChatRoom(userId, chatRoomId, joinChatRoomRequest)); } + + /** + * 특정 채팅방의 이름 수정 + */ + @PostMapping("/{chatRoomId}/setting") + public BaseResponse modifyChatRoomName( + @JwtLoginAuth Long userId, + @PathVariable Long spaceId, + @PathVariable Long chatRoomId, + @RequestParam String name) { + return new BaseResponse<>(chatRoomService.modifyChatRoomName(userId, chatRoomId, name)); + } } diff --git a/src/main/java/space/space_spring/entity/ChatRoom.java b/src/main/java/space/space_spring/entity/ChatRoom.java index f19a7b40..0f3104da 100644 --- a/src/main/java/space/space_spring/entity/ChatRoom.java +++ b/src/main/java/space/space_spring/entity/ChatRoom.java @@ -48,6 +48,10 @@ public static ChatRoom of(Space space, CreateChatRoomRequest createChatRoomReque .build(); } + public void updateName(String name) { + this.name = name; + } + // // 양방향 매핑 // @OneToMany(mappedBy = "chatRoom", cascade = CascadeType.ALL) // private List userChatRooms; diff --git a/src/main/java/space/space_spring/service/ChatRoomService.java b/src/main/java/space/space_spring/service/ChatRoomService.java index 93178a82..3d908ee3 100644 --- a/src/main/java/space/space_spring/service/ChatRoomService.java +++ b/src/main/java/space/space_spring/service/ChatRoomService.java @@ -142,4 +142,17 @@ public ChatSuccessResponse joinChatRoom(Long userId, Long chatRoomId, JoinChatRo }); return ChatSuccessResponse.of(true); } + + public ChatSuccessResponse modifyChatRoomName(Long userId, Long chatRoomId, String name) { + // TODO 1: 해당 채팅방 find + Optional chatRoomByChatRoomId = chatRoomDao.findById(chatRoomId); + + chatRoomByChatRoomId.ifPresent(chatRoom -> { + // TODO 2: 채팅방 이름 변경 + chatRoom.updateName(name); + chatRoomDao.save(chatRoom); + }); + + return ChatSuccessResponse.of(true); + } }