Skip to content

Commit

Permalink
refactor: 전공 특수 핸들러 인터페이스 수정 및 반영
Browse files Browse the repository at this point in the history
  • Loading branch information
stophwan committed Jun 11, 2024
1 parent adfcbff commit 2291e43
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ private void addMandatoryLectures(Set<Lecture> taken, Set<Lecture> graduationLec
graduationLectures.stream()
.filter(graduationLecture -> graduationLecture.getIsRevoked() == 0)
.forEach(haveToLectures::add);

}

private boolean checkCompleted() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -16,6 +17,8 @@
@RequiredArgsConstructor
public class MandatoryMajorManager {

private static final String detailCategoryName = "전공필수";

private final List<MajorExceptionHandler> majorExceptionHandlers;

public DetailCategoryResult createDetailCategoryResult(User user, TakenLectureInventory takenLectureInventory,
Expand All @@ -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();
}
}

Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
public interface MajorExceptionHandler {
boolean isSupport(User user, MajorGraduationCategory majorGraduationCategory);

boolean checkMandatoryCondition(TakenLectureInventory takenLectureInventory,
MandatorySpecialCaseInformation getMandatorySpecialCaseInformation(TakenLectureInventory takenLectureInventory,
Set<Lecture> mandatoryLectures, Set<Lecture> electiveLectures);

int getRemovedMandatoryTotalCredit();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "경영정보학과";
Expand All @@ -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) {
Expand All @@ -43,30 +49,37 @@ public boolean isSupport(User user, MajorGraduationCategory majorGraduationCateg
}

@Override
public boolean checkMandatoryCondition(TakenLectureInventory takenLectureInventory,
Set<Lecture> mandatoryLectures, Set<Lecture> electiveLectures) {
boolean checkMandatoryCondition = checkCompleteOptionalMandatory(takenLectureInventory, mandatoryLectures,
public MandatorySpecialCaseInformation getMandatorySpecialCaseInformation(
TakenLectureInventory takenLectureInventory, Set<Lecture> mandatoryLectures, Set<Lecture> 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<Lecture> mandatoryLectures, Set<Lecture> electiveLectures) {
int chooseNum = optionalMandatory.getChooseNumber();
//전공과목Set에서 전공필수과목에 해당되는 과목들을 추출한다.
/*
* 전공과목 Set 에서 전공선택필수과목에 해당되는 과목들을 추출한다.
*/

Set<Lecture> optionalMandatoryLectures = mandatoryLectures.stream().filter(
optionalMandatory.getOptionalMandatoryLectures()::contains).collect(Collectors.toSet());

/*
remainingMandatoryLectures에 모든 전공선택필수 과목을 넣고 수강했을 시 제거한다.
최종적으로 전공선택필수 과목들 목록에서 사용자가 전공선택필수과목을 수강했다면 제거한다.
최종적으로 remainingMandatoryLectures에 남아있는 과목은 수강해야하는 과목들이다.
N택 M개 수강이라면 M개 이상 수강하였으면 전공필수에서 전부 제거, 전공 선택으로 이관하고 아니라면 전공필수에 그대로 남아있어야한다.
*/

Set<Lecture> remainingMandatoryLectures = new HashSet<>(optionalMandatoryLectures);
int count = 0;
for (TakenLecture takenLecture : takenLectureInventory.getTakenLectures()) {
Expand All @@ -91,4 +104,23 @@ private String getCalculatingMajor(User user, MajorGraduationCategory majorGradu
}
return user.getSubMajor();
}
/**
@Override
public boolean checkMandatoryCondition(TakenLectureInventory takenLectureInventory,
Set<Lecture> mandatoryLectures, Set<Lecture> electiveLectures) {
boolean checkMandatoryCondition = checkCompleteOptionalMandatory(takenLectureInventory, mandatoryLectures,
electiveLectures);
if (!checkMandatoryCondition) {
removedMandatoryTotalCredit = optionalMandatory.getTotalOptionalMandatoryCredit()
- optionalMandatory.getChooseLectureCredit();
}
return checkMandatoryCondition;
}
@Override
public int getRemovedMandatoryTotalCredit() {
return removedMandatoryTotalCredit;
}
**/
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Lecture> REPLACED_LECTURES = List.of(
Lecture.of("HAI01110", "답사1", 1, 1, null),
Lecture.of("HAI01111", "답사2", 1, 1, "HAI01111")
Expand All @@ -37,6 +41,18 @@ public boolean isSupport(User user, MajorGraduationCategory majorGraduationCateg
return major.equals("철학과") && user.getEntryYear() <= 21;
}

@Override
public MandatorySpecialCaseInformation getMandatorySpecialCaseInformation(
TakenLectureInventory takenLectureInventory, Set<Lecture> mandatoryLectures, Set<Lecture> 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<Lecture> mandatoryLectures, Set<Lecture> electiveLectures) {
Expand All @@ -52,6 +68,7 @@ public boolean checkMandatoryCondition(TakenLectureInventory takenLectureInvento
public int getRemovedMandatoryTotalCredit() {
return removedMandatoryTotalCredit;
}
**/

public boolean checkCompleteReplaceMandatory(TakenLectureInventory takenLectureInventory,
Set<Lecture> mandatoryLectures, Set<Lecture> electiveLectures) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 2291e43

Please sign in to comment.