Skip to content

[DDING-125-1] 섹션 여러 개일 경우 폼지 생성 수정#295

Merged
Seooooo24 merged 5 commits intodevelopfrom
fix/DDING-125
Mar 13, 2025
Merged

[DDING-125-1] 섹션 여러 개일 경우 폼지 생성 수정#295
Seooooo24 merged 5 commits intodevelopfrom
fix/DDING-125

Conversation

@Seooooo24
Copy link
Copy Markdown
Collaborator

@Seooooo24 Seooooo24 commented Mar 9, 2025

🚀 작업 내용

섹션 여러 개일 경우 폼지 생성 기능 수정하였습니다.
form의 sections 사이즈가 1보다 클 경우, 아닐 경우로 분기하고 그에 따른 private 메서드 toCreateFormFieldsForMultipleSections, toCreateFormFieldsForSingleSection을 각각 만들었습니다.

유저 폼지 조회도 수정하도록 하겠습니다.

🤔 고민했던 내용

분기를 private 메서드 외부에서 할지 내부에서 할지, private 메서드는 어떤 기준으로 분리해야 할지 고민되었습니다.
달리 선택지가 없어서 그대로 두긴 했지만 메서드명이 너무 긴 것 같다는 생각이 들었습니다.
람다식 내부에 if-else문도 있고... 내부 로직이 조금 난잡하다는 생각도 들었습니다.
그리고 이 로직이 Facade에 있는 게 맞는지 잘 모르겠습니다. FormStatistics처럼 따로 빼는 건 좀 이상하겠죠..??

💬 리뷰 중점사항

Summary by CodeRabbit

  • New Features
    • 폼 생성 시 단일 섹션과 다중 섹션에 따라 항목 배분이 개선되어, 사용자 맞춤형 폼 구성이 보다 명확해졌습니다.
    • 신규 섹션 지정 기능이 추가되어, 공통 항목과 개별 섹션 항목이 효과적으로 구분됩니다.
    • 섹션 크기 비교 기능이 추가되어, 폼의 섹션 수에 따라 로직이 유연하게 조정됩니다.

@Seooooo24 Seooooo24 added 🎯리팩토링 리팩토링 및 고도화 이슈 D-3 labels Mar 9, 2025
@Seooooo24 Seooooo24 self-assigned this Mar 9, 2025
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 9, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

이 PR은 FacadeCentralFormServiceImpl 클래스의 toCreateFormFieldstoUpdateFormFields 메서드를 수정하여 폼 필드를 생성하고 업데이트하는 방식을 개선합니다. toCreateFormFields 메서드는 각 formField에 대해 generateFormFieldsBySection(savedForm)을 호출하여 새로운 리스트를 생성하고 반환합니다. toUpdateFormFields 메서드는 매핑 로직을 일관성을 위해 재구성하였으며, 두 메서드의 형식이 정리되었습니다. 또한, CreateFormFieldCommand 레코드에 toEntityWithSection 메서드가 추가되고, Form 클래스에 isLargerSectionThan 메서드가 추가되었습니다.

Changes

파일 변경 요약
src/main/java/ddingdong/ddingdongBE/domain/form/service/FacadeCentralFormServiceImpl.java toCreateFormFieldstoUpdateFormFields 메서드 형식 재구성
src/main/java/ddingdong/ddingdongBE/domain/form/service/dto/command/CreateFormCommand.java CreateFormFieldCommand 레코드에 toEntityWithSection 메서드 추가
src/main/java/ddingdong/ddingdongBE/domain/form/entity/Form.java isLargerSectionThan 메서드 추가
src/main/java/ddingdong/ddingdongBE/domain/form/entity/FormField.java generateFormFieldsBySection, expandCommonSectionFormField, copyWithSection 메서드 및 상수 추가

Possibly related PRs

Suggested labels

✨기능

Suggested reviewers

  • wonjunYou
  • 5uhwann
  • KoSeonJe

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.

📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d0af73a and cecb804.

