diff --git a/src/main/java/com/dku/council/domain/chat/controller/ChatRoomController.java b/src/main/java/com/dku/council/domain/chat/controller/ChatRoomController.java index 12a1837b..c0b4d905 100644 --- a/src/main/java/com/dku/council/domain/chat/controller/ChatRoomController.java +++ b/src/main/java/com/dku/council/domain/chat/controller/ChatRoomController.java @@ -48,22 +48,16 @@ public String goChatRoom(Model model, AppAuthentication auth) { * 채팅방 생성 * * @param name 채팅방 이름 - * @param roomPwd 채팅방 비밀번호 - * @param secretCheck 채팅방 잠금 설정 여부 * @param maxUserCount 채팅방 최대 인원 수 설정 (default = 10) */ @PostMapping("/create") @UserAuth public String createRoom(@RequestParam("roomName") String name, - @RequestParam("roomPwd") String roomPwd, - @RequestParam("secretChk") String secretCheck, @RequestParam(value = "maxUserCount", defaultValue = "10") String maxUserCount, AppAuthentication auth, RedirectAttributes rttr) { ResponseChatRoomDto room = chatService.createChatRoom(name, - roomPwd, - Boolean.parseBoolean(secretCheck), Integer.parseInt(maxUserCount), auth.getUserId()); @@ -90,19 +84,18 @@ public String roomDetail(Model model, String roomId, AppAuthentication auth){ } /** - * 채팅방 비밀번호 확인 + * 채팅방 방장 확인 * * @param roomId 채팅방 id - * @param roomPwd 사용자가 입력한 비밀번호 - * @return 사용자가 입력한 비밀번호가 일치하면 true, 아니면 false + * @return 현재 사용자가 해당 채팅방의 방장이라면 true, 아니면 false */ - @PostMapping("/confirmPwd/{roomId}") + @GetMapping("/confirm/manager/{roomId}") @UserAuth @ResponseBody - public boolean confirmPwd(@PathVariable String roomId, - @RequestParam String roomPwd){ + public boolean confirmPwd(AppAuthentication auth, + @PathVariable String roomId){ - return chatService.confirmPwd(roomId, roomPwd); + return chatService.confirmRoomManager(roomId, auth.getUserId()); } /** diff --git a/src/main/java/com/dku/council/domain/chat/model/dto/response/ResponseChatRoomDto.java b/src/main/java/com/dku/council/domain/chat/model/dto/response/ResponseChatRoomDto.java index ed432357..21a8c6d8 100644 --- a/src/main/java/com/dku/council/domain/chat/model/dto/response/ResponseChatRoomDto.java +++ b/src/main/java/com/dku/council/domain/chat/model/dto/response/ResponseChatRoomDto.java @@ -10,6 +10,4 @@ public class ResponseChatRoomDto { private final String roomName; private final int userCount; private final int maxUserCount; - private final String roomPwd; // 채팅방 삭제시 필요한 pwd - private final boolean secretCheck; // 채팅방 잠금 여부 } diff --git a/src/main/java/com/dku/council/domain/chat/model/entity/ChatRoom.java b/src/main/java/com/dku/council/domain/chat/model/entity/ChatRoom.java index cf1469eb..95abe87d 100644 --- a/src/main/java/com/dku/council/domain/chat/model/entity/ChatRoom.java +++ b/src/main/java/com/dku/council/domain/chat/model/entity/ChatRoom.java @@ -42,11 +42,6 @@ public class ChatRoom extends BaseEntity { @NotNull private int maxUserCount; - @NotNull - private String roomPwd; - - private boolean secretCheck; - @OneToMany(mappedBy = "chatRoom", cascade = CascadeType.ALL, orphanRemoval = true) private List users = new ArrayList<>(); @@ -58,15 +53,11 @@ private ChatRoom(@NotNull String roomId, @NotNull String roomName, @NotNull int userCount, @NotNull int maxUserCount, - @NotNull String roomPwd, - boolean secretCheck, User roomManager) { this.roomId = roomId; this.roomName = roomName; this.userCount = userCount; this.maxUserCount = maxUserCount; - this.roomPwd = roomPwd; - this.secretCheck = secretCheck; this.roomManager = roomManager; this.chatRoomStatus = ChatRoomStatus.ACTIVE; } diff --git a/src/main/java/com/dku/council/domain/chat/repository/ChatRoomRepository.java b/src/main/java/com/dku/council/domain/chat/repository/ChatRoomRepository.java index a70b48f0..d9a756ac 100644 --- a/src/main/java/com/dku/council/domain/chat/repository/ChatRoomRepository.java +++ b/src/main/java/com/dku/council/domain/chat/repository/ChatRoomRepository.java @@ -21,7 +21,7 @@ public interface ChatRoomRepository extends JpaRepository { Optional findChatRoomByRoomId(@Param("roomId") String roomId); @Query("select c from ChatRoom c " + - "where c.roomId = :roomId and c.roomPwd = :roomPwd ") - Optional checkChatRoomByRoomPwd(@Param("roomId") String roomId, - @Param("roomPwd") String roomPwd); + "where c.roomId = :roomId and c.roomManager.id = :userId ") + Optional checkChatRoomManagerByUserId(@Param("roomId") String roomId, + @Param("userId") Long userId); } diff --git a/src/main/java/com/dku/council/domain/chat/service/ChatService.java b/src/main/java/com/dku/council/domain/chat/service/ChatService.java index e63365c5..e48e4d0d 100644 --- a/src/main/java/com/dku/council/domain/chat/service/ChatService.java +++ b/src/main/java/com/dku/council/domain/chat/service/ChatService.java @@ -42,9 +42,7 @@ public List findAllRoom() { ResponseChatRoomDto responseChatRoomDto = new ResponseChatRoomDto(chatRoom.getRoomId(), chatRoom.getRoomName(), chatRoom.getUserCount(), - chatRoom.getMaxUserCount(), - chatRoom.getRoomPwd(), - chatRoom.isSecretCheck()); + chatRoom.getMaxUserCount()); responseChatRoomDtos.add(responseChatRoomDto); } } @@ -63,22 +61,18 @@ public ResponseChatRoomDto findRoomById(String roomId) { return new ResponseChatRoomDto(chatRoom.getRoomId(), chatRoom.getRoomName(), chatRoom.getUserCount(), - chatRoom.getMaxUserCount(), - chatRoom.getRoomPwd(), - chatRoom.isSecretCheck()); + chatRoom.getMaxUserCount()); } /** * 채팅방 생성 * * @param roomName 생성할 채팅방의 이름 - * @param roomPwd 생성항 채팅방의 비밀번호 - * @param secretCheck 생성할 채팅방의 채팅방 잠금 여부 * @param maxUserCount 생성할 채팅방의 최대 인원수 제한 * @param userId 채팅방을 생성하고자 하는 사용자 id * @return 채팅방 정보 */ - public ResponseChatRoomDto createChatRoom(String roomName, String roomPwd, boolean secretCheck, int maxUserCount, Long userId){ + public ResponseChatRoomDto createChatRoom(String roomName, int maxUserCount, Long userId){ // roomName 와 roomPwd 로 chatRoom 빌드 후 return User user = userRepository.findById(userId).orElseThrow(UserNotFoundException::new); @@ -89,17 +83,13 @@ public ResponseChatRoomDto createChatRoom(String roomName, String roomPwd, boole .roomManager(user) // 채팅방 방장 .userCount(0) // 채팅방 참여 인원수 .maxUserCount(maxUserCount) // 최대 인원수 제한 - .roomPwd(roomPwd) // 채팅방 패스워드 - .secretCheck(secretCheck) // 채팅방 잠금 여부 .build(); chatRoomRepository.save(chatRoom); return new ResponseChatRoomDto(chatRoom.getRoomId(), chatRoom.getRoomName(), chatRoom.getUserCount(), - chatRoom.getMaxUserCount(), - chatRoom.getRoomPwd(), - chatRoom.isSecretCheck()); + chatRoom.getMaxUserCount()); } /** @@ -175,15 +165,15 @@ public List getUserList(String roomId){ } /** - * 채팅방 비밀번호 확인 + * 채팅방 방장 확인 * - * @param roomId 비밀번호 확인할 채팅방 id - * @param roomPwd 사용자가 입력한 해당 채팅방의 비밀번호 + * @param roomId 채팅방 id + * @param userId 사용자 id * * @return 확인이 완료되면 true, 아니면 false */ - public boolean confirmPwd(String roomId, String roomPwd) { - return chatRoomRepository.checkChatRoomByRoomPwd(roomId, roomPwd).isPresent(); + public boolean confirmRoomManager(String roomId, Long userId) { + return chatRoomRepository.checkChatRoomManagerByUserId(roomId, userId).isPresent(); } /** diff --git a/src/main/resources/templates/page/chatting/roomlist.html b/src/main/resources/templates/page/chatting/roomlist.html index 43102386..181d0d8c 100644 --- a/src/main/resources/templates/page/chatting/roomlist.html +++ b/src/main/resources/templates/page/chatting/roomlist.html @@ -32,55 +32,6 @@ }); - $("#confirmPwdModal").on("show.bs.modal", function (e) { - roomId = $(e.relatedTarget).data('id'); - // console.log("roomId: " + roomId); - - }); - - // 채팅방 설정 시 비밀번호 확인 - keyup 펑션 활용 - $("#confirmPwd").on("keyup", function(){ - let $confirmPwd = $("#confirmPwd").val(); - const $configRoomBtn = $("#configRoomBtn"); - let $confirmLabel = $("#confirmLabel"); - - $.ajax({ - type : "post", - url : "/chatRoom/confirmPwd/"+roomId, - data : { - "roomPwd" : $confirmPwd - }, - success : function(result){ - // console.log("동작완료") - - // result 의 결과에 따라서 아래 내용 실행 - if(result){ // true 일때는 - // $configRoomBtn 를 활성화 상태로 만들고 비밀번호 확인 완료를 출력 - $configRoomBtn.attr("class", "btn btn-primary"); - $configRoomBtn.attr("aria-disabled", false); - - $confirmLabel.html("비밀번호 확인 완료"); - $("#confirm").css({ - "color" : "#0D6EFD", - "font-weight" : "bold", - }); - - }else{ // false 일때는 - // $configRoomBtn 를 비활성화 상태로 만들고 비밀번호가 틀립니다 문구를 출력 - $configRoomBtn.attr("class", "btn btn-primary disabled"); - $configRoomBtn.attr("aria-disabled", true); - - $confirmLabel.html("비밀번호가 틀립니다"); - $("#confirm").css({ - "color" : "#FA3E3E", - "font-weight" : "bold", - }); - - } - } - }) - }) - // 기본은 유저 설정 칸 미활성화 $maxUserCount.hide(); @@ -101,14 +52,8 @@ function createRoom() { let name = $("#roomName").val(); - let pwd = $("#roomPwd").val(); - let secret = $("#secret").is(':checked'); - let secretChk = $("#secretChk"); let $maxUserCount = $("#maxUserCount"); - // console.log("name : " + name); - // console.log("pwd : " + pwd); - if (name === "") { alert("방 이름은 필수입니다") return false; @@ -117,10 +62,6 @@ alert("이미 존재하는 방입니다") return false; } - if (pwd === "") { - alert("비밀번호는 필수입니다") - return false; - } // 최소 방 인원 수는 2 if($maxUserCount.val() <= 1){ @@ -128,41 +69,24 @@ return false; } - if (secret) { - secretChk.attr('value', true); - } else { - secretChk.attr('value', false); - } - return true; } - // 채팅방 입장 시 비밀번호 확인 - function enterRoom(){ - let $enterPwd = $("#enterPwd").val(); - + // 채팅방 설정 권환 확인 + function checkRoomManager() { $.ajax({ - type : "post", - url : "/chatRoom/confirmPwd/"+roomId, + type : "get", + url : "/confirm/manager/"+roomId, async : false, - data : { - "roomPwd" : $enterPwd - }, success : function(result){ - // console.log("동작완료") - // console.log("확인 : "+chkRoomUserCnt(roomId)) - - if(result){ - if (chkRoomUserCnt(roomId)) { - location.href = "/chatRoom/enter?roomId="+roomId; - } - }else{ - alert("비밀번호가 틀립니다. \n 비밀번호를 확인해주세요") + if(!result) { + alert("채팅방 설정을 변경할 수 있는 권한이 없습니다.") } } }) } + // 채팅방 삭제 function delRoom(){ $.ajax({ type : "DELETE", @@ -250,7 +174,7 @@
- + @@ -258,23 +182,18 @@
- - @@ -299,25 +218,9 @@
- -
- -
- -
-
-
-
-
-
- - - +
- - - - -
채팅방명잠금 여부 참여 인원 채팅방 설정
- [[${room.roomName}]] - - - [[${room.roomName}]] + + [[${room.roomName}]] - - 🔒︎ - + + [[${room.roomName}]] [[${room.userCount}]]/[[${room.maxUserCount}]] - +