Skip to content

[DDING-125-2] 섹션 여러 개일 경우 사용자 폼지 조회 수정#296

Merged
Seooooo24 merged 3 commits intodevelopfrom
fix/DDING-125-2
Mar 12, 2025
Merged

[DDING-125-2] 섹션 여러 개일 경우 사용자 폼지 조회 수정#296
Seooooo24 merged 3 commits intodevelopfrom
fix/DDING-125-2

Conversation

@Seooooo24
Copy link
Copy Markdown
Collaborator

@Seooooo24 Seooooo24 commented Mar 9, 2025

🚀 작업 내용

섹션 여러 개일 경우 사용자 폼지 조회 기능 수정하였습니다.

🤔 고민했던 내용

💬 리뷰 중점사항

Summary by CodeRabbit

  • Refactor
    • 폼 필드 섹션 조회 로직이 단순화되어, 기본 섹션 값 대신 명시적 섹션을 기준으로 처리됩니다.
    • 불필요한 기본 섹션 상수와 관련 조건이 제거되어, 폼 구성 요소의 처리 과정이 한층 명확해졌습니다.
  • Tests
    • 테스트 클래스가 재구성되어 명확하고 유지보수하기 쉬운 방식으로 테스트가 작성되었습니다.
    • 새로운 테스트 메소드가 추가되어 특정 섹션의 폼 필드를 검증합니다.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 9, 2025

Walkthrough

이번 변경사항은 두 개의 파일에 걸쳐 메서드 시그니처와 상수 사용을 단순화하는 리팩토링 작업입니다.
FormFieldRepository에서는 findAllByFormAndSection 메서드의 SQL 쿼리에서 :defaultSection 조건을 제거하고, 해당 파라미터를 메서드 시그니처에서 제외했습니다.
동시에, GeneralFormFieldService에서는 FORM_DEFAULT_SECTION 상수를 삭제하고, getAllByFormAndSection 메서드 호출 시 기본 섹션을 사용하지 않도록 수정하였습니다.

Changes

파일 경로 변경 내용
src/main/java/ddingdong/ddingdongBE/domain/form/repository/…/FormFieldRepository.java findAllByFormAndSection 메서드에서 :defaultSection 조건 제거 및 파라미터 목록에서 defaultSection 삭제
src/main/java/ddingdong/ddingdongBE/domain/form/service/…/GeneralFormFieldService.java FORM_DEFAULT_SECTION 상수 제거 및 getAllByFormAndSection 메서드 호출에서 기본 섹션 관련 인자 삭제
src/test/java/ddingdong/ddingdongBE/domain/form/service/…/FacadeUserFormServiceImplTest.java 테스트 클래스 전면 수정, FixtureMonkey 사용 제거 및 빌더 패턴을 통한 엔티티 생성 방식으로 변경, 새로운 테스트 메서드 추가

Possibly related PRs

Suggested labels

✨기능, D-1

Suggested reviewers

  • wonjunYou
  • 5uhwann
  • KoSeonJe
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
  • @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.

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.

@Seooooo24 Seooooo24 self-assigned this Mar 9, 2025
@Seooooo24 Seooooo24 added the D-3 label Mar 9, 2025
Copy link
Copy Markdown
Collaborator

@KoSeonJe KoSeonJe left a comment

Choose a reason for hiding this comment

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

확인했습니다~ 고생하셨어요

Copy link
Copy Markdown
Collaborator

@KoSeonJe KoSeonJe left a comment

Choose a reason for hiding this comment

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

테스트 코드 한번 작성해보면 좋을 것 같아요..!
MonkeyFixture를 연관관계 주입되는 엔터티에만 안쓰면 에러안나드라구요!

@Seooooo24
Copy link
Copy Markdown
Collaborator Author

테스트 코드 한번 작성해보면 좋을 것 같아요..! MonkeyFixture를 연관관계 주입되는 엔터티에만 안쓰면 에러안나드라구요!

넵 알겠습니다! 작성해보겠습니다!

@github-actions github-actions bot added D-2 and removed D-3 labels Mar 10, 2025
Copy link
Copy Markdown

@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

🧹 Nitpick comments (1)
src/test/java/ddingdong/ddingdongBE/domain/form/service/FacadeUserFormServiceImplTest.java (1)

93-107: 폼 조회 테스트가 정확하게 구현되었습니다.

