From 870dc3c612448a1cdaa8cce3750638b77d7cccf3 Mon Sep 17 00:00:00 2001 From: hyunn522 Date: Mon, 12 Aug 2024 14:54:25 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=B1=84=ED=8C=85=EB=B0=A9=20=EC=9D=B4?= =?UTF-8?q?=EB=A6=84=20=EB=B3=80=EA=B2=BD=20=EB=A1=9C=EC=A7=81=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../space_spring/controller/ChatRoomController.java | 12 ++++++++++++ .../java/space/space_spring/entity/ChatRoom.java | 4 ++++ .../space/space_spring/service/ChatRoomService.java | 13 +++++++++++++ 3 files changed, 29 insertions(+) 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); + } }