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

feat: 스터디 히스토리 V2 도메인 구현 #876

Merged
merged 3 commits into from
Feb 9, 2025

Conversation

Sangwook02
Copy link
Member

@Sangwook02 Sangwook02 commented Feb 9, 2025

🌱 관련 이슈

📌 작업 내용 및 특이사항

  • 기존 스터디를 StudyV2로 재구현함에 따라 구버전 Study를 레퍼런스하고 있는 StudyHistory를 재구현했습니다.

📝 참고사항

📚 기타

Summary by CodeRabbit

  • 새로운 기능
    • 스터디 진행 이력 관리 기능이 추가되어, 사용자가 스터디 참여 기록을 생성하고 업데이트할 수 있습니다.
    • 스터디 완료 여부 확인 및 완료 취소 기능으로 보다 유연하게 진행 상태를 관리할 수 있습니다.

@Sangwook02 Sangwook02 self-assigned this Feb 9, 2025
@Sangwook02 Sangwook02 requested a review from a team as a code owner February 9, 2025 10:12
Copy link

coderabbitai bot commented Feb 9, 2025

Walkthrough

이번 PR은 새로운 StudyHistoryV2 클래스가 추가된 변경사항을 포함합니다. 해당 클래스는 BaseEntity를 상속하며 JPA 엔티티로 study_history_v2 테이블과 매핑됩니다. 클래스는 id, status(StudyHistoryStatus), repositoryLink, Member 및 StudyV2 엔티티와의 연관 관계 필드를 포함합니다. 또한, 생성, repositoryLink 업데이트, 완료 처리, 완료 취소 및 완료 여부 확인 메서드를 제공하며, 엔티티 제거 전 StudyApplyCanceledEvent 이벤트를 등록합니다.

Changes

파일 경로 변경 내용
src/main/java/com/gdschongik/…/StudyHistoryV2.java 새로운 StudyHistoryV2 클래스 추가 (BaseEntity 상속, JPA 엔티티로 study_history_v2 매핑). 필드: id, status, repositoryLink, Member, StudyV2. 생성 메서드(create) 및 updateRepositoryLink, complete, withdrawCompletion, isCompleted 메서드 추가. @PreRemove를 통한 이벤트(StudyApplyCanceledEvent) 등록.

Sequence Diagram(s)

sequenceDiagram
    participant C as Client
    participant SH as StudyHistoryV2
    participant E as Event System

    C->>SH: create(member, study)
    SH-->>C: 인스턴스 반환

    C->>SH: updateRepositoryLink(link)
    C->>SH: complete()
    SH->>E: StudyCompletion 이벤트 등록

    C->>SH: withdrawCompletion()
    SH->>E: CompletionWithdrawn 이벤트 등록

    C->>SH: Entity 제거
    SH->>E: StudyApplyCanceled 이벤트 등록
Loading

Possibly related PRs

Suggested labels

✨ feature

Suggested reviewers

  • kckc0608
  • uwoobeat

Poem

깡총깡총 뛰는 나의 발,
StudyHistoryV2로 기록을 새로 채워요.
메서드 하나하나 정갈한 춤사위,
이벤트와 함께 빛나는 코드의 길.
토끼의 축복, 영원한 코드의 봄! 🐇


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0486ffe and 9b03efb.