특정 섹션의 폼 필드를 조회하는 기능이 잘 구현되어 있습니다. 다만, 테스트 커버리지를 향상시킬 수 있는 몇 가지 제안사항이 있습니다:

  1. 현재는 첫 번째 섹션에 대한 테스트만 있습니다. 두 번째 섹션에 대한 테스트도 추가하면 좋을 것 같습니다.
  2. 존재하지 않는 섹션을 요청했을 때의 처리(예외 발생 또는 빈 결과 반환)에 대한 테스트 케이스를 추가하면 좋을 것 같습니다.
  3. 현재 테스트는 첫 번째 폼 필드만 확인하고 있는데, 모든 폼 필드가 올바르게 반환되는지 검증할 수 있습니다.
@DisplayName("다른 섹션 선택 시 해당 섹션의 폼 필드만 조회된다.")
@Test
void getFormWithDifferentSection() {
    // given
    FormField savedFormField1 = createFormField("질문1", 1, savedSections.get(0), savedForm);
    FormField savedFormField2 = createFormField("질문2", 2, savedSections.get(1), savedForm);

    String selectedSection = savedSections.get(1);

    // when
    UserFormQuery userFormQuery = facadeUserFormService.getUserForm(savedForm.getId(), selectedSection);

    // then
    assertThat(userFormQuery.formFields()).hasSize(1);
    assertThat(userFormQuery.formFields().get(0).id()).isEqualTo(savedFormField2.getId());
}

@DisplayName("존재하지 않는 섹션을 요청할 경우 빈 폼 필드 목록이 반환된다.")
@Test
void getFormWithNonExistingSection() {
    // given
    FormField savedFormField1 = createFormField("질문1", 1, savedSections.get(0), savedForm);
    FormField savedFormField2 = createFormField("질문2", 2, savedSections.get(1), savedForm);

    String nonExistingSection = "non-existing-section";

    // when
    UserFormQuery userFormQuery = facadeUserFormService.getUserForm(savedForm.getId(), nonExistingSection);

    // then
    assertThat(userFormQuery.formFields()).isEmpty();
}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5185d85 and e9c5a86.

📒 Files selected for processing (1)
  • src/test/java/ddingdong/ddingdongBE/domain/form/service/FacadeUserFormServiceImplTest.java (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Build and analyze
🔇 Additional comments (3)
src/test/java/ddingdong/ddingdongBE/domain/form/service/FacadeUserFormServiceImplTest.java (3)

45-79: 데이터 설정 방식이 명확하고 가독성이 좋습니다.

테스트 데이터 설정 코드가 명확하고 이해하기 쉽게 구성되어 있습니다. FixtureMonkey 대신 Builder 패턴을 사용하여 엔티티를 명시적으로 생성한 것이 좋습니다.

다만, 몇 가지 개선할 수 있는 부분이 있습니다:

  1. 엔티티 ID를 명시적으로 설정(1L)하는 것보다 데이터베이스의 자동 생성 기능을 활용하는 것이 더 자연스러울 수 있습니다.
  2. Club 엔티티에서 여러 필드를 명시적으로 null로 설정하는 것보다 빈 컬렉션이나 기본값을 사용하는 것이 좋습니다.
-    User user = User.builder()
-            .id(1L)
-            .role(Role.CLUB)
-            .build();
+    User user = User.builder()
+            .role(Role.CLUB)
+            .build();

-    Club club = Club.builder()
-            .id(1L)
-            .user(savedUser)
-            .score(null)
-            .clubMembers(null)
-            .deletedAt(null)
-            .build();
+    Club club = Club.builder()
+            .user(savedUser)
+            .build();

81-91: 테스트 코드가 간결하고 목적이 명확합니다.

Given-When-Then 구조가 명확하고, 섹션 조회 기능을 잘 검증하고 있습니다.


109-119: 폼 필드 생성 헬퍼 메서드가 잘 구현되었습니다.

폼 필드를 생성하는 헬퍼 메서드가 테스트 코드를 간결하게 만들어주고 있습니다.

@sonarqubecloud
Copy link
Copy Markdown

@Seooooo24 Seooooo24 merged commit 62024ba into develop Mar 12, 2025
4 checks passed
@Seooooo24 Seooooo24 deleted the fix/DDING-125-2 branch March 12, 2025 16:26
KoSeonJe pushed a commit that referenced this pull request Apr 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants