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: 쿠폰 도메인의 스터디 레퍼런스 변경 #905

Merged
merged 2 commits into from
Feb 21, 2025

Conversation

Sangwook02
Copy link
Member

@Sangwook02 Sangwook02 commented Feb 19, 2025

🌱 관련 이슈

📌 작업 내용 및 특이사항

  • Coupon에서 StudyStudyV2로 변경했습니다.

📝 참고사항

  • 상용 db에 작업 필요

📚 기타

Summary by CodeRabbit

  • Refactor
    • 쿠폰 발급 및 처리 로직이 최신 학습 모듈에 맞춰 업데이트되어, 시스템의 안정성과 유지보수성이 향상되었습니다.
  • Tests
    • 쿠폰 관련 테스트와 통합 테스트가 최신 학습 모델에 맞춰 수정되었습니다.

@Sangwook02 Sangwook02 requested a review from a team as a code owner February 19, 2025 09:59
Copy link

coderabbitai bot commented Feb 19, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

이번 PR은 기존의 Study 및 StudyHistory 도메인 대신 새로운 StudyV2 및 StudyHistoryV2를 사용하도록 쿠폰 관련 서비스, DAO, 도메인 및 유틸리티 클래스를 리팩토링합니다. 메서드 시그니처, 필드 타입, 임포트 문 등이 전면 수정되었으며, 이에 맞추어 테스트 코드와 헬퍼 클래스도 업데이트되었습니다.

Changes

File(s) Change Summary
src/main/java/com/gdschongik/gdsc/domain/coupon/application/CouponService.java
src/main/java/com/gdschongik/gdsc/domain/coupon/dao/CouponRepository.java
src/main/java/com/gdschongik/gdsc/domain/coupon/dao/IssuedCouponCustomRepository(.java)
src/main/java/com/gdschongik/gdsc/domain/coupon/domain/Coupon.java
src/main/java/com/gdschongik/gdsc/domain/coupon/util/CouponNameUtil.java
Study, StudyHistory 관련 타입과 임포트를 StudyV2, StudyHistoryV2로 전환. 각 메서드 및 필드의 타입 시그니처 수정과 함께 @joincolumn, 학기 관련 로직 등 연관 어노테이션 및 유틸 메서드도 함께 업데이트됨.
src/test/java/com/gdschongik/gdsc/domain/coupon/application/CouponServiceTest.java
src/test/java/com/gdschongik/gdsc/domain/coupon/util/CouponNameUtilTest.java
src/test/java/com/gdschongik/gdsc/helper/FixtureHelper.java
src/test/java/com/gdschongik/gdsc/helper/IntegrationTest.java
테스트 케이스와 헬퍼 메서드에서 Study, StudyHistory 대신 StudyV2, StudyHistoryV2를 사용하도록 수정. 이에 따라, 관련 메서드 시그니처 및 인스턴스 생성 방식 등이 변경됨.

Sequence Diagram(s)

sequenceDiagram
  participant CS as CouponService
  participant SR as StudyV2Repository
  participant CR as CouponRepository

  CS->>SR: StudyV2 데이터 조회 요청
  SR-->>CS: StudyV2 데이터 반환
  CS->>CR: StudyV2 기반 쿠폰 조회/생성 요청
  CR-->>CS: 쿠폰 조회 결과/생성 완료 응답
Loading

Possibly related PRs

Suggested labels

♻️ refactor

Suggested reviewers

  • kckc0608
  • uwoobeat

Poem

깡총깡충 나는 토끼,
코드 숲을 뛰어넘으며,
Study에서 StudyV2로 길을 바꾸고,
한 줄 한 줄 정성스레 다듬었네,
모두의 미소 속에 즐거움이 피어나네 🐰✨
작은 발자국 따라 행복을 노래해!


📜 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 3e000dd and a3da373.

📒 Files selected for processing (1)
  • src/test/java/com/gdschongik/gdsc/domain/coupon/util/CouponNameUtilTest.java (2 hunks)
✨ 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.

@Sangwook02 Sangwook02 added the ✨ feature 새로운 기능 추가 및 수정 label Feb 19, 2025
@Sangwook02 Sangwook02 self-assigned this Feb 19, 2025
Copy link

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: 0

🔭 Outside diff range comments (1)
src/main/java/com/gdschongik/gdsc/domain/coupon/application/CouponService.java (1)

107-125: 🛠️ Refactor suggestion

스터디 이력 검증 로직 추가 필요

studyHistories가 비어있는 경우나 서로 다른 스터디의 이력이 포함된 경우에 대한 검증이 필요합니다.

 @Transactional
 public void createAndIssueCouponByStudyHistories(List<Long> studyHistoryIds) {
     List<StudyHistoryV2> studyHistories = studyHistoryRepository.findAllById(studyHistoryIds);
+    if (studyHistories.isEmpty()) {
+        throw new CustomException(STUDY_HISTORY_NOT_FOUND);
+    }
+    
+    StudyV2 study = studyHistories.get(0).getStudy();
+    boolean hasDifferentStudy = studyHistories.stream()
+            .map(StudyHistoryV2::getStudy)
+            .anyMatch(s -> !s.equals(study));
+    if (hasDifferentStudy) {
+        throw new CustomException(INVALID_STUDY_HISTORIES);
+    }
+
     List<Long> studentIds = studyHistories.stream()
             .map(studyHistory -> studyHistory.getStudent().getId())
             .toList();
     List<Member> students = memberRepository.findAllById(studentIds);
-    StudyV2 study = studyHistories.get(0).getStudy();
🧹 Nitpick comments (4)
src/main/java/com/gdschongik/gdsc/domain/coupon/domain/Coupon.java (2)

29-29: 테이블 제약조건 변경 확인 필요

데이터베이스 마이그레이션 작업이 필요할 수 있습니다. 기존 study_id를 사용하는 제약조건에서 study_v2_id로 변경되었습니다.

프로덕션 데이터베이스 마이그레이션 계획을 수립하고 실행해야 합니다.


49-51: 연관관계 매핑 변경 확인

StudyV2로의 연관관계 매핑이 올바르게 설정되었습니다. 단, 기존 Study 엔티티와의 데이터 마이그레이션 계획이 필요합니다.

기존 Study 엔티티와 연결된 쿠폰 데이터의 마이그레이션 전략을 수립해야 합니다.

src/main/java/com/gdschongik/gdsc/domain/coupon/application/CouponService.java (1)

130-130: 할인 금액 상수화 필요

이전 PR #847의 피드백에 따라, 스터디 수료 쿠폰의 할인 금액(Money.FIVE_THOUSAND)을 상수로 분리하는 것이 좋습니다.

+private static final Money STUDY_COMPLETION_DISCOUNT_AMOUNT = Money.FIVE_THOUSAND;

 private Coupon findOrCreate(CouponType couponType, StudyV2 study) {
     return couponRepository.findByCouponTypeAndStudy(couponType, study).orElseGet(() -> {
         String couponName = couponNameUtil.generateStudyCompletionCouponName(study);
-        Coupon coupon = Coupon.createAutomatic(couponName, Money.FIVE_THOUSAND, couponType, study);
+        Coupon coupon = Coupon.createAutomatic(couponName, STUDY_COMPLETION_DISCOUNT_AMOUNT, couponType, study);
         return couponRepository.save(coupon);
     });
 }
src/test/java/com/gdschongik/gdsc/helper/IntegrationTest.java (1)

327-330: 메서드 문서화가 필요합니다!

createStudyHistory 메서드가 잘 구현되었지만, 메서드의 목적과 사용법을 설명하는 JavaDoc 문서화가 추가되면 좋을 것 같습니다.

다음과 같이 문서화를 추가해보세요:

+    /**
+     * StudyV2와 연관된 StudyHistoryV2를 생성합니다.
+     *
+     * @param member 스터디 참여 멤버
+     * @param study 참여할 스터디
+     * @return 생성된 스터디 히스토리
+     */
     protected StudyHistoryV2 createStudyHistory(Member member, StudyV2 study) {
         StudyHistoryV2 studyHistory = StudyHistoryV2.create(member, study);
         return studyHistoryV2Repository.save(studyHistory);
     }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 848076b and 3e000dd.

📒 Files selected for processing (10)
  • src/main/java/com/gdschongik/gdsc/domain/coupon/application/CouponService.java (5 hunks)
  • src/main/java/com/gdschongik/gdsc/domain/coupon/dao/CouponRepository.java (1 hunks)
  • src/main/java/com/gdschongik/gdsc/domain/coupon/dao/IssuedCouponCustomRepository.java (2 hunks)
  • src/main/java/com/gdschongik/gdsc/domain/coupon/dao/IssuedCouponCustomRepositoryImpl.java (2 hunks)
  • src/main/java/com/gdschongik/gdsc/domain/coupon/domain/Coupon.java (4 hunks)
  • src/main/java/com/gdschongik/gdsc/domain/coupon/util/CouponNameUtil.java (2 hunks)
  • src/test/java/com/gdschongik/gdsc/domain/coupon/application/CouponServiceTest.java (5 hunks)
  • src/test/java/com/gdschongik/gdsc/domain/coupon/util/CouponNameUtilTest.java (2 hunks)
  • src/test/java/com/gdschongik/gdsc/helper/FixtureHelper.java (1 hunks)
  • src/test/java/com/gdschongik/gdsc/helper/IntegrationTest.java (4 hunks)
🧰 Additional context used
🧠 Learnings (2)
src/test/java/com/gdschongik/gdsc/helper/IntegrationTest.java (1)
Learnt from: uwoobeat
PR: GDSC-Hongik/gdsc-server#889
File: src/main/java/com/gdschongik/gdsc/domain/studyv2/api/MentorStudyControllerV2.java:35-39
Timestamp: 2025-02-12T11:11:19.196Z
Learning: In the GDSC server project's V2 domain, following DDD principles, StudyV2 is an aggregate root and StudySession is its child entity. Therefore, StudySession should only be accessed through StudyV2 aggregate root using StudyV2Repository, not directly via a separate StudySessionRepository.
src/main/java/com/gdschongik/gdsc/domain/coupon/application/CouponService.java (1)
Learnt from: kckc0608
PR: GDSC-Hongik/gdsc-server#847
File: src/main/java/com/gdschongik/gdsc/domain/coupon/application/CouponService.java:115-115
Timestamp: 2025-01-22T12:27:00.185Z
Learning: Discount amounts in the coupon domain should be managed as constants rather than hardcoded values, especially for specific coupon types like study completion coupons.
🔇 Additional comments (12)
src/main/java/com/gdschongik/gdsc/domain/coupon/dao/CouponRepository.java (1)

5-5: Study에서 StudyV2로의 전환이 올바르게 이루어졌습니다!

인터페이스의 메서드 시그니처와 임포트문이 새로운 StudyV2 도메인 모델과 일관되게 업데이트되었습니다.

Also applies to: 10-10

src/main/java/com/gdschongik/gdsc/domain/coupon/util/CouponNameUtil.java (1)

13-17: 리팩토링으로 코드가 더 명확해졌습니다!

StudyV2로의 전환과 함께 다음과 같은 개선사항이 있습니다:

  • Semester 객체를 명시적으로 분리하여 가독성이 향상되었습니다
  • SemesterFormatter 사용이 더 명확해졌습니다
src/main/java/com/gdschongik/gdsc/domain/coupon/dao/IssuedCouponCustomRepository.java (1)

7-7: StudyV2 도메인으로의 전환이 정확하게 이루어졌습니다!

커스텀 리포지토리 인터페이스의 메서드 시그니처와 임포트문이 새로운 도메인 모델과 일관되게 변경되었습니다.

Also applies to: 16-16

src/test/java/com/gdschongik/gdsc/domain/coupon/util/CouponNameUtilTest.java (1)

21-34: Discord 관련 설정이 추가된 것을 확인해주세요.

StudyV2로의 전환 과정에서 Discord 통합을 위한 새로운 매개변수들이 추가되었습니다:

  • STUDY_DISCORD_CHANNEL_ID
  • STUDY_DISCORD_ROLE_ID

이러한 변경사항들이 실제 운영 환경에서 예상대로 동작하는지 확인이 필요합니다.

src/main/java/com/gdschongik/gdsc/domain/coupon/dao/IssuedCouponCustomRepositoryImpl.java (1)

41-51:

❓ Verification inconclusive

메서드 시그니처 변경이 쿼리 로직에 미치는 영향 확인 필요

쿼리 로직이 StudyV2 엔티티와 정상적으로 동작하는지 확인이 필요합니다. 특히 coupon.study.eq(study) 부분에서 StudyV2의 연관관계가 올바르게 매핑되어 있는지 검증해야 합니다.


🏁 Script executed:

#!/bin/bash
# StudyV2와 Coupon 간의 연관관계 매핑 확인
ast-grep --pattern 'class Coupon {
  $$$
  @ManyToOne
  $$$
  private StudyV2 study;
  $$$
}'

