-
Notifications
You must be signed in to change notification settings - Fork 3
[BE] refactor: 구조화된 템플릿 사용 #980
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
base: develop
Are you sure you want to change the base?
Changes from all commits
86b62da
d5783eb
181b67a
1e9d3e5
c92a40a
2feace1
f55c75c
8cc8d2e
61f0e99
f9c07a4
9091b48
4bf7a00
ae6a893
36b2d91
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 |
---|---|---|
|
@@ -13,11 +13,14 @@ | |
import jakarta.persistence.OneToMany; | ||
import jakarta.persistence.Table; | ||
import java.util.Collection; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import lombok.AccessLevel; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import reviewme.template.domain.exception.DuplicateQuestionIdException; | ||
import reviewme.template.domain.exception.QuestionIdsNotExistException; | ||
|
||
@Entity | ||
@Table(name = "section") | ||
|
@@ -52,6 +55,7 @@ public class Section { | |
|
||
public Section(VisibleType visibleType, List<Long> questionIds, | ||
Long onSelectedOptionId, String sectionName, String header, int position) { | ||
validateQuestionIds(questionIds); | ||
this.visibleType = visibleType; | ||
this.questionIds = questionIds.stream() | ||
.map(SectionQuestion::new) | ||
|
@@ -62,6 +66,36 @@ public Section(VisibleType visibleType, List<Long> questionIds, | |
this.position = position; | ||
} | ||
|
||
private void validateQuestionIds(List<Long> questionIds) { | ||
validateNotEmpty(questionIds); | ||
validateNoDuplicates(questionIds); | ||
} | ||
|
||
private void validateNotEmpty(List<Long> questionIds) { | ||
if (questionIds == null || questionIds.isEmpty()) { | ||
throw new QuestionIdsNotExistException(); | ||
} | ||
} | ||
|
||
private void validateNoDuplicates(List<Long> questionIds) { | ||
int originalSize = questionIds.size(); | ||
int deduplicatedSize = new HashSet<>(questionIds).size(); | ||
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. 중복을 제거한 후의 수라는 뜻의 변수명은 어떨까요? 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. dedup이 그 의미입니당~ 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. 아루의 코멘트 정답 |
||
|
||
if (originalSize != deduplicatedSize) { | ||
throw new DuplicateQuestionIdException(questionIds); | ||
} | ||
} | ||
|
||
public List<Long> getQuestionIds() { | ||
return questionIds.stream() | ||
.map(SectionQuestion::getQuestionId) | ||
.toList(); | ||
} | ||
|
||
public boolean isAlwaysVisible() { | ||
return visibleType == VisibleType.ALWAYS; | ||
} | ||
|
||
public boolean isVisibleBySelectedOptionIds(Collection<Long> selectedOptionIds) { | ||
return visibleType == VisibleType.ALWAYS || selectedOptionIds.contains(onSelectedOptionId); | ||
} | ||
|
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.
checkbox 통일 좋네요 👍