📒 Files selected for processing (1)
  • src/main/java/com/gdschongik/gdsc/domain/studyv2/domain/StudyHistoryV2.java (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/java/com/gdschongik/gdsc/domain/studyv2/domain/StudyHistoryV2.java

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

github-actions bot commented Feb 9, 2025

Job Summary for Gradle

Check Style and Test to Develop :: build-test
Gradle Root Project Requested Tasks Gradle Version Build Outcome Build Scan®
gdsc check 8.5 Build Scan published

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between efe4a8f and 194a2c7.

📒 Files selected for processing (1)
  • src/main/java/com/gdschongik/gdsc/domain/studyv2/domain/StudyHistoryV2.java (1 hunks)
🔇 Additional comments (2)
src/main/java/com/gdschongik/gdsc/domain/studyv2/domain/StudyHistoryV2.java (2)

32-34: 유니크 제약 조건에 대한 예외 처리 추가 필요

member_id와 study_v2_id의 유니크 제약 조건 위반 시 발생하는 예외에 대한 적절한 처리가 필요합니다. 사용자에게 의미 있는 에러 메시지를 전달하기 위해 예외 처리 로직을 추가하는 것이 좋습니다.


48-54: 연관 관계의 cascade 설정 검토 필요

@ManyToOne 관계에서 cascade 옵션이 명시되어 있지 않습니다. StudyV2나 Member 엔티티의 생명주기가 StudyHistoryV2에 영향을 받아야 하는지 검토가 필요합니다.

Comment on lines 63 to 65
public static StudyHistoryV2 create(Member student, StudyV2 study) {
return StudyHistoryV2.builder().student(student).study(study).build();
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

파라미터 유효성 검증 추가 필요

create 메소드에서 studentstudy 파라미터의 null 체크가 누락되어 있습니다. 잠재적인 NullPointerException을 방지하기 위해 검증 로직을 추가하는 것이 좋습니다.

다음과 같이 수정을 제안합니다:

 public static StudyHistoryV2 create(Member student, StudyV2 study) {
+    if (student == null || study == null) {
+        throw new IllegalArgumentException("student와 study는 null이 될 수 없습니다.");
+    }
     return StudyHistoryV2.builder().student(student).study(study).build();
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public static StudyHistoryV2 create(Member student, StudyV2 study) {
return StudyHistoryV2.builder().student(student).study(study).build();
}
public static StudyHistoryV2 create(Member student, StudyV2 study) {
if (student == null || study == null) {
throw new IllegalArgumentException("student와 study는 null이 될 수 없습니다.");
}
return StudyHistoryV2.builder().student(student).study(study).build();
}

Comment on lines 89 to 92
public void withdrawCompletion() {
studyHistoryStatus = NONE;
registerEvent(new StudyHistoryCompletionWithdrawnEvent(this.id));
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

상태 변경 검증 로직 추가 필요

withdrawCompletion 메소드에서 현재 상태가 COMPLETED가 아닌 경우에 대한 처리가 누락되어 있습니다. 잘못된 상태에서의 철회를 방지하기 위한 검증이 필요합니다.

다음과 같이 수정을 제안합니다:

 public void withdrawCompletion() {
+    if (!isCompleted()) {
+        throw new IllegalStateException("완료되지 않은 스터디는 철회할 수 없습니다.");
+    }
     studyHistoryStatus = NONE;
     registerEvent(new StudyHistoryCompletionWithdrawnEvent(this.id));
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public void withdrawCompletion() {
studyHistoryStatus = NONE;
registerEvent(new StudyHistoryCompletionWithdrawnEvent(this.id));
}
public void withdrawCompletion() {
if (!isCompleted()) {
throw new IllegalStateException("완료되지 않은 스터디는 철회할 수 없습니다.");
}
studyHistoryStatus = NONE;
registerEvent(new StudyHistoryCompletionWithdrawnEvent(this.id));
}

Comment on lines 82 to 84
public void complete() {
studyHistoryStatus = COMPLETED;
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

상태 변경 검증 로직 추가 필요

complete 메소드에서 현재 상태가 이미 COMPLETED인 경우에 대한 처리가 누락되어 있습니다. 중복 완료 처리를 방지하기 위한 검증이 필요합니다.

다음과 같이 수정을 제안합니다:

 public void complete() {
+    if (isCompleted()) {
+        throw new IllegalStateException("이미 완료된 스터디입니다.");
+    }
     studyHistoryStatus = COMPLETED;
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public void complete() {
studyHistoryStatus = COMPLETED;
}
public void complete() {
if (isCompleted()) {
throw new IllegalStateException("이미 완료된 스터디입니다.");
}
studyHistoryStatus = COMPLETED;
}


@Builder(access = AccessLevel.PRIVATE)
private StudyHistoryV2(Member student, StudyV2 study) {
this.studyHistoryStatus = NONE;
Copy link
Member

Choose a reason for hiding this comment

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

빌더에서는 전달된 값을 그대로 할당
정팩메에서 디폴트 값을 지정하도록 수정해야 합니다


@Comment("수료 상태")
@Enumerated(EnumType.STRING)
private StudyHistoryStatus studyHistoryStatus;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
private StudyHistoryStatus studyHistoryStatus;
private StudyHistoryStatus status;

Copy link
Member Author

Choose a reason for hiding this comment

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

수정하는 김에 #850 이것도 반영했어요

Copy link

github-actions bot commented Feb 9, 2025

Job Summary for Gradle

Check Style and Test to Develop :: build-test
Gradle Root Project Requested Tasks Gradle Version Build Outcome Build Scan®
gdsc check 8.5 Build Scan published

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 194a2c7 and 0486ffe.

📒 Files selected for processing (1)
  • src/main/java/com/gdschongik/gdsc/domain/study/domain/StudyHistory.java (4 hunks)
🔇 Additional comments (2)
src/main/java/com/gdschongik/gdsc/domain/study/domain/StudyHistory.java (2)

52-57: 생성자 구현이 적절합니다!

빌더 패턴과 private 접근 제어자를 사용하여 객체 생성을 적절히 제한하고 있습니다.


59-61: 팩토리 메서드 구현이 적절합니다!

정적 팩토리 메서드를 통해 초기 상태를 NONE으로 설정하는 것이 적절합니다.

Comment on lines 38 to 42
private String repositoryLink;

@Comment("수료 상태")
@Enumerated(EnumType.STRING)
private StudyHistoryStatus studyHistoryStatus;

private String repositoryLink;
private StudyHistoryStatus status;
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

repositoryLink 필드에 JPA 어노테이션 추가 필요

데이터베이스 매핑을 명시적으로 하기 위해 다음과 같은 개선이 필요합니다:

-    private String repositoryLink;
+    @Column(name = "repository_link")
+    @Comment("레포지토리 링크")
+    private String repositoryLink;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
private String repositoryLink;
@Comment("수료 상태")
@Enumerated(EnumType.STRING)
private StudyHistoryStatus studyHistoryStatus;
private String repositoryLink;
private StudyHistoryStatus status;
@Column(name = "repository_link")
@Comment("레포지토리 링크")
private String repositoryLink;
@Comment("수료 상태")
@Enumerated(EnumType.STRING)
private StudyHistoryStatus status;

Comment on lines 78 to 88
public void complete() {
studyHistoryStatus = COMPLETED;
status = COMPLETED;
}

/**
* 스터디 수료 철회
*/
public void withdrawCompletion() {
studyHistoryStatus = NONE;
status = NONE;
registerEvent(new StudyHistoryCompletionWithdrawnEvent(this.id));
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

상태 변경 시 유효성 검사 및 이벤트 처리 개선 필요

상태 변경 메서드에 다음과 같은 개선이 필요합니다:

  1. 상태 변경 전 유효성 검사
  2. complete() 메서드에도 이벤트 등록 추가
 public void complete() {
+    if (status == COMPLETED) {
+        throw new IllegalStateException("이미 수료 완료된 스터디입니다.");
+    }
     status = COMPLETED;
+    registerEvent(new StudyHistoryCompletedEvent(this.id));
 }

 public void withdrawCompletion() {
+    if (status != COMPLETED) {
+        throw new IllegalStateException("수료 상태가 아닌 스터디는 철회할 수 없습니다.");
+    }
     status = NONE;
     registerEvent(new StudyHistoryCompletionWithdrawnEvent(this.id));
 }

Copy link
Member

@uwoobeat uwoobeat left a comment

Choose a reason for hiding this comment

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

lgtm


@PreRemove
private void preRemove() {
registerEvent(new StudyApplyCanceledEvent(this.study.getId(), this.student.getId()));
Copy link
Member

Choose a reason for hiding this comment

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

여기서는 this를 쓰고있네요

Copy link
Member Author

Choose a reason for hiding this comment

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

아 리뷰 반영을 V1에 반영함..
수정하고 머지할게요

@uwoobeat
Copy link
Member

uwoobeat commented Feb 9, 2025

그리고 기존 엔티티 순서는 그대로 냅둬도 될듯요

Copy link
Member

@kckc0608 kckc0608 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

github-actions bot commented Feb 9, 2025

Job Summary for Gradle

Check Style and Test to Develop :: build-test
Gradle Root Project Requested Tasks Gradle Version Build Outcome Build Scan®
gdsc check 8.5 Build Scan published

@Sangwook02 Sangwook02 merged commit b56893d into develop Feb 9, 2025
1 check passed
@Sangwook02 Sangwook02 deleted the feature/874-study-history-v2 branch February 9, 2025 10:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

✨ StudyHistory V2 도메인 구현
3 participants