Skip to content
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

[개선] 입학원서 과목 목록 정렬 #126

Merged
merged 2 commits into from
Sep 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.bamdoliro.maru.domain.form.domain.type.AchievementLevel;
import com.bamdoliro.maru.domain.form.domain.value.Subject;
import com.bamdoliro.maru.domain.form.domain.value.SubjectMap;
import com.bamdoliro.maru.domain.form.exception.FormAlreadySubmittedException;
import com.bamdoliro.maru.domain.form.service.FormFacade;
import com.bamdoliro.maru.domain.user.domain.User;
import com.bamdoliro.maru.infrastructure.pdf.GeneratePdfService;
Expand All @@ -24,10 +23,7 @@
import org.springframework.core.io.ByteArrayResource;

import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.*;
import java.util.stream.Collectors;

@Slf4j
Expand Down Expand Up @@ -72,10 +68,25 @@ public ByteArrayResource execute(User user) {

private List<SubjectVO> getSubjectList(Form form) {
List<SubjectVO> value = new ArrayList<>();
List<String> careerElectiveCourses = List.of("음악", "미술", "체육");
Map<String, List<Subject>> subjectMap = form.getGrade()
.getSubjectListValue()
.stream()
.collect(Collectors.groupingBy(Subject::getSubjectName));
.filter(subject -> !careerElectiveCourses.contains(subject.getSubjectName()))
.collect(Collectors.groupingBy(
Subject::getSubjectName,
LinkedHashMap::new,
Collectors.toList()
));
careerElectiveCourses.forEach(course -> {
List<Subject> subjects = form.getGrade().getSubjectListValue()
.stream()
.filter(subject -> course.equals(subject.getSubjectName()))
.collect(Collectors.toList());
if (!subjects.isEmpty()) {
subjectMap.put(course, subjects);
}
});

subjectMap.forEach((key, values) -> {
SubjectVO subject = new SubjectVO(key);
Expand All @@ -84,7 +95,7 @@ private List<SubjectVO> getSubjectList(Form form) {
subject.score = v.getOriginalScore();
} else {
try {
SubjectVO.class.getField("achievementLevel" + v.toString())
SubjectVO.class.getField("achievementLevel" + v)
.set(subject, v.getAchievementLevel());
} catch (IllegalAccessException | NoSuchFieldException e) {
throw new RuntimeException(e);
Expand Down
Loading