-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[COZY-395] feat: 방장 로직 수정, 비공개방 전환 API #187
Conversation
리뷰해드려요~Mate.java - 리뷰 1
Room.java - 리뷰 2
RoomController.java - 리뷰 3
PrivateRoomCreateRequestDTO.java, PublicRoomCreateRequestDTO.java, RoomUpdateRequestDTO.java - 리뷰 4
RoomCommandService.java - 리뷰 5
추가 개선 사항:
위의 제안은 현재 코드에 추가될 수 있는 추가 개선 사항입니다. 이러한 제안은 필요한 경우에만 적용되어야 합니다. |
@@ -12,7 +12,7 @@ public record PrivateRoomCreateRequestDTO( | |||
@Pattern(regexp = "^(?!\\s)[가-힣a-zA-Z0-9\\s]+(?<!\\s)$", message = "한글, 영어, 숫자 및 공백만 입력해주세요. 단, 공백은 처음이나 끝에 올 수 없습니다.") | |||
String name, | |||
@NotNull(message = "프로필 이미지 선택은 필수입니다.") | |||
@Range(min=0, max=15) | |||
@Range(min=1, max=16) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Range 1-16으로 수정했습니다
private void assignNewRoomManager(Long roomId, Mate quittingMate) { | ||
quittingMate.setNotRoomManager(); | ||
mateRepository.save(quittingMate); | ||
List<Mate> remainingMates = mateRepository.findAllByRoomIdAndEntryStatus(roomId, EntryStatus.JOINED); | ||
|
||
if (remainingMates.isEmpty()) { | ||
return; | ||
} | ||
Mate newManager = remainingMates.stream() | ||
.min(Comparator.comparing(Mate::getCreatedAt)) | ||
.orElseThrow(() -> new GeneralException(ErrorStatus._ROOM_MANAGER_NOT_FOUND)); // 방장 없음 예외 처리 | ||
newManager.setRoomManager(); | ||
mateRepository.save(newManager); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
방에 JOINED 상태인 mate들 중 가장 먼저 들어온 mate가 방장이 되도록 했습니다
@@ -563,15 +581,14 @@ public void respondToJoinRequest(Long requesterId, boolean accept, Long managerI | |||
} | |||
} | |||
|
|||
public void convertToPublicRoom(Long roomId, Long memberId) { | |||
public void changeToPublicRoom(Long roomId, Long memberId) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
방 공개 상태 변경 함수 이름 전체적으로 changeTo로 통일했습니다
public void changeToPrivateRoom(Long roomId, Long memberId) { | ||
memberRepository.findById(memberId) | ||
.orElseThrow(() -> new GeneralException(ErrorStatus._MEMBER_NOT_FOUND)); | ||
|
||
Room room = roomRepository.findById(roomId) | ||
.orElseThrow(() -> new GeneralException(ErrorStatus._ROOM_NOT_FOUND)); | ||
|
||
Mate member = mateRepository.findByRoomIdAndMemberIdAndEntryStatus(roomId, memberId, | ||
EntryStatus.JOINED) | ||
.orElseThrow(() -> new GeneralException(ErrorStatus._NOT_ROOM_MATE)); | ||
|
||
if (!member.isRoomManager()) { | ||
throw new GeneralException(ErrorStatus._NOT_ROOM_MANAGER); | ||
} | ||
|
||
if (room.getRoomType() != RoomType.PUBLIC) { | ||
throw new GeneralException(ErrorStatus._PRIVATE_ROOM); | ||
} | ||
|
||
room.changeToPrivateRoom(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
방장인 경우에만 PRIVATE 상태로 변경할 수 있습니다
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 수고하셨습니다
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
원래 못봤었는데 deleteRoomDatas()에서
for (Post post : posts) {
postCommentRepository.deleteByPostId(post.getId());
postImageRepository.deleteByPostId(post.getId());
}
deleteByPostId(post.getId()), deleteByPostId(post.getId()); 이러면 최초 단건 삭제 아닌가여 deleteAllByPostId로 바꿔야 할거에여
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
넵
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 질문 몇개 남겼습니다
newManager.setRoomManager(); | ||
mateRepository.save(newManager); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
update면 save 없어도 될거 같아여
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이게 findBy로 가져온게 아니라서 바로 더티체크 안되지 않나여? flush()든 save()든 해야하지 않나여
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
삭제해도 정상적으로 동작해서 지웠습니당
room.changeToPublicRoom(); | ||
roomRepository.save(room); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
얘도여
리뷰해드려요~RoomController.java - 변경 1
RoomController.java - 추가 1
Room.java - 추가 1
RoomCommandService.java - 변경 1
RoomCommandService.java - 변경 2
RoomCommandService.java - 추가 1
PrivateRoomCreateRequestDTO.java, PublicRoomCreateRequestDTO.java, RoomUpdateRequestDTO.java - 변경 1
PostCommentRepository.java, PostImageRepository.java - 변경 1
추가적으로 제안할 수 있는 개선 사항은 다음과 같습니다.
이렇게 하면 방의 상태를 변경할 때 반드시 방 생성 또는 방 상태 변경 메서드에서 방 상태를 설정해주는 것이 아니라 별도의 메서드를 호출해서 방 상태를 설정할 수 있게 됩니다. 이렇게 하면 방 상태를 변경하는 로직을 더 간단하게 구현할 수 있습니다. |
리뷰해드려요~RoomController.java
@PatchMapping("/{roomId}/to-private")
@Operation(summary = "[바니] 비공개방으로 전환", description = "roomId에 해당하는 방을 비공개방으로 전환합니다.")
@SwaggerApiError({
ErrorStatus._MEMBER_NOT_FOUND,
ErrorStatus._ROOM_NOT_FOUND,
ErrorStatus._NOT_ROOM_MATE,
ErrorStatus._NOT_ROOM_MANAGER,
ErrorStatus._PRIVATE_ROOM,
})
public ResponseEntity<ApiResponse<String>> convertToPrivateRoom(
@PathVariable Long roomId, @AuthenticationPrincipal MemberDetails memberDetails) {
roomCommandService.changeToPrivateRoom(roomId, memberDetails.member().getId());
return ResponseEntity.ok(ApiResponse.onSuccess("비공개방 전환 완료"));
} Room.java
public void changeToPublicRoom() {
this.roomType = RoomType.PUBLIC;
if (this.getStatus() != RoomStatus.ENABLE) {
enableRoom();
}
}
public void changeToPrivateRoom() {
this.roomType = RoomType.PRIVATE;
if (this.getStatus() != RoomStatus.ENABLE) {
enableRoom();
}
}
public void enableRoom() {
this.status = RoomStatus.ENABLE;
this.enabledAt = LocalDate.now();
} RoomCommandService.java
public void changeToPublicRoom(Long roomId, Long memberId) {
memberRepository.findById(memberId)
.orElseThrow(() -> new GeneralException(ErrorStatus._MEMBER_NOT_FOUND));
Room room = roomRepository.findById(roomId)
.orElseThrow(() -> new GeneralException(ErrorStatus._ROOM_NOT_FOUND));
Mate member = mateRepository.findByRoomIdAndMemberIdAndEntryStatus(roomId, memberId,
EntryStatus.JOINED)
.orElseThrow(() -> new GeneralException(ErrorStatus._NOT_ROOM_MATE));
// 방장이 아니면 예외 발생
if (!member.isRoomManager()) {
throw new GeneralException(ErrorStatus._NOT_ROOM_MANAGER);
}
if (room.getRoomType() != RoomType.PRIVATE) {
throw new GeneralException(ErrorStatus._PRIVATE_ROOM);
}
room.changeToPublicRoom();
}
public void changeToPrivateRoom(Long roomId, Long memberId) {
memberRepository.findById(memberId)
.orElseThrow(() -> new GeneralException(ErrorStatus._MEMBER_NOT_FOUND));
Room room = roomRepository.findById(roomId)
.orElseThrow(() -> new GeneralException(ErrorStatus._ROOM_NOT_FOUND));
Mate member = mateRepository.findByRoomIdAndMemberIdAndEntryStatus(roomId, memberId,
EntryStatus.JOINED)
.orElseThrow(() -> new GeneralException(ErrorStatus._NOT_ROOM_MATE));
if (!member.isRoomManager()) {
throw new GeneralException(ErrorStatus._NOT_ROOM_MANAGER);
}
if (room.getRoomType() != RoomType.PUBLIC) {
throw new GeneralException(ErrorStatus._PUBLIC_ROOM);
}
room.changeToPrivateRoom();
} Mate.java
public void setRoomManager() {
this.isRoomManager = true;
}
public void setNotRoomManager() {
this.isRoomManager = false;
}
추가 개선 사항을 적용하면 코드가 더욱 깔끔하고 일관성 있게 보일 수 있습니다. |
⚒️develop의 최신 커밋을 pull 받았나요?
네
#️⃣ 작업 내용
방장이 나가는 경우 그 다음으로 가장 먼저 들어온 mate가 방장이 되도록 변경
비공개방 전환 API 구현
persona range 1-16으로 수정했습니다
동작 확인
방장이 나갔을 때
그 다음으로 들어온 mate가 방장이 됨
최후의 방장이 나갔을때 방 삭제되는 것 확인했습니다
비공개방 전환


이미 비공개방일때
비공개방 전환 성공
💬 리뷰 요구사항(선택)