Length of output: 95


쿼리 로직 및 StudyV2 매핑 수동 검증 필요

  • src/main/java/com/gdschongik/gdsc/domain/coupon/dao/IssuedCouponCustomRepositoryImpl.java의 41-51번 라인에서 StudyV2로 변경된 파라미터를 사용하는 쿼리 로직(coupon.study.eq(study))이 의도한 대로 동작하는지 확인해야 합니다.
  • 자동 검증 스크립트 실행 결과(Coupon 엔티티에 StudyV2 연관 매핑 관련)가 출력되지 않아, Coupon 엔티티 내에서 private StudyV2 study; 어노테이션(@ManyToOne 등) 매핑이 올바르게 적용되었는지 수동으로 확인해 주시기 바랍니다.
src/test/java/com/gdschongik/gdsc/helper/FixtureHelper.java (1)

92-95: 테스트 헬퍼 메서드가 적절히 업데이트되었습니다

StudyV2를 사용하도록 변경된 createAndIssue 메서드가 올바르게 구현되었습니다.

src/main/java/com/gdschongik/gdsc/domain/coupon/application/CouponService.java (1)

43-49: 의존성이 적절히 업데이트되었습니다

StudyV2 관련 저장소들로 올바르게 변경되었습니다.

src/test/java/com/gdschongik/gdsc/domain/coupon/application/CouponServiceTest.java (3)

19-21: 임포트 변경이 적절합니다!

Study 도메인에서 StudyV2 도메인으로의 마이그레이션을 위한 임포트 변경이 올바르게 이루어졌습니다.


217-219: 테스트 메서드의 타입 변경이 적절합니다!

Study와 StudyHistory에서 StudyV2와 StudyHistoryV2로의 타입 변경이 일관되게 적용되었으며, 테스트 로직은 그대로 유지되었습니다.


236-260: 전체 테스트 커버리지가 잘 유지되었습니다!

모든 테스트 메서드에서 StudyV2와 StudyHistoryV2로의 변경이 일관되게 적용되었으며, 기존의 테스트 커버리지가 잘 유지되고 있습니다.

Also applies to: 279-282

src/test/java/com/gdschongik/gdsc/helper/IntegrationTest.java (2)

109-111: StudyHistoryV2Repository 주입이 적절합니다!

StudyV2 도메인으로의 마이그레이션을 위해 필요한 StudyHistoryV2Repository가 올바르게 주입되었습니다.


239-244: createAndIssue 메서드의 파라미터 타입 변경이 적절합니다!

Study에서 StudyV2로의 파라미터 타입 변경이 일관되게 적용되었으며, 메서드의 핵심 로직은 그대로 유지되었습니다.

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

하나만 봐주세요

@@ -20,18 +18,20 @@ class CouponNameUtilTest {
void 스터디_수료_쿠폰_이름이_생성된다() {
// given
Member mentor = fixtureHelper.createMentor(1L);
Study study = Study.create(
StudyV2 study = StudyV2.createLive(
Copy link
Member

Choose a reason for hiding this comment

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

픽스쳐 유틸을 쓰면 좋을듯요

Copy link
Member Author

Choose a reason for hiding this comment

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

픽스쳐 헬퍼에 있는 메서드는 스터디 제목을 주입할 수 없어서 StudyV2에 있는 메서드를 직접 갖다 썼었어요.
assert문을 수정하고 픽스쳐 헬퍼 사용하도록 수정했습니다~

Copy link

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 0839082 into develop Feb 21, 2025
1 of 2 checks passed
@Sangwook02 Sangwook02 deleted the feature/898-coupon-study-reference branch February 21, 2025 03:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ feature 새로운 기능 추가 및 수정
Projects
None yet
Development

Successfully merging this pull request may close these issues.

✨ 쿠폰 도메인의 스터디 레퍼런스를 V2로 변경
2 participants