Skip to content

Commit

Permalink
question table에서 recruitment column, index 제거 #122
Browse files Browse the repository at this point in the history
Merge pull request #124 from team-crews/refactor/#122-remove-index-in-question-table
  • Loading branch information
jongmee authored Nov 16, 2024
2 parents b4b3b31 + d0304cc commit 3aac619
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@
@AllArgsConstructor
@Table(name = "narrative_question",
indexes = {
@Index(columnList = "section_id", name = "idx_section_id"),
@Index(columnList = "recruitment_id", name = "idx_recruitment_id")

@Index(columnList = "section_id", name = "idx_section_id")
}
)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
Expand All @@ -36,10 +34,6 @@ public class NarrativeQuestion implements Question {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "recruitment_id", nullable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
private Recruitment recruitment;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "section_id", nullable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
private Section section;
Expand All @@ -60,7 +54,7 @@ public class NarrativeQuestion implements Question {
private Integer wordLimit;

public NarrativeQuestion(Long id) {
this(id, null, null, null, null, null, null);
this(id, null, null, null, null);
}

public NarrativeQuestion(Long id, String content, Boolean necessity, Integer order, Integer wordLimit) {
Expand All @@ -79,10 +73,6 @@ public void updateSection(Section section) {
this.section = section;
}

public void updateRecruitment(Recruitment recruitment) {
this.recruitment = recruitment;
}

public Long getSectionId() {
return this.section.getId();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,6 @@ public Recruitment(Long id, String code, String title, String description, Local

private void addSections(List<Section> sections) {
sections.forEach(section -> section.updateRecruitment(this));
sections.stream()
.map(section -> section.getSelectiveQuestions())
.flatMap(Collection::stream)
.forEach(selectiveQuestion -> selectiveQuestion.updateRecruitment(this));
sections.stream()
.map(section -> section.getNarrativeQuestions())
.flatMap(Collection::stream)
.forEach(narrativeQuestion -> narrativeQuestion.updateRecruitment(this));
this.sections.addAll(sections);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
@Entity
@Table(name = "selective_question",
indexes = {
@Index(columnList = "section_id", name = "idx_section_id"),
@Index(columnList = "recruitment_id", name = "idx_recruitment_id")
@Index(columnList = "section_id", name = "idx_section_id")
}
)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
Expand All @@ -41,10 +40,6 @@ public class SelectiveQuestion implements Question {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "recruitment_id", nullable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
private Recruitment recruitment;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "section_id", nullable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
private Section section;
Expand Down Expand Up @@ -108,10 +103,6 @@ public void updateSection(Section section) {
this.section = section;
}

public void updateRecruitment(Recruitment recruitment) {
this.recruitment = recruitment;
}

public List<Choice> getOrderedChoices() {
Collections.sort(choices);
return choices;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,12 @@ protected Recruitment createDefaultRecruitment(Administrator publisher) {
private NarrativeQuestion createNarrativeQuestion(Section section) {
NarrativeQuestion narrativeQuestion = NARRATIVE_QUESTION();
narrativeQuestion.updateSection(section);
narrativeQuestion.updateRecruitment(section.getRecruitment());
return narrativeQuestion;
}

private SelectiveQuestion createSelectiveQuestion(Section section) {
SelectiveQuestion selectiveQuestion = SELECTIVE_QUESTION();
selectiveQuestion.updateSection(section);
selectiveQuestion.updateRecruitment(section.getRecruitment());
return selectiveQuestion;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ public TestRecruitment create(String code, String clubName, LocalDateTime deadli

public TestRecruitment addSection(String name, List<NarrativeQuestion> narrativeQuestions,
List<SelectiveQuestion> selectiveQuestions) {
narrativeQuestions.forEach(narrativeQuestion -> narrativeQuestion.updateRecruitment(this.recruitment));
selectiveQuestions.forEach(selectiveQuestion -> selectiveQuestion.updateRecruitment(this.recruitment));
Section section = new Section(null, name, DEFAULT_DESCRIPTION, narrativeQuestions, selectiveQuestions);
section.updateRecruitment(this.recruitment);
Section savedSection = environ.sectionRepository().save(section);
Expand Down

0 comments on commit 3aac619

Please sign in to comment.