Skip to content

Conversation

@dahyun24
Copy link
Collaborator

해당 사항 (중복 선택)

  • FEAT : 새로운 기능 추가 및 개선
  • FIX : 기존 기능 수정 및 정상 동작을 위한 간단한 추가, 수정사항
  • BUG : 버그 수정
  • REFACTOR : 결과의 변경 없이 코드의 구조를 재조정
  • TEST : 테스트 코드 추가
  • DOCS : 코드가 아닌 문서를 수정한 경우
  • REMOVE : 파일을 삭제하는 작업만 수행
  • RENAME : 파일 또는 폴더명을 수정하거나 위치(경로)를 변경
  • ETC : 이외에 다른 경우 - 어떠한 사항인지 작성해주세요.

설명

  • 시도한 방법 : 하나의 DB를 사용하여 Service 차원에서 읽기 쓰기를 나눔
    • RoomCommandService (write)

    • RoomQueryService (read) 의 경우 @Transactional(readOnly = true) 적용

      cqrs 이론 이미지

🔗 관련 이슈

해결한 이슈: closed #260

📝 작업 내용

1. CQRS 패턴 적용

cqrs

K6 성능 테스트 결과 (10명, 30명, 50명 들어있는 방에서 데이터 조회(GET)및 변경(POST) 성능 테스트)

  • 엄청난 성능 향상 결과 보이지 않음
  • (분석 결과 노션) CQRS 성능 테스트 결과 비교
    • => 읽기, 쓰기 DB 분리를 통한 CQRS 적용 예정 (DB replication)

2. 방 나가기 / 방 삭제 기능 추가

  • 방 삭제의 경우 creator(0)만 가능
    *creator가 방 나가기를 했을 경우 새로운 creator는 누구에게로 주어야하는가의 문제가 새롭게 생김
  • /api/rooms/leave/{roomId}
  • /api/rooms/delete/{roomId}

@dahyun24 dahyun24 self-assigned this Mar 24, 2025
@dahyun24 dahyun24 added the 🕹️BE 백엔드 작업 label Mar 24, 2025
@42inshin 42inshin requested a review from Copilot March 30, 2025 12:25
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces new CQRS functionality by separating command and query responsibilities for room operations, and implements additional endpoints for room leave and delete actions.

  • Implements joinRoom, leaveRoom, and deleteRoom methods in RoomService.
  • Introduces a new RoomQueryService to handle read operations.
  • Updates RoomController and InvitationController to use the new service methods.

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/backend/main-server/main/src/main/java/com/kickzo/main/service/RoomService.java Refactors room join flow and adds leaveRoom and deleteRoom functionalities.
src/backend/main-server/main/src/main/java/com/kickzo/main/service/RoomQueryService.java New service for handling read operations and room information retrieval.
src/backend/main-server/main/src/main/java/com/kickzo/main/repository/UserOutRedisRepository.java Adds method to remove room entries from Redis.
src/backend/main-server/main/src/main/java/com/kickzo/main/repository/RoomUserRepository.java Adds deleteByRoomId method for removing all room users on room deletion.
src/backend/main-server/main/src/main/java/com/kickzo/main/controller/RoomController.java Updates endpoints to reflect new command/query separation and adds endpoints for leaving and deleting a room.
src/backend/main-server/main/src/main/java/com/kickzo/main/controller/InvitationController.java Adjusts dependency to use RoomQueryService for invitation acceptance flow.
Comments suppressed due to low confidence (1)

src/backend/main-server/main/src/main/java/com/kickzo/main/service/RoomService.java:90

  • The call to findRoleByUserIdAndRoomId may return null; consider changing the variable type to Integer and adding a null check before comparing against 0.
int role = roomUserRepository.findRoleByUserIdAndRoomId(roomId, userId);

Copy link
Member

@42inshin 42inshin left a comment

Choose a reason for hiding this comment

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

java 코드도 한번씩 PR 보려고 해요~! 화이팅입니다

Comment on lines 90 to 93
int role = roomUserRepository.findRoleByUserIdAndRoomId(roomId, userId);
if (role != 0){
throw new CustomException(CustomErrorCode.INVALID_ACCESS_ROLE);
}
Copy link
Member

Choose a reason for hiding this comment

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

role을 enum을 만들어서 관리하는건 어떨까요? 나중에 볼때 0번이 뭔지 기억 안날수도 있을 것 같아요

ai 추천으로는 아래 방식을 알려주네요 ㅎㅎ

 // 삭제 권한 확인 (ADMIN = 0)
    Integer role = roomUserRepository.findRoleByUserIdAndRoomId(roomId, userId);
    if (role == null || !Objects.equals(role, RoomRole.ADMIN.getValue())) {
        throw new CustomException(CustomErrorCode.INVALID_ACCESS_ROLE);
    }
public enum RoomRole {
    ADMIN(0),
    MEMBER(1);

    private final int value;

    RoomRole(int value) {
        this.value = value;
    }

    public int getValue() {
        return value;
    }
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

수정 완료 하였습니다! 감사합니다~

@dahyun24 dahyun24 added the FEAT 새로운 기능 추가 및 개선 label Apr 3, 2025
@dahyun24 dahyun24 changed the title [BE] FEAT: 메인서버 CQRS 적용 + 방 삭제/나가기 기능 추가 [BE] FEAT: 메인서버 CQRS 적용 + 방 삭제/나가기 기능 추가 #260 Apr 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🕹️BE 백엔드 작업 FEAT 새로운 기능 추가 및 개선

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BE] FEAT: 메인서버 - CQRS 패턴 적용

3 participants