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

[DEV-43] 편입 졸업 요건 검사 비즈니스 로직 구현 #287

Draft
wants to merge 8 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
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 @@ -45,111 +45,142 @@ public boolean supports(GraduationCategory graduationCategory) {
}

@Override
public DetailGraduationResult calculateSingleDetailGraduation(User user,
public DetailGraduationResult calculateSingleDetailGraduation(
User user,
GraduationCategory graduationCategory,
TakenLectureInventory takenLectureInventory, GraduationRequirement graduationRequirement) {
TakenLectureInventory takenLectureInventory, GraduationRequirement graduationRequirement
) {
MajorType majorType = MajorType.from(graduationCategory);

if (majorType == MajorType.SUB) {
return generateSubMajorDetailGraduationResult(user, takenLectureInventory,
graduationRequirement);
graduationRequirement
);
}

DetailGraduationResult majorDetailGraduationResult = generateMajorDetailGraduationResult(
user,
majorType, takenLectureInventory, graduationRequirement);
majorType, takenLectureInventory, graduationRequirement
);

boolean isMandatory = graduationCategory.checkMandatoryIfSeperatedByMandatoryAndElective();
boolean isMandatory = graduationCategory.checkMandatoryIfSeparatedByMandatoryAndElective();

if (isMandatory) {
DetailCategoryResult majorDetailCategoryResult = separateMandatoryMajor(
graduationCategory,
majorDetailGraduationResult);
majorDetailGraduationResult
);
return DetailGraduationResult.create(graduationCategory,
majorDetailCategoryResult.getTotalCredits(), List.of(majorDetailCategoryResult));
majorDetailCategoryResult.getTotalCredits(), List.of(majorDetailCategoryResult)
);
}

DetailCategoryResult majorDetailCategoryResult = separateElectiveMajor(graduationCategory,
majorDetailGraduationResult);
DetailCategoryResult majorDetailCategoryResult = separateElectiveMajor(
graduationCategory,
majorDetailGraduationResult
);
return DetailGraduationResult.create(graduationCategory,
majorDetailCategoryResult.getTotalCredits(), List.of(majorDetailCategoryResult));
majorDetailCategoryResult.getTotalCredits(), List.of(majorDetailCategoryResult)
);
}

public List<DetailGraduationResult> calculateAllDetailGraduation(User user,
TakenLectureInventory takenLectureInventory, GraduationRequirement graduationRequirement) {
public List<DetailGraduationResult> calculateAllDetailGraduation(
User user,
TakenLectureInventory takenLectureInventory, GraduationRequirement graduationRequirement
) {

DetailGraduationResult primaryMajorDetailGraduationResult = generateMajorDetailGraduationResult(
user,
MajorType.PRIMARY, takenLectureInventory, graduationRequirement);
MajorType.PRIMARY, takenLectureInventory, graduationRequirement
);
DetailGraduationResult primaryMandatoryMajorDetailGraduationResult = isolateMandatoryMajorDetailGraduation(
PRIMARY_MANDATORY_MAJOR, primaryMajorDetailGraduationResult);
DetailGraduationResult primaryElectiveMajorDetailGraduationResult = isolateElectiveMajorDetailGraduation(
PRIMARY_ELECTIVE_MAJOR, primaryMajorDetailGraduationResult);

List<DetailGraduationResult> majorGraduationResults = new ArrayList<>(
List.of(primaryMandatoryMajorDetailGraduationResult,
primaryElectiveMajorDetailGraduationResult));
List.of(
primaryMandatoryMajorDetailGraduationResult,
primaryElectiveMajorDetailGraduationResult
));