📒 Files selected for processing (3)
  • src/main/java/ddingdong/ddingdongBE/domain/form/entity/Form.java (1 hunks)
  • src/main/java/ddingdong/ddingdongBE/domain/form/entity/FormField.java (3 hunks)
  • src/main/java/ddingdong/ddingdongBE/domain/form/service/FacadeCentralFormServiceImpl.java (1 hunks)
✨ 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 changed the title fix: 섹션 여러 개일 경우 폼지 생성 수정 [DDING-125-1] 섹션 여러 개일 경우 폼지 생성 수정 Mar 9, 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: 1

🧹 Nitpick comments (3)
src/main/java/ddingdong/ddingdongBE/domain/form/service/dto/command/CreateFormCommand.java (1)

46-56: 코드 중복을 줄일 수 있는 방법을 고려해보세요.

toEntityWithSection 메서드가 toEntity 메서드와 거의 동일한 구현을 가지고 있습니다. 두 메서드의 유일한 차이점은 section 값의 출처입니다. 코드 중복을 줄이기 위해 다음과 같은 접근 방식을 고려해볼 수 있습니다:

public FormField toEntity(Form savedForm) {
    return FormField.builder()
            .question(question)
            .fieldType(type)
            .options(options)
            .required(required)
            .fieldOrder(order)
            .section(section)
            .form(savedForm)
            .build();
}

public FormField toEntityWithSection(Form savedForm, String section) {
-   return FormField.builder()
-           .question(question)
-           .fieldType(type)
-           .options(options)
-           .required(required)
-           .fieldOrder(order)
-           .section(section)
-           .form(savedForm)
-           .build();
+   return FormField.builder()
+           .question(question)
+           .fieldType(type)
+           .options(options)
+           .required(required)
+           .fieldOrder(order)
+           .section(section)
+           .form(savedForm)
+           .build();
}

또는 private 헬퍼 메서드를 사용하여 빌더 로직을 공통화할 수도 있습니다.

src/main/java/ddingdong/ddingdongBE/domain/form/service/FacadeCentralFormServiceImpl.java (2)

269-282: 다중 섹션 처리 로직이 복잡하니 가독성을 개선해 보세요.

toCreateFormFieldsForMultipleSections 메서드에서 사용된 flatMap과 조건문을 포함하는 람다 표현식은 복잡성이 높습니다. 특히 "공통" 섹션을 다른 섹션들에 매핑하는 로직이 한 번에 이해하기 어렵습니다. 다음과 같이 메서드를 분리하여 가독성을 높일 수 있습니다:

private List<FormField> toCreateFormFieldsForMultipleSections(Form savedForm,
        List<CreateFormFieldCommand> createFormFieldCommands) {
    return createFormFieldCommands.stream()
-           .flatMap(formFieldCommand -> {
-               if (formFieldCommand.section().equals("공통")) {
-                   return savedForm.getSections().stream()
-                           .filter(section -> !section.equals("공통"))
-                           .map(section -> formFieldCommand.toEntityWithSection(savedForm, section));
-               } else {
-                   return Stream.of(formFieldCommand.toEntityWithSection(savedForm, formFieldCommand.section()));
-               }
-           })
+           .flatMap(formFieldCommand -> formFieldCommand.section().equals("공통") 
+                   ? createCommonSectionFields(savedForm, formFieldCommand)
+                   : Stream.of(formFieldCommand.toEntityWithSection(savedForm, formFieldCommand.section())))
            .toList();
}

+ private Stream<FormField> createCommonSectionFields(Form savedForm, CreateFormFieldCommand command) {
+     return savedForm.getSections().stream()
+             .filter(section -> !section.equals("공통"))
+             .map(section -> command.toEntityWithSection(savedForm, section));
+ }

또한 "공통" 같은 문자열 상수는 클래스 상수로 선언하여 사용하는 것이 좋습니다.


269-282: "공통" 같은 문자열 상수는 클래스 상수로 정의하는 것이 좋습니다.

"공통"이라는 문자열이 코드 내에서 하드코딩되어 있습니다. 이런 문자열 상수는 클래스 상수로 정의하여 사용하는 것이 좋습니다. 이렇게 하면 오타 방지 및 향후 변경 시 용이합니다.

+ private static final String COMMON_SECTION = "공통";

