Skip to content

Commit

Permalink
feat: 채팅방 이름 변경 로직 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
hyunn522 committed Aug 12, 2024
1 parent 8f54e7f commit 870dc3c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,16 @@ public BaseResponse<ChatSuccessResponse> joinChatRoom(
@RequestBody JoinChatRoomRequest joinChatRoomRequest) {
return new BaseResponse<>(chatRoomService.joinChatRoom(userId, chatRoomId, joinChatRoomRequest));
}

/**
* 특정 채팅방의 이름 수정
*/
@PostMapping("/{chatRoomId}/setting")
public BaseResponse<ChatSuccessResponse> modifyChatRoomName(
@JwtLoginAuth Long userId,
@PathVariable Long spaceId,
@PathVariable Long chatRoomId,
@RequestParam String name) {
return new BaseResponse<>(chatRoomService.modifyChatRoomName(userId, chatRoomId, name));
}
}
4 changes: 4 additions & 0 deletions src/main/java/space/space_spring/entity/ChatRoom.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<UserChatRoom> userChatRooms;
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/space/space_spring/service/ChatRoomService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<ChatRoom> chatRoomByChatRoomId = chatRoomDao.findById(chatRoomId);

chatRoomByChatRoomId.ifPresent(chatRoom -> {
// TODO 2: 채팅방 이름 변경
chatRoom.updateName(name);
chatRoomDao.save(chatRoom);
});

return ChatSuccessResponse.of(true);
}
}

0 comments on commit 870dc3c

Please sign in to comment.