if (user.getStudentCategory() == StudentCategory.DUAL_MAJOR) {
DetailGraduationResult dualMajorDetailGraduationResult = generateMajorDetailGraduationResult(
user,
MajorType.DUAL, takenLectureInventory, graduationRequirement);
MajorType.DUAL, takenLectureInventory, graduationRequirement
);
DetailGraduationResult dualMandatoryMajorDetailGraduationResult = isolateMandatoryMajorDetailGraduation(
DUAL_MANDATORY_MAJOR, dualMajorDetailGraduationResult);
DetailGraduationResult dualElectiveMajorDetailGraduationResult = isolateElectiveMajorDetailGraduation(
DUAL_ELECTIVE_MAJOR, dualMajorDetailGraduationResult);
majorGraduationResults.addAll(
List.of(dualMandatoryMajorDetailGraduationResult,
dualElectiveMajorDetailGraduationResult));
List.of(
dualMandatoryMajorDetailGraduationResult,
dualElectiveMajorDetailGraduationResult
));
}
if (user.getStudentCategory() == StudentCategory.SUB_MAJOR) {
majorGraduationResults.add(
generateSubMajorDetailGraduationResult(user, takenLectureInventory,
graduationRequirement));
graduationRequirement
));
}
return majorGraduationResults;
}

private DetailGraduationResult generateMajorDetailGraduationResult(User user,
private DetailGraduationResult generateMajorDetailGraduationResult(
User user,
MajorType majorType,
TakenLectureInventory takenLectureInventory,
GraduationRequirement graduationRequirement) {
GraduationRequirement graduationRequirement
) {
Set<MajorLecture> graduationMajorLectures = findMajorPort.findMajor(
user.getMajorByMajorType(majorType));
return majorGraduationManager.createDetailGraduationResult(user, majorType,
takenLectureInventory, graduationMajorLectures,
graduationRequirement.getMajorCreditByMajorType(majorType));
graduationRequirement.getMajorCreditByMajorType(majorType)
);
}

private DetailGraduationResult generateSubMajorDetailGraduationResult(User user,
private DetailGraduationResult generateSubMajorDetailGraduationResult(
User user,
TakenLectureInventory takenLectureInventory,
GraduationRequirement graduationRequirement) {
GraduationRequirement graduationRequirement
) {
Set<MajorLecture> graduationSubMajorLectures = findMajorPort.findMajor(user.getSubMajor());
return subMajorGraduationManager.createDetailGraduationResult(user, takenLectureInventory,
graduationSubMajorLectures,
graduationRequirement.getSubMajorCredit());
graduationRequirement.getSubMajorCredit()
);
}

private DetailGraduationResult isolateMandatoryMajorDetailGraduation(
GraduationCategory graduationCategory, DetailGraduationResult majorDetailGraduationResult) {
GraduationCategory graduationCategory, DetailGraduationResult majorDetailGraduationResult
) {
DetailCategoryResult mandatoryMajorDetailCategoryResult = separateMandatoryMajor(
graduationCategory, majorDetailGraduationResult);
return DetailGraduationResult.create(graduationCategory,
return DetailGraduationResult.create(
graduationCategory,
mandatoryMajorDetailCategoryResult.getTotalCredits(),
List.of(mandatoryMajorDetailCategoryResult));
List.of(mandatoryMajorDetailCategoryResult)
);
}

private DetailGraduationResult isolateElectiveMajorDetailGraduation(
GraduationCategory graduationCategory, DetailGraduationResult majorDetailGraduationResult) {
GraduationCategory graduationCategory, DetailGraduationResult majorDetailGraduationResult
) {
DetailCategoryResult electiveMajorDetailCategoryResult = separateElectiveMajor(
graduationCategory, majorDetailGraduationResult);
return DetailGraduationResult.create(graduationCategory,
return DetailGraduationResult.create(
graduationCategory,
electiveMajorDetailCategoryResult.getTotalCredits(),
List.of(electiveMajorDetailCategoryResult));
List.of(electiveMajorDetailCategoryResult)
);
}