private List<FormField> toCreateFormFieldsForMultipleSections(Form savedForm,
        List<CreateFormFieldCommand> createFormFieldCommands) {
    return createFormFieldCommands.stream()
            .flatMap(formFieldCommand -> {
-                if (formFieldCommand.section().equals("공통")) {
+                if (formFieldCommand.section().equals(COMMON_SECTION)) {
                    return savedForm.getSections().stream()
-                            .filter(section -> !section.equals("공통"))
+                            .filter(section -> !section.equals(COMMON_SECTION))
                            .map(section -> formFieldCommand.toEntityWithSection(savedForm, section));
                } else {
                    return Stream.of(formFieldCommand.toEntityWithSection(savedForm, formFieldCommand.section()));
                }
            })
            .toList();
}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 546cf90 and aed0fa9.

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

72-77: 폼 섹션 수에 따른 분기 처리 구현이 잘 되었습니다.

폼에 섹션이 여러 개인 경우와 단일 섹션인 경우를 명확하게 구분하여 처리하는 로직이 잘 구현되었습니다. 이 구현은 PR의 목적에 부합하며, 비즈니스 요구사항을 명확하게 반영하고 있습니다.


264-268: 단일 섹션 처리 메서드가 명확하게 구현되었습니다.

기존의 toCreateFormFields 메서드를 좀 더 명확한 이름인 toCreateFormFieldsForSingleSection으로 변경한 점이 좋습니다. 이 메서드는 기존 구현과 동일하게 유지하면서 이름을 통해 그 목적을 더 명확히 전달하고 있습니다.

@Seooooo24 Seooooo24 changed the title [DDING-125-1] 섹션 여러 개일 경우 폼지 생성 수정 [DDING-125] 섹션 여러 개일 경우 폼지 생성 수정 Mar 9, 2025
@Seooooo24 Seooooo24 changed the title [DDING-125] 섹션 여러 개일 경우 폼지 생성 수정 [DDING-125-1] 섹션 여러 개일 경우 폼지 생성 수정 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.

코멘트 반영해주세요~! 고생하셨습니다

Comment on lines +271 to +281
return createFormFieldCommands.stream()
.flatMap(formFieldCommand -> {
if (formFieldCommand.section().equals("공통")) {
return savedForm.getSections().stream()
.filter(section -> !section.equals("공통"))
.map(section -> formFieldCommand.toEntityWithSection(savedForm, section));
} else {
return Stream.of(formFieldCommand.toEntityWithSection(savedForm, formFieldCommand.section()));
}
})
.toList();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

p3)
뎁스가 3인데,
flatMap -> if -> stream
가독성이 떨어져서 최대한 리팩토링 해주시면 좋을 것 같아요.

그리고 "공통"도 상수처리 하면 좋을 것 같네요

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

private 메서드 두 개로 나누어보았습니다. 한 번 더 나눌까 생각했지만 그러면 너무 많은 메서드 때문에 오히려 가독성이 떨어질 것 같기도 해서... 어떻게 생각하시는지 말씀해주실 수 있을까요?

상수처리 완료했습니다!

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

@5uhwann 5uhwann left a comment

Choose a reason for hiding this comment

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

p3)
현재 코드상으론 Command 객체를 검증 후 FormField entity를 생성하는 로직이어서 FacadeCentralFormServiceImpl에 section을 바탕으로 FormField를 생성하는 로직이 포함된거 같습니다.
제 의견으로는 FacadeCentralFormServiceImpl에서는 FormField를 entity로 변환하고 저장하는 코드만 작성하고 FormField에서 section을 활용한 로직을 작성해 FormField를 생성하는게 좋아보입니다.
구체적으로

  1. FacadeCentralFormServiceImpl에서 Command 객체를 요청 상태 그대로 entity로 변환
  2. 변환된 FormField entity 내부에서 section의 개수 및 공통 여부를 체크하여 조건에 맞을 경우 FormField 객체를 각 섹션별로 복제 및 반환
  3. FacadeCentralFormServiceImpl 복제된 FormField 리스트를 저장

해당 흐름으로 작성되면 대부분의 로직을 FormField 내부에 작성할 수 있을 거 같습니다.

@github-actions github-actions bot added D-0 and removed D-1 labels Mar 12, 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/main/java/ddingdong/ddingdongBE/domain/form/entity/FormField.java (1)

103-113: 개별 섹션 복사 메서드
copyWithSection(String newSection)를 통해 섹션만 다른 FormField 인스턴스를 생성해 재사용할 수 있습니다. 공통 속성은 그대로 복사하고 섹션만 변경하도록 구현되어 있어 섹션 확장 로직에 적합합니다. 다만, 새로운 FormField 생성 시 반드시 동일한 Form 참조가 필요한지 검토가 필요할 수 있습니다.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ea74d20 and 21d30a9.

📒 Files selected for processing (2)
  • src/main/java/ddingdong/ddingdongBE/domain/form/entity/FormField.java (2 hunks)
  • src/main/java/ddingdong/ddingdongBE/domain/form/service/FacadeCentralFormServiceImpl.java (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/java/ddingdong/ddingdongBE/domain/form/service/FacadeCentralFormServiceImpl.java
🔇 Additional comments (5)
src/main/java/ddingdong/ddingdongBE/domain/form/entity/FormField.java (5)

16-16: 스트림 임포트 추가 확인
해당 스트림 임포트는 다중 섹션 처리 시 유연하게 FormField 객체를 생성하고 반환하기 위해 필요한 것으로 보입니다. 문제 없습니다.


26-27: 상수 선언의 명확성
COMMON_SECTIONSINGLE_SECTION_SIZE라는 상수를 통해 섹션 로직을 직접적으로 나타내므로 가독성이 좋습니다. 추가로, 상수명은 비즈니스 의도를 간결하게 표현하고 있어 유지 보수에 용이합니다.


29-72: 필드 정의와 빌더 패턴 적용
필드가 역할에 맞게 잘 구분되어 있으며, 빌더 패턴을 통해 객체 생성을 명확하게 처리하고 있습니다. 기존 BaseEntity를 상속받고 있으므로, 엔터티 전반의 일관성이 잘 유지됩니다. 특별한 문제 없이 적절해 보입니다.


87-92: 복수 섹션 처리 로직
form.isLargerSectionThan(SINGLE_SECTION_SIZE) 조건을 통해 섹션의 개수를 판별하고, 필요한 경우 expandCommonSectionFormField를 호출하는 흐름이 직관적입니다. 섹션이 1개인 경우 단순화된 로직을 사용해 반환하므로, 개념적으로 분기 처리가 깔끔합니다.


94-101: 공통 섹션 분기 로직
COMMON_SECTION인지 확인하고, 해당 섹션을 제외한 나머지 섹션에 대해서만 copyWithSection을 호출하여 새로운 FormField 스트림을 생성합니다. 다중 섹션 시 공통 필드가 올바르게 확장되도록 의도된 로직으로 보이며, 책임이 명확하게 분리되어 있습니다.

Copy link
Copy Markdown
Collaborator

@5uhwann 5uhwann left a comment

Choose a reason for hiding this comment

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

고생하셨습니다!

Comment on lines +264 to +265
.map(formFieldCommand -> formFieldCommand.toEntity(savedForm))
.toList();
Copy link
Copy Markdown
Collaborator

@5uhwann 5uhwann Mar 13, 2025

Choose a reason for hiding this comment

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

p4)

Suggested change
.map(formFieldCommand -> formFieldCommand.toEntity(savedForm))
.toList();
.map(formFieldCommand -> formFieldCommand.toEntity(savedForm))
.flatMap(formField -> formField.generateFormFieldsBySection(form))
.toList();

createForm() 메서드의 스트림과 합쳐도 괜찮을거 같습니다!

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

헙 그러네요 수정하였습니다!

@Seooooo24 Seooooo24 merged commit 64edf8b into develop Mar 13, 2025
1 of 2 checks passed
@Seooooo24 Seooooo24 deleted the fix/DDING-125 branch March 13, 2025 14:35
@sonarqubecloud
Copy link
Copy Markdown

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

D-0 🎯리팩토링 리팩토링 및 고도화 이슈

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants