-
Notifications
You must be signed in to change notification settings - Fork 3
[DDING-125-1] 섹션 여러 개일 경우 폼지 생성 수정 #295
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,6 +41,7 @@ | |
| import java.util.Objects; | ||
| import java.util.concurrent.CompletableFuture; | ||
| import java.util.concurrent.TimeUnit; | ||
| import java.util.stream.Stream; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.stereotype.Service; | ||
|
|
@@ -52,6 +53,9 @@ | |
| @Slf4j | ||
| public class FacadeCentralFormServiceImpl implements FacadeCentralFormService { | ||
|
|
||
| private static final int SINGLE_SECTION_SIZE = 1; | ||
| private static final String COMMON_SECTION = "공통"; | ||
|
|
||
| private final FormService formService; | ||
| private final FormFieldService formFieldService; | ||
| private final ClubService clubService; | ||
|
|
@@ -68,8 +72,7 @@ public void createForm(CreateFormCommand createFormCommand) { | |
|
|
||
| Form form = createFormCommand.toEntity(club); | ||
| Form savedForm = formService.create(form); | ||
|
|
||
| List<FormField> formFields = toCreateFormFields(savedForm, | ||
| List<FormField> formFields = buildFormFieldBySection(savedForm, | ||
| createFormCommand.formFieldCommands()); | ||
| formFieldService.createAll(formFields); | ||
| } | ||
|
|
@@ -254,12 +257,41 @@ private void validateEndDate(LocalDate startDate, LocalDate endDate) { | |
| private List<FormField> toUpdateFormFields(Form originform, | ||
| List<UpdateFormFieldCommand> updateFormFieldCommands) { | ||
| return updateFormFieldCommands.stream() | ||
| .map(formFieldCommand -> formFieldCommand.toEntity(originform)).toList(); | ||
| .map(formFieldCommand -> formFieldCommand.toEntity(originform)) | ||
| .toList(); | ||
| } | ||
|
|
||
| private List<FormField> buildFormFieldBySection(Form savedForm, | ||
| List<CreateFormFieldCommand> createFormFieldCommand) { | ||
| if (savedForm.isLargerSectionThan(SINGLE_SECTION_SIZE)) { | ||
| return toCreateFormFieldsForMultipleSections(savedForm, createFormFieldCommand); | ||
| } else { | ||
| return toCreateFormFieldsForSingleSection(savedForm, createFormFieldCommand); | ||
| } | ||
| } | ||
|
|
||
| private List<FormField> toCreateFormFields(Form savedForm, | ||
| List<CreateFormFieldCommand> createFormFieldCommands) { | ||
| private List<FormField> toCreateFormFieldsForSingleSection(Form savedForm, | ||
| List<CreateFormFieldCommand> createFormFieldCommands) { | ||
| return createFormFieldCommands.stream() | ||
| .map(formFieldCommand -> formFieldCommand.toEntity(savedForm)).toList(); | ||
| .map(formFieldCommand -> formFieldCommand.toEntity(savedForm)) | ||
| .toList(); | ||
| } | ||
|
|
||
| private List<FormField> toCreateFormFieldsForMultipleSections(Form savedForm, | ||
| List<CreateFormFieldCommand> createFormFieldCommands) { | ||
| return createFormFieldCommands.stream() | ||
| .flatMap(formFieldCommand -> createFormFieldsBySection(savedForm, formFieldCommand)) | ||
| .toList(); | ||
|
Comment on lines
+271
to
+260
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. p3) 그리고 "공통"도 상수처리 하면 좋을 것 같네요
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. private 메서드 두 개로 나누어보았습니다. 한 번 더 나눌까 생각했지만 그러면 너무 많은 메서드 때문에 오히려 가독성이 떨어질 것 같기도 해서... 어떻게 생각하시는지 말씀해주실 수 있을까요? 상수처리 완료했습니다! |
||
| } | ||
|
|
||
| private Stream<FormField> createFormFieldsBySection(Form savedForm, | ||
| CreateFormFieldCommand formFieldCommand) { | ||
| if (formFieldCommand.section().equals(COMMON_SECTION)) { | ||
| return savedForm.getSections().stream() | ||
| .filter(section -> !section.equals(COMMON_SECTION)) | ||
| .map(section -> formFieldCommand.toEntityWithSection(savedForm, section)); | ||
| } | ||
| return Stream.of(formFieldCommand.toEntityWithSection(savedForm, formFieldCommand.section())); | ||
| } | ||
|
|
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
p4)
createForm() 메서드의 스트림과 합쳐도 괜찮을거 같습니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
헙 그러네요 수정하였습니다!