Skip to content
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

Merged
merged 6 commits into from
Nov 26, 2024

Conversation

suuu0719
Copy link
Contributor

⚒️develop의 최신 커밋을 pull 받았나요?

#️⃣ 작업 내용

방장이 나가는 경우 그 다음으로 가장 먼저 들어온 mate가 방장이 되도록 변경
비공개방 전환 API 구현
persona range 1-16으로 수정했습니다

동작 확인

image
방장이 나갔을 때
image
그 다음으로 들어온 mate가 방장이 됨
최후의 방장이 나갔을때 방 삭제되는 것 확인했습니다

비공개방 전환
image
이미 비공개방일때
image
비공개방 전환 성공

💬 리뷰 요구사항(선택)

리뷰어가 특별히 봐주었으면 하는 부분이 있다면 작성해주세요
고민사항도 적어주세요.

@suuu0719 suuu0719 self-assigned this Nov 25, 2024
@suuu0719 suuu0719 added the enhancement New feature or request label Nov 25, 2024
Copy link

리뷰해드려요~

Mate.java - 리뷰 1

  • 새로운 메서드 setRoomManagersetNotRoomManager가 추가되었습니다.
  • 이러한 메서드는 룸 매니저 여부를 설정하거나 해제하는 데 사용됩니다.

Room.java - 리뷰 2

  • 메서드 이름 convertToPublicRoom가 변경되었습니다.
  • 이제 changeToPublicRoom로 변경되었습니다.
  • 또한 convertToPrivateRoom 메서드가 추가되었습니다.
  • 이 메서드는 방을 비공개 방으로 전환하는 데 사용됩니다.

RoomController.java - 리뷰 3

  • convertToPublicRoom 메서드 이름이 변경되었습니다.
  • 이제 changeToPublicRoom로 변경되었습니다.
  • 또한 convertToPrivateRoom 메서드가 추가되었습니다.
  • 이 메서드는 방을 비공개 방으로 전환하는 데 사용됩니다.

PrivateRoomCreateRequestDTO.java, PublicRoomCreateRequestDTO.java, RoomUpdateRequestDTO.java - 리뷰 4

  • persona 필드의 범위가 변경되었습니다.
  • 이제 1에서 16 사이입니다.

RoomCommandService.java - 리뷰 5

  • deleteRoomDatas 메서드에 새로운 메서드 assignNewRoomManager가 추가되었습니다.
  • 이 메서드는 방 매니저가 방을 떠날 때 새로운 방 매니저를 지정합니다.
  • convertToPublicRoomconvertToPrivateRoom 메서드 이름이 변경되었습니다.
  • 이제 changeToPublicRoomchangeToPrivateRoom로 변경되었습니다.
  • 또한 convertToPrivateRoom 메서드가 추가되었습니다.
  • 이 메서드는 방을 비공개 방으로 전환하는 데 사용됩니다.

추가 개선 사항:

  • 룸 매니저 여부를 설정하는 메서드를 더 설계할 수 있습니다.
  • 룸 매니저 여부를 설정하는 메서드는 룸 매니저가 방을 떠날 때 새로운 룸 매니저를 지정하는 데 사용될 수 있습니다.
  • 룸 매니저 여부를 설정하는 메서드는 룸 매니저가 방에서 나가거나 방을 떠날 때 새로운 룸 매니저를 지정하는 데 사용될 수 있습니다.
  • 룸 매니저 여부를 설정하는 메서드는 룸 매니저가 방에 입장할 때 룸 매니저로 지정되는 데 사용될 수 있습니다.
  • 룸 매니저 여부를 설정하는 메서드는 룸 매니저가 방에 입장할 때 룸 매니저로 지정되는 데 사용될 수 있습니다.

위의 제안은 현재 코드에 추가될 수 있는 추가 개선 사항입니다. 이러한 제안은 필요한 경우에만 적용되어야 합니다.

@@ -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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Range 1-16으로 수정했습니다

Comment on lines 240 to 254
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);
}

Copy link
Contributor Author

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) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

방 공개 상태 변경 함수 이름 전체적으로 changeTo로 통일했습니다

Comment on lines +607 to +626
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();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

방장인 경우에만 PRIVATE 상태로 변경할 수 있습니다

Copy link
Contributor

@genius00hwan genius00hwan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 수고하셨습니다

Copy link
Contributor

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로 바꿔야 할거에여

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@jpark0506 jpark0506 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 질문 몇개 남겼습니다

Comment on lines 251 to 253
newManager.setRoomManager();
mateRepository.save(newManager);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update면 save 없어도 될거 같아여

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이게 findBy로 가져온게 아니라서 바로 더티체크 안되지 않나여? flush()든 save()든 해야하지 않나여

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

삭제해도 정상적으로 동작해서 지웠습니당

Comment on lines 603 to 605
room.changeToPublicRoom();
roomRepository.save(room);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

얘도여

Copy link

리뷰해드려요~

RoomController.java - 변경 1

  • 방 전환 요청 메서드 이름 변경(convertToPublicRoom -> changeToPublicRoom)

RoomController.java - 추가 1

  • 방 전환 요청 메서드 추가(changeToPrivateRoom)

Room.java - 추가 1

  • 방 상태 변경 메서드 추가(changeToPublicRoom, changeToPrivateRoom, enableRoom)

RoomCommandService.java - 변경 1

  • 방 생성 메서드 내에 방 상태 변경 메서드 호출 추가(enableRoom)

RoomCommandService.java - 변경 2

  • 방 삭제 메서드 내에 방 내 멤버 정보 업데이트 메서드 호출 추가(assignNewRoomManager)

RoomCommandService.java - 추가 1

  • 방 내 방장 위임 메서드 추가(assignNewRoomManager)

PrivateRoomCreateRequestDTO.java, PublicRoomCreateRequestDTO.java, RoomUpdateRequestDTO.java - 변경 1

  • 프로필 이미지 선택 필수 여부 변경(0 -> 1)

PostCommentRepository.java, PostImageRepository.java - 변경 1

  • 삭제 메서드 변경(deleteByPostId -> deleteAllByPostId)

추가적으로 제안할 수 있는 개선 사항은 다음과 같습니다.

  • Room.java - 추가 1

  • 방 생성 메서드 내에 방 상태 설정 메서드 호출 추가(setRoomType)

  • RoomCommandService.java - 변경 1

  • 방 생성 메서드 내에 방 상태 설정 메서드 호출 추가(setRoomType)

  • RoomCommandService.java - 추가 1

  • 방 상태 설정 메서드 추가(setRoomType)

  • RoomController.java - 변경 1

  • 방 상태 변경 메서드 내에 방 상태 설정 메서드 호출 추가(setRoomType)

  • RoomController.java - 추가 1

  • 방 상태 변경 메서드 추가(setRoomType)

이렇게 하면 방의 상태를 변경할 때 반드시 방 생성 또는 방 상태 변경 메서드에서 방 상태를 설정해주는 것이 아니라 별도의 메서드를 호출해서 방 상태를 설정할 수 있게 됩니다. 이렇게 하면 방 상태를 변경하는 로직을 더 간단하게 구현할 수 있습니다.

@suuu0719 suuu0719 merged commit 15b02a9 into develop Nov 26, 2024
1 check passed
@suuu0719 suuu0719 deleted the feature/COZY-395 branch November 26, 2024 07:09
Copy link

리뷰해드려요~

RoomController.java

  • 방 변경 기능에 대한 새로운 패치 메서드(convertToPrivateRoom)가 추가되었습니다.
  • 이 메서드는 특정 방의 유형을 비공개 방으로 변경합니다.
  • 메서드 내용은 아래와 같습니다.
@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

  • 방 유형 변경 기능을 위한 메서드(changeToPublicRoom, changeToPrivateRoom, enableRoom)가 추가되었습니다.
  • 이 메서드는 방의 유형을 공개 방으로 변경하거나 비공개 방으로 변경하거나 방을 활성화하는 기능을 제공합니다.
  • 메서드 내용은 아래와 같습니다.
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

  • 방 유형 변경 기능을 위한 메서드(changeToPublicRoom, changeToPrivateRoom)가 추가되었습니다.
  • 이 메서드는 특정 방의 유형을 공개 방으로 변경하거나 비공개 방으로 변경합니다.
  • 메서드 내용은 아래와 같습니다.
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

  • 방 관리자 여부 설정 기능을 위한 메서드(setRoomManager, setNotRoomManager)가 추가되었습니다.
  • 이 메서드는 특정 멤버가 방 관리자인지 여부를 설정합니다.
  • 메서드 내용은 아래와 같습니다.
public void setRoomManager() {
    this.isRoomManager = true;
}

public void setNotRoomManager() {
    this.isRoomManager = false;
}
  • 추가 개선 사항:
  • RoomController.java에서 convertToPublicRoom 메서드에서 roomCommandService.convertToPublicRoom(roomId, memberDetails.member().getId());roomCommandService.changeToPublicRoom(roomId, memberDetails.member().getId());로 변경해야 합니다.
  • RoomController.java에서 convertToPrivateRoom 메서드를 추가해야 합니다.
  • Room.java에서 convertToPublicRoom 메서드를 changeToPublicRoom 메서드로 변경해야 합니다.
  • Room.java에서 convertToPrivateRoom 메서드를 changeToPrivateRoom 메서드로 변경해야 합니다.
  • RoomCommandService.java에서 convertToPublicRoom 메서드를 changeToPublicRoom 메서드로 변경해야 합니다.
  • RoomCommandService.java에서 convertToPrivateRoom 메서드를 changeToPrivateRoom 메서드로 변경해야 합니다.

추가 개선 사항을 적용하면 코드가 더욱 깔끔하고 일관성 있게 보일 수 있습니다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants