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: 과제 스터디 생성 로직 구현 #869

Merged
merged 9 commits into from
Feb 8, 2025

Conversation

uwoobeat
Copy link
Member

@uwoobeat uwoobeat commented Feb 6, 2025

🌱 관련 이슈

📌 작업 내용 및 특이사항

  • 엔드포인트 분리하는 것보다 그냥 추상화된 형태로 제공하고 내부에서 분기치는게 현재 공수 상 적절하다고 봤읍니다,,,

📝 참고사항

📚 기타

Summary by CodeRabbit

  • New Features

    • 라이브 스터디와 과제 스터디 생성 로직이 명확하게 구분되었습니다.
    • 관리 API 문서가 업데이트되어 과제 스터디 생성 시 라이브 관련 필드가 null이어야 함을 명시합니다.
    • 부적절한 스터디 타입 선택 시 적절한 오류 메시지가 제공됩니다.
  • Refactor

    • 스터디 및 세션 관련 기능의 명칭과 분기 처리가 개선되어 일관성이 향상되었습니다.
  • Tests

    • 스터디 생성 시 라이브 세션 필드와 출석번호 처리에 대한 검증 테스트가 추가 및 수정되었습니다.

@uwoobeat uwoobeat requested a review from a team as a code owner February 6, 2025 12:04
Copy link

coderabbitai bot commented Feb 6, 2025

Walkthrough

이번 PR은 스터디 생성 로직에 분기 처리를 도입하여 라이브 스터디와 과제 스터디의 생성 방식을 구분합니다. StudyTypeisLive() 메소드를 추가해 해당 타입이 라이브인지 판별하며, 이에 따라 StudyFactory 및 관련 도메인 클래스(StudyV2, StudySessionV2)에서 별도의 라이브/과제 스터디 생성 메소드를 호출합니다. 또한, API 설명 업데이트와 관련 필드의 null 가능성 변경, 새로운 에러 코드 추가, 그리고 이를 검증하는 테스트 케이스가 포함되었습니다.

Changes

파일 변경 사항
src/.../study/domain/StudyType.java isLive() 메소드 추가
src/.../studyv2/api/AdminStudyControllerV2.java API 설명 업데이트 (과제 스터디의 라이브 세션 필드는 null이어야 함 명시)
src/.../studyv2/domain/StudyFactory.java, src/.../studyv2/domain/StudyV2.java, src/.../studyv2/domain/StudySessionV2.java 생성 로직 분기 처리: 라이브(→ createLive, createEmptyForLive)와 과제 스터디(→ createAssignment, createEmptyForAssignment) 메소드 추가 및 변경
src/.../studyv2/dto/request/StudyCreateRequest.java dayOfWeek, startTime, endTime 필드에 @Nullable 어노테이션 추가
src/.../global/exception/ErrorCode.java 새로운 에러 코드 STUDY_NOT_CREATABLE_NOT_LIVE 추가
src/.../studyv2/domain/StudyFactoryTest.java 과제 및 라이브 스터디 생성 행위 검증을 위한 테스트 추가, 기존 라이브 스터디 테스트 메소드 명 변경

Sequence Diagram(s)

sequenceDiagram
    participant C as Controller
    participant F as StudyFactory
    participant V as StudyV2
    participant S as StudySessionV2

    C->>F: create(studyType, ...)
    F->>F: studyType.isLive()?
    alt 라이브 스터디
        F->>V: createLive(...)
        V->>S: createEmptyForLive(...)
    else 과제 스터디
        F->>V: createAssignment(...)
        V->>S: createEmptyForAssignment(...)
    end
Loading

Assessment against linked issues

Objective Addressed Explanation
과제 스터디 생성 로직 구현 (#866)

Possibly related PRs

Suggested labels

✨ feature, ⚓ Domain: Study

Suggested reviewers

  • Sangwook02
  • kckc0608

Poem

나는 귀여운 토끼, 코드 숲을 달리며,
라이브와 과제 구분해, 별처럼 빛나는 날개를 펴네.
생성 로직이 춤추고, 에러도 새롭게 노래해,
각 테스트가 속삭이는, 성공의 기쁨을 전해줘.
코딩의 마법 속에서, 우리는 함께 꿈을 그리네! 🐰✨

Tip

🌐 Web search-backed reviews and chat
  • We have enabled web search-based reviews and chat for all users. This feature allows CodeRabbit to access the latest documentation and information on the web.
  • You can disable this feature by setting web_search: false in the knowledge_base settings.
  • Please share any feedback in the Discord discussion.
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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.

@uwoobeat uwoobeat changed the title feat: 과제 스터디 생성 API 구현 feat: 과제 스터디 생성 로직 구현 Feb 6, 2025
Copy link

github-actions bot commented Feb 6, 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

@uwoobeat uwoobeat self-assigned this Feb 6, 2025
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: 1

🧹 Nitpick comments (4)
src/main/java/com/gdschongik/gdsc/domain/studyv2/domain/StudyFactory.java (2)

64-99: 메소드가 다소 길어 가독성이 떨어집니다.

매개변수가 많아 메소드가 길어졌습니다. 빌더 패턴을 사용하여 가독성을 개선할 수 있습니다.

다음과 같은 리팩토링을 제안합니다:

+ @Builder
+ public static class LiveStudyParams {
+     private StudyType type;
+     private String title;
+     private String description;
+     // ... other fields
+ }

- private StudyV2 createLive(StudyType type, String title, /* other params */) {
+ private StudyV2 createLive(LiveStudyParams params) {
      StudyV2 study = StudyV2.createLive(
-             type,
-             title,
+             params.getType(),
+             params.getTitle(),
              // ... other fields
      );
      // ... rest of the method
 }

101-125: Assignment 생성 메소드도 동일한 개선이 필요합니다.

createAssignment 메소드도 매개변수가 많아 가독성이 떨어집니다.

위와 동일한 방식으로 빌더 패턴을 적용하여 가독성을 개선할 수 있습니다.

src/main/java/com/gdschongik/gdsc/domain/studyv2/domain/StudyV2.java (1)

169-194: 과제 스터디 생성 메소드가 잘 구현되어 있습니다.

과제 스터디 생성 시 필요한 필드만 받아서 처리하는 것이 좋습니다. 다만, 파라미터가 많아 가독성이 떨어질 수 있습니다.

다음과 같이 빌더 패턴을 위한 DTO를 도입하는 것을 고려해보세요:

public static class AssignmentStudyCreateDto {
    private final String title;
    private final String description;
    // ... 나머지 필드들
    
    @Builder
    public AssignmentStudyCreateDto(/* 필드들 */) {
        this.title = title;
        // ... 필드 초기화
    }
}

public static StudyV2 createAssignment(AssignmentStudyCreateDto dto) {
    return StudyV2.builder()
            .type(StudyType.ASSIGNMENT)
            .title(dto.getTitle())
            // ... 나머지 필드 설정
            .build();
}
src/main/java/com/gdschongik/gdsc/domain/studyv2/dto/request/StudyCreateRequest.java (1)

25-27: 라이브 세션 필드들의 VO 분리 제안이 적절합니다.

TODO 코멘트에서 제안된 대로 라이브 세션 관련 필드들(dayOfWeek, startTime, endTime)을 별도의 VO로 분리하면 다음과 같은 이점이 있습니다:

  • 관련 필드들의 응집도 향상
  • 유효성 검증 로직의 캡슐화
  • 코드의 가독성 및 유지보수성 향상

LiveSessionInfo VO 구현에 대한 예시 코드를 제공해드릴까요?

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 258fa76 and eda60ed.

📒 Files selected for processing (8)
  • src/main/java/com/gdschongik/gdsc/domain/study/domain/StudyType.java (1 hunks)
  • src/main/java/com/gdschongik/gdsc/domain/studyv2/api/AdminStudyControllerV2.java (1 hunks)
  • src/main/java/com/gdschongik/gdsc/domain/studyv2/domain/StudyFactory.java (2 hunks)
  • src/main/java/com/gdschongik/gdsc/domain/studyv2/domain/StudySessionV2.java (1 hunks)
  • src/main/java/com/gdschongik/gdsc/domain/studyv2/domain/StudyV2.java (4 hunks)
  • src/main/java/com/gdschongik/gdsc/domain/studyv2/dto/request/StudyCreateRequest.java (2 hunks)
  • src/main/java/com/gdschongik/gdsc/global/exception/ErrorCode.java (1 hunks)
  • src/test/java/com/gdschongik/gdsc/domain/studyv2/domain/StudyFactoryTest.java (3 hunks)
🔇 Additional comments (12)
src/main/java/com/gdschongik/gdsc/domain/study/domain/StudyType.java (1)

15-17: 구현이 명확하고 깔끔합니다!

isLive() 메소드가 명확한 의도를 가지고 있으며, enum 비교를 적절하게 사용하고 있습니다.

src/main/java/com/gdschongik/gdsc/domain/studyv2/api/AdminStudyControllerV2.java (1)

23-23: API 문서화가 개선되었습니다!

과제 스터디의 필드 요구사항이 명확하게 문서화되어 있어 API 사용자가 이해하기 쉽습니다.

src/main/java/com/gdschongik/gdsc/domain/studyv2/domain/StudySessionV2.java (1)

95-101: 🛠️ Refactor suggestion

메소드 이름이 명확해졌으나 검증 로직이 필요합니다.

필수 필드에 대한 유효성 검사가 누락되어 있습니다. position과 studyV2가 null이 아님을 보장하는 검증이 필요합니다.

다음과 같이 검증 로직을 추가하는 것을 제안합니다:

 public static void createEmptyForLive(Integer position, String lessonAttendanceNumber, StudyV2 studyV2) {
+    Objects.requireNonNull(position, "position must not be null");
+    Objects.requireNonNull(studyV2, "studyV2 must not be null");
     StudySessionV2.builder()
             .position(position)
             .lessonAttendanceNumber(lessonAttendanceNumber)
             .studyV2(studyV2)
             .build();
 }
src/main/java/com/gdschongik/gdsc/domain/studyv2/domain/StudyFactory.java (1)

34-62: 분기 처리가 명확합니다!

타입에 따른 분기 처리가 명확하고 이해하기 쉽습니다.

src/test/java/com/gdschongik/gdsc/domain/studyv2/domain/StudyFactoryTest.java (3)

51-77: 테스트 케이스가 과제 스터디의 필드 검증을 잘 수행하고 있습니다.

과제 스터디 생성 시 라이브 세션 관련 필드(요일, 시작/종료 시간)가 null로 설정되는지 확인하는 테스트가 잘 구현되어 있습니다.


109-110: 메소드 이름이 명확하게 변경되었습니다.

테스트 메소드 이름이 '라이브 스터디'에 특화된 것임을 명확히 하도록 변경된 것이 좋습니다.


138-164: 과제 스터디의 출석 번호 검증이 잘 구현되어 있습니다.

과제 스터디의 세션에는 출석 번호가 생성되지 않아야 한다는 요구사항을 잘 검증하고 있습니다.

src/main/java/com/gdschongik/gdsc/domain/studyv2/domain/StudyV2.java (2)

128-161: 라이브 스터디 생성 로직이 잘 구현되어 있습니다.

타입 검증을 통해 라이브 스터디 생성을 안전하게 처리하고 있습니다.


163-167: 타입 검증 로직이 명확합니다.

라이브 스터디 타입이 아닌 경우 적절한 예외를 발생시키는 검증 로직이 잘 구현되어 있습니다.

src/main/java/com/gdschongik/gdsc/global/exception/ErrorCode.java (1)

110-110: 에러 코드가 명확하게 정의되어 있습니다.

스터디 타입 검증 실패에 대한 에러 메시지가 명확하고 적절한 HTTP 상태 코드가 사용되었습니다.

src/main/java/com/gdschongik/gdsc/domain/studyv2/dto/request/StudyCreateRequest.java (2)

6-6: jakarta.annotation.Nullable 임포트 추가가 적절합니다.

Jakarta EE의 @nullable 어노테이션을 사용하여 필드의 null 허용 여부를 명시적으로 표현한 것이 좋습니다.


20-22: 라이브 세션 관련 필드들의 Nullable 처리가 적절합니다.

과제 스터디의 경우 라이브 세션 정보가 필요하지 않으므로, dayOfWeek, startTime, endTime 필드를 @nullable로 처리한 것이 적절합니다. 하지만 이러한 필드들의 유효성 검증을 위한 추가적인 로직이 필요할 수 있습니다.

라이브 스터디의 경우 이 필드들이 반드시 존재해야 하는지 검증하는 로직이 있는지 확인이 필요합니다:

Comment on lines +103 to +105
public static void createEmptyForAssignment(Integer position, StudyV2 studyV2) {
StudySessionV2.builder().position(position).studyV2(studyV2).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

동일한 검증 로직이 필요합니다.

createEmptyForAssignment 메소드도 필수 필드 검증이 필요합니다.

다음과 같이 검증 로직을 추가하는 것을 제안합니다:

 public static void createEmptyForAssignment(Integer position, StudyV2 studyV2) {
+    Objects.requireNonNull(position, "position must not be null");
+    Objects.requireNonNull(studyV2, "studyV2 must not be null");
     StudySessionV2.builder().position(position).studyV2(studyV2).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 void createEmptyForAssignment(Integer position, StudyV2 studyV2) {
StudySessionV2.builder().position(position).studyV2(studyV2).build();
}
public static void createEmptyForAssignment(Integer position, StudyV2 studyV2) {
Objects.requireNonNull(position, "position must not be null");
Objects.requireNonNull(studyV2, "studyV2 must not be null");
StudySessionV2.builder().position(position).studyV2(studyV2).build();
}

Copy link
Member

@Sangwook02 Sangwook02 left a comment

Choose a reason for hiding this comment

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

lgtm

@uwoobeat uwoobeat merged commit 613ba13 into develop Feb 8, 2025
1 check passed
@uwoobeat uwoobeat deleted the feature/866-create-assignment-study-api branch February 8, 2025 09:40
@uwoobeat uwoobeat restored the feature/866-create-assignment-study-api branch February 8, 2025 09:41
@uwoobeat uwoobeat deleted the feature/866-create-assignment-study-api branch February 8, 2025 09:41
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.

✨ 과제 스터디 생성 로직 구현
2 participants