private DetailCategoryResult separateMandatoryMajor(
GraduationCategory graduationCategory, DetailGraduationResult majorDetailGraduationResult) {
GraduationCategory graduationCategory, DetailGraduationResult majorDetailGraduationResult
) {
DetailCategoryResult mandatoryMajorDetailCategoryResult = majorDetailGraduationResult.getDetailCategory()
.stream()
.filter(detailCategoryResult -> detailCategoryResult.getDetailCategoryName()
Expand All @@ -161,7 +192,8 @@ private DetailCategoryResult separateMandatoryMajor(
}

private DetailCategoryResult separateElectiveMajor(
GraduationCategory graduationCategory, DetailGraduationResult majorDetailGraduationResult) {
GraduationCategory graduationCategory, DetailGraduationResult majorDetailGraduationResult
) {
DetailCategoryResult electiveMajorDetailCategoryResult = majorDetailGraduationResult.getDetailCategory()
.stream()
.filter(detailCategoryResult -> detailCategoryResult.getDetailCategoryName()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static GraduationCategory of(String name) {
.orElseThrow(() -> new IllegalArgumentException("해당 카테고리를 찾을 수 없습니다."));
}

public boolean checkMandatoryIfSeperatedByMandatoryAndElective() {
public boolean checkMandatoryIfSeparatedByMandatoryAndElective() {
return this == PRIMARY_MANDATORY_MAJOR || this == DUAL_MANDATORY_MAJOR;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class ParsingTextService implements ParsingTextUseCase {
private final UpdateStudentInformationUseCase updateStudentInformationUseCase;
private final SaveTakenLectureFromParsingTextUseCase saveTakenLectureFromParsingTextUseCase;
private final DeleteTakenLectureUseCase deleteTakenLectureByUserUseCase;

private final GenerateOrModifyCompletedCreditUseCase generateOrModifyCompletedCreditUseCase;

@Override
Expand Down Expand Up @@ -63,20 +62,19 @@ private void deleteTakenLecturesIfAlreadyEnrolled(User user) {

private void saveTakenLectures(User user, ParsingInformation parsingInformation) {
List<ParsingTakenLectureDto> parsingTakenLectureDtoList = parsingInformation.getTakenLectureInformation();
List<TakenLectureInformation> saveTakenLectureCommand = getSaveTakenLectureCommand(
parsingTakenLectureDtoList);
List<TakenLectureInformation> saveTakenLectureCommand =
getSaveTakenLectureCommand(parsingTakenLectureDtoList);
saveTakenLectureFromParsingTextUseCase.saveTakenLectures(user, saveTakenLectureCommand);
}

private User updateUser(User user, ParsingInformation parsingInformation) {
UpdateStudentInformationCommand updateStudentInfoCommand = UpdateStudentInformationCommand.of(
user, parsingInformation);
UpdateStudentInformationCommand updateStudentInfoCommand =
UpdateStudentInformationCommand.of(user, parsingInformation);
return updateStudentInformationUseCase.updateUser(updateStudentInfoCommand);
}

private void validateParsingText(String parsingText) {
if (parsingText.trim()
.isEmpty()) {
if (parsingText.trim().isEmpty()) {
throw new InvalidPdfException("PDF를 인식하지 못했습니다. 채널톡으로 문의 바랍니다.");
}
}
Expand All @@ -88,13 +86,15 @@ private void validateStudentNumber(User user, ParsingInformation parsingInformat
}

private List<TakenLectureInformation> getSaveTakenLectureCommand(
List<ParsingTakenLectureDto> parsingTakenLectureDtoList) {
List<ParsingTakenLectureDto> parsingTakenLectureDtoList
) {
return parsingTakenLectureDtoList.stream()
.map(parsingTakenLectureDto ->
TakenLectureInformation.createTakenLectureInformation(
parsingTakenLectureDto.getLectureCode(),
parsingTakenLectureDto.getYear(),
parsingTakenLectureDto.getSemester())
parsingTakenLectureDto.getSemester()
)
)
.collect(Collectors.toList());
}
Expand All @@ -105,5 +105,4 @@ private void checkUnSupportedUser(ParsingInformation parsingInformation) {
throw new IllegalArgumentException(ErrorCode.UNSUPPORTED_STUDENT_CATEGORY.toString());
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.Semester;
import com.plzgraduate.myongjigraduatebe.user.domain.model.StudentCategory;
import com.plzgraduate.myongjigraduatebe.user.domain.model.TransferCredit;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import lombok.Builder;
import lombok.Getter;

Expand All @@ -19,13 +22,22 @@ public class ParsingInformation {
private final String dualMajor;
private final String associatedMajor;
private final StudentCategory studentCategory;
private final TransferCredit transferCredit;
private final List<ParsingTakenLectureDto> takenLectureInformation;

@Builder
public ParsingInformation(String studentName, String studentNumber, String major,
String changeMajor, String subMajor, String dualMajor,
String associatedMajor, StudentCategory studentCategory,
List<ParsingTakenLectureDto> takenLectureInformation) {
public ParsingInformation(
String studentName,
String studentNumber,
String major,
String changeMajor,
String subMajor,
String dualMajor,
String associatedMajor,
StudentCategory studentCategory,
TransferCredit transferCredit,
List<ParsingTakenLectureDto> takenLectureInformation
) {
this.studentName = studentName;
this.studentNumber = studentNumber;
this.major = major;
Expand All @@ -34,6 +46,7 @@ public ParsingInformation(String studentName, String studentNumber, String major
this.subMajor = subMajor;
this.associatedMajor = associatedMajor;
this.studentCategory = studentCategory;
this.transferCredit = transferCredit;
this.takenLectureInformation = takenLectureInformation;
}

Expand All @@ -49,6 +62,7 @@ public static ParsingInformation parsing(String parsingText) {
.subMajor(parsingStudentCategoryDto.getSubMajor())
.associatedMajor(parsingStudentCategoryDto.getAssociatedMajor())
.studentCategory(parsingStudentCategoryDto.getStudentCategory())
.transferCredit(parsingStudentCategoryDto.getTransferCredit())
.takenLectureInformation(parseTakenLectureInformation(splitText))
.build();
}
Expand Down Expand Up @@ -80,11 +94,14 @@ private static ParsingStudentCategoryDto parseStudentCategory(String[] splitText
String subMajor = null;
String associatedMajor = null;
StudentCategory studentCategory;
TransferCredit transferCredit;
String secondLineText = splitText[2];
String thirdLineText = splitText[3];
String fourthLineText = splitText[4];
List<String> categories = new ArrayList<>();
String[] parts = secondLineText.split(", ");
String[] thirdLineParts = thirdLineText.split(", ");

if (thirdLineParts.length == 4) {
String part = thirdLineParts[3];
if (part.startsWith("전과내역 -")) {
Expand All @@ -105,16 +122,25 @@ private static ParsingStudentCategoryDto parseStudentCategory(String[] splitText
associatedMajor = part.substring("연계전공 - ".length());
}
}

studentCategory = StudentCategory.from(categories);
return ParsingStudentCategoryDto.of(changeMajor, subMajor, dualMajor, associatedMajor,
studentCategory);

String fourthLine = fourthLineText.substring("편입생 인정학점 - ".length());
transferCredit = TransferCredit.from(Arrays.stream(fourthLine.split(","))
.map(s -> s.replaceAll("[^0-9]", ""))
.collect(Collectors.joining("/")));

return ParsingStudentCategoryDto.of(
changeMajor, subMajor, dualMajor, associatedMajor, studentCategory, transferCredit
);
}

private static List<ParsingTakenLectureDto> parseTakenLectureInformation(String[] splitText) {
List<ParsingTakenLectureDto> takenLectureInformation = new ArrayList<>();
for (int i = 16; i < splitText.length; i += 7) {
if (i + 3 < splitText.length && !Pattern.matches("^[A-Z]+$",
splitText[i + 3].substring(0, 1))) {
if (i + 3 < splitText.length && !Pattern.matches(
"^[A-Z]+$", splitText[i + 3].substring(0, 1)
)) {
return takenLectureInformation;
}
int year = Integer.parseInt(splitText[i + 1].split(" ")[0].substring(0, 4));
Expand Down
Loading