diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/DetailCategoryResult.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/DetailCategoryResult.java index 80e096b7..09e55272 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/DetailCategoryResult.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/DetailCategoryResult.java @@ -95,7 +95,6 @@ private void addMandatoryLectures(Set taken, Set graduationLec graduationLectures.stream() .filter(graduationLecture -> graduationLecture.getIsRevoked() == 0) .forEach(haveToLectures::add); - } private boolean checkCompleted() { diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/MandatoryMajorManager.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/MandatoryMajorManager.java index 723aae1c..ce5b8415 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/MandatoryMajorManager.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/MandatoryMajorManager.java @@ -6,6 +6,7 @@ import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailCategoryResult; import com.plzgraduate.myongjigraduatebe.graduation.domain.service.major.exception.MajorExceptionHandler; +import com.plzgraduate.myongjigraduatebe.graduation.domain.service.major.exception.MandatorySpecialCaseInformation; import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; @@ -16,6 +17,8 @@ @RequiredArgsConstructor public class MandatoryMajorManager { + private static final String detailCategoryName = "전공필수"; + private final List majorExceptionHandlers; public DetailCategoryResult createDetailCategoryResult(User user, TakenLectureInventory takenLectureInventory, @@ -28,9 +31,10 @@ public DetailCategoryResult createDetailCategoryResult(User user, TakenLectureIn for (MajorExceptionHandler majorExceptionHandler : majorExceptionHandlers) { if (majorExceptionHandler.isSupport(user, majorGraduationCategory)) { - isSatisfiedMandatory = majorExceptionHandler.checkMandatoryCondition(takenLectureInventory, - mandatoryLectures, electiveLectures); - removeMandatoryTotalCredit = majorExceptionHandler.getRemovedMandatoryTotalCredit(); + MandatorySpecialCaseInformation mandatorySpecialCaseInformation = majorExceptionHandler.getMandatorySpecialCaseInformation( + takenLectureInventory, mandatoryLectures, electiveLectures); + isSatisfiedMandatory = mandatorySpecialCaseInformation.isCompleteMandatorySpecialCase(); + removeMandatoryTotalCredit = mandatorySpecialCaseInformation.getRemovedMandatoryTotalCredit(); } } @@ -40,7 +44,7 @@ public DetailCategoryResult createDetailCategoryResult(User user, TakenLectureIn finishedTakenLecture.add(takenLecture); takenMandatory.add(takenLecture.getLecture()); }); - DetailCategoryResult majorMandatoryResult = DetailCategoryResult.create("전공필수", isSatisfiedMandatory, + DetailCategoryResult majorMandatoryResult = DetailCategoryResult.create(detailCategoryName, isSatisfiedMandatory, calculateTotalCredit(takenMandatory, mandatoryLectures, removeMandatoryTotalCredit)); majorMandatoryResult.calculate(takenMandatory, mandatoryLectures); takenLectureInventory.handleFinishedTakenLectures(finishedTakenLecture); diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/exception/MajorExceptionHandler.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/exception/MajorExceptionHandler.java index e4dfd64e..2aeeb33f 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/exception/MajorExceptionHandler.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/exception/MajorExceptionHandler.java @@ -10,8 +10,6 @@ public interface MajorExceptionHandler { boolean isSupport(User user, MajorGraduationCategory majorGraduationCategory); - boolean checkMandatoryCondition(TakenLectureInventory takenLectureInventory, + MandatorySpecialCaseInformation getMandatorySpecialCaseInformation(TakenLectureInventory takenLectureInventory, Set mandatoryLectures, Set electiveLectures); - - int getRemovedMandatoryTotalCredit(); } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/exception/OptionalMandatoryHandler.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/exception/OptionalMandatoryHandler.java index 192cc1c6..93701a7a 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/exception/OptionalMandatoryHandler.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/exception/OptionalMandatoryHandler.java @@ -14,6 +14,13 @@ import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; +/** + * N택 M의 선택과목이 있는 경우 처리하는 핸들러 클래스 + * 국제통상의 경우 회계원리, 마케팅원론, 재무관리 원론, 인적자원관리, 생산운영관리(폐지), 운영관리(구, 생산운영관리) 5개 중 4개 선택 + * 경영정보의 경우 인적자원관리, 마켓팅원론, 재무관리원론에서 ~18학번까지는 3개 모두 이수, 19학번 이후 택 2 + * 경영의 경우 국제통상원론, 국제경양, 경영정보 중 택1 + * 행정의 + */ public class OptionalMandatoryHandler implements MajorExceptionHandler { private static final String MANAGEMENT_INFORMATION = "경영정보학과"; @@ -22,7 +29,6 @@ public class OptionalMandatoryHandler implements MajorExceptionHandler { private static final String INTERNATIONAL_TRADE = "국제통상학과"; private static final int CLASS_OF_17 = 17; private static final int CLASS_OF_19 = 19; - private int removedMandatoryTotalCredit = 0; private OptionalMandatory optionalMandatory; public boolean isSupport(User user, MajorGraduationCategory majorGraduationCategory) { @@ -43,30 +49,37 @@ public boolean isSupport(User user, MajorGraduationCategory majorGraduationCateg } @Override - public boolean checkMandatoryCondition(TakenLectureInventory takenLectureInventory, - Set mandatoryLectures, Set electiveLectures) { - boolean checkMandatoryCondition = checkCompleteOptionalMandatory(takenLectureInventory, mandatoryLectures, + public MandatorySpecialCaseInformation getMandatorySpecialCaseInformation( + TakenLectureInventory takenLectureInventory, Set mandatoryLectures, Set electiveLectures) { + + int removedMandatoryTotalCredit = 0; + boolean completeMandatorySpecialCase = checkCompleteOptionalMandatory(takenLectureInventory, mandatoryLectures, electiveLectures); - if (!checkMandatoryCondition) { - removedMandatoryTotalCredit = optionalMandatory.getTotalOptionalMandatoryCredit(optionalMandatory) - - optionalMandatory.getChooseLectureCredit(optionalMandatory); + if (!completeMandatorySpecialCase) { + removedMandatoryTotalCredit = optionalMandatory.getTotalOptionalMandatoryCredit() + - optionalMandatory.getChooseLectureCredit(); } - return checkMandatoryCondition; - } - - @Override - public int getRemovedMandatoryTotalCredit() { - return removedMandatoryTotalCredit; + return MandatorySpecialCaseInformation.of(completeMandatorySpecialCase, removedMandatoryTotalCredit); } private boolean checkCompleteOptionalMandatory(TakenLectureInventory takenLectureInventory, Set mandatoryLectures, Set electiveLectures) { int chooseNum = optionalMandatory.getChooseNumber(); - //전공과목Set에서 전공필수과목에 해당되는 과목들을 추출한다. + /* + * 전공과목 Set 에서 전공선택필수과목에 해당되는 과목들을 추출한다. + */ + Set optionalMandatoryLectures = mandatoryLectures.stream().filter( optionalMandatory.getOptionalMandatoryLectures()::contains).collect(Collectors.toSet()); + /* + remainingMandatoryLectures에 모든 전공선택필수 과목을 넣고 수강했을 시 제거한다. + 최종적으로 전공선택필수 과목들 목록에서 사용자가 전공선택필수과목을 수강했다면 제거한다. + 최종적으로 remainingMandatoryLectures에 남아있는 과목은 수강해야하는 과목들이다. + N택 M개 수강이라면 M개 이상 수강하였으면 전공필수에서 전부 제거, 전공 선택으로 이관하고 아니라면 전공필수에 그대로 남아있어야한다. + */ + Set remainingMandatoryLectures = new HashSet<>(optionalMandatoryLectures); int count = 0; for (TakenLecture takenLecture : takenLectureInventory.getTakenLectures()) { @@ -91,4 +104,23 @@ private String getCalculatingMajor(User user, MajorGraduationCategory majorGradu } return user.getSubMajor(); } + /** + @Override + public boolean checkMandatoryCondition(TakenLectureInventory takenLectureInventory, + Set mandatoryLectures, Set electiveLectures) { + boolean checkMandatoryCondition = checkCompleteOptionalMandatory(takenLectureInventory, mandatoryLectures, + electiveLectures); + + if (!checkMandatoryCondition) { + removedMandatoryTotalCredit = optionalMandatory.getTotalOptionalMandatoryCredit() + - optionalMandatory.getChooseLectureCredit(); + } + return checkMandatoryCondition; + } + + @Override + public int getRemovedMandatoryTotalCredit() { + return removedMandatoryTotalCredit; + } + **/ } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/exception/ReplaceMandatoryMajorHandler.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/exception/ReplaceMandatoryMajorHandler.java index b46bc96c..2de99576 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/exception/ReplaceMandatoryMajorHandler.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/exception/ReplaceMandatoryMajorHandler.java @@ -13,8 +13,12 @@ import com.plzgraduate.myongjigraduatebe.user.domain.model.User; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; +/** + * 철학과의 경우 답사1, 답사2는 폐지 되었지만 2021번 이전까지 전공필수 + * '신유학의 이해' '유학사상의이해' 중 택1 이수 시 대체 인정 + */ public class ReplaceMandatoryMajorHandler implements MajorExceptionHandler { - private int removedMandatoryTotalCredit = 0; + //private int removedMandatoryTotalCredit = 0; private static final List REPLACED_LECTURES = List.of( Lecture.of("HAI01110", "답사1", 1, 1, null), Lecture.of("HAI01111", "답사2", 1, 1, "HAI01111") @@ -37,6 +41,18 @@ public boolean isSupport(User user, MajorGraduationCategory majorGraduationCateg return major.equals("철학과") && user.getEntryYear() <= 21; } + @Override + public MandatorySpecialCaseInformation getMandatorySpecialCaseInformation( + TakenLectureInventory takenLectureInventory, Set mandatoryLectures, Set electiveLectures) { + boolean completeMandatorySpecialCase = checkCompleteReplaceMandatory(takenLectureInventory, mandatoryLectures, + electiveLectures); + int removedMandatoryTotalCredit = 0; + if (!completeMandatorySpecialCase) { + removedMandatoryTotalCredit = 3; + } + return MandatorySpecialCaseInformation.of(completeMandatorySpecialCase, removedMandatoryTotalCredit); + } +/** @Override public boolean checkMandatoryCondition(TakenLectureInventory takenLectureInventory, Set mandatoryLectures, Set electiveLectures) { @@ -52,6 +68,7 @@ public boolean checkMandatoryCondition(TakenLectureInventory takenLectureInvento public int getRemovedMandatoryTotalCredit() { return removedMandatoryTotalCredit; } + **/ public boolean checkCompleteReplaceMandatory(TakenLectureInventory takenLectureInventory, Set mandatoryLectures, Set electiveLectures) { diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/exception/ReplaceMandatoryMajorHandlerTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/exception/ReplaceMandatoryMajorHandlerTest.java index b2deda28..9717fcf3 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/exception/ReplaceMandatoryMajorHandlerTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/exception/ReplaceMandatoryMajorHandlerTest.java @@ -46,9 +46,11 @@ class ReplaceMandatoryMajorHandlerTest { //when MajorExceptionHandler exceptionHandler = new ReplaceMandatoryMajorHandler(); - boolean checkMandatoryCondition = exceptionHandler.checkMandatoryCondition(takenLectureInventory, + MandatorySpecialCaseInformation mandatorySpecialCaseInformation = exceptionHandler.getMandatorySpecialCaseInformation( + takenLectureInventory, mandatoryLectures, electiveLectures); - int removedMandatoryTotalCredit = exceptionHandler.getRemovedMandatoryTotalCredit(); + boolean checkMandatoryCondition = mandatorySpecialCaseInformation.isCompleteMandatorySpecialCase(); + int removedMandatoryTotalCredit = mandatorySpecialCaseInformation.getRemovedMandatoryTotalCredit(); //then assertThat(checkMandatoryCondition).isTrue(); @@ -80,9 +82,11 @@ class ReplaceMandatoryMajorHandlerTest { //when MajorExceptionHandler exceptionHandler = new ReplaceMandatoryMajorHandler(); - boolean checkMandatoryCondition = exceptionHandler.checkMandatoryCondition(takenLectureInventory, + MandatorySpecialCaseInformation mandatorySpecialCaseInformation = exceptionHandler.getMandatorySpecialCaseInformation( + takenLectureInventory, mandatoryLectures, electiveLectures); - int removedMandatoryTotalCredit = exceptionHandler.getRemovedMandatoryTotalCredit(); + boolean checkMandatoryCondition = mandatorySpecialCaseInformation.isCompleteMandatorySpecialCase(); + int removedMandatoryTotalCredit = mandatorySpecialCaseInformation.getRemovedMandatoryTotalCredit(); //then assertThat(checkMandatoryCondition).isTrue(); @@ -110,9 +114,11 @@ class ReplaceMandatoryMajorHandlerTest { //when MajorExceptionHandler exceptionHandler = new ReplaceMandatoryMajorHandler(); - boolean checkMandatoryCondition = exceptionHandler.checkMandatoryCondition(takenLectureInventory, + MandatorySpecialCaseInformation mandatorySpecialCaseInformation = exceptionHandler.getMandatorySpecialCaseInformation( + takenLectureInventory, mandatoryLectures, electiveLectures); - int removedMandatoryTotalCredit = exceptionHandler.getRemovedMandatoryTotalCredit(); + boolean checkMandatoryCondition = mandatorySpecialCaseInformation.isCompleteMandatorySpecialCase(); + int removedMandatoryTotalCredit = mandatorySpecialCaseInformation.getRemovedMandatoryTotalCredit(); //then assertThat(checkMandatoryCondition).isFalse();