Skip to content

Commit

Permalink
Merge pull request EveryUniv#115 from EveryUniv/dev
Browse files Browse the repository at this point in the history
fix: 채팅방 엔티티 수정
  • Loading branch information
kjungw1025 authored Feb 16, 2024
2 parents b5240a5 + aba2374 commit 103c4ad
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 225 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand All @@ -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());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; // 채팅방 잠금 여부
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<ChatRoomUser> users = new ArrayList<>();

Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public interface ChatRoomRepository extends JpaRepository<ChatRoom, Long> {
Optional<ChatRoom> findChatRoomByRoomId(@Param("roomId") String roomId);

@Query("select c from ChatRoom c " +
"where c.roomId = :roomId and c.roomPwd = :roomPwd ")
Optional<ChatRoom> checkChatRoomByRoomPwd(@Param("roomId") String roomId,
@Param("roomPwd") String roomPwd);
"where c.roomId = :roomId and c.roomManager.id = :userId ")
Optional<ChatRoom> checkChatRoomManagerByUserId(@Param("roomId") String roomId,
@Param("userId") Long userId);
}
28 changes: 9 additions & 19 deletions src/main/java/com/dku/council/domain/chat/service/ChatService.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ public List<ResponseChatRoomDto> findAllRoom() {
ResponseChatRoomDto responseChatRoomDto = new ResponseChatRoomDto(chatRoom.getRoomId(),
chatRoom.getRoomName(),
chatRoom.getUserCount(),
chatRoom.getMaxUserCount(),
chatRoom.getRoomPwd(),
chatRoom.isSecretCheck());
chatRoom.getMaxUserCount());
responseChatRoomDtos.add(responseChatRoomDto);
}
}
Expand All @@ -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);
Expand All @@ -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());
}

/**
Expand Down Expand Up @@ -175,15 +165,15 @@ public List<String> 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();
}

/**
Expand Down
Loading

0 comments on commit 103c4ad

Please sign in to comment.