From b9810ab071b9b9e42744770cb223acfbbbc60341 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A0=95=EC=A7=80=ED=99=98?= <64758861+stophwan@users.noreply.github.com> Date: Sun, 30 Jun 2024 00:19:13 +0900 Subject: [PATCH] =?UTF-8?q?[DEV-36]=20=EC=A1=B8=EC=97=85=20=EA=B2=80?= =?UTF-8?q?=EC=82=AC=20=EC=BD=94=EB=93=9C=20=EB=A6=AC=ED=8C=A9=ED=86=A0?= =?UTF-8?q?=EB=A7=81=20(#274)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: MajorGraduationCategory -> MajorType 변경 * feat: User도메인 MajorType 별 전공과목 반환 메서드 구현 * feat: GraduationRequirement도메인 MajorType별 졸업요견 반환 메서드 구현 * feat: GraduationCategory 도메인 전공필수, 선택 확인하는 메서드 추가 * refactor: 학문기초교양 졸업 계산 Service 리팩토링 * refactor: 전공 졸업 계산 Service 리팩토링 * refactor: UseCaseResolver 삭제 및 하위 메서드 통합 * refactor: CalculateGraduationService 책임 분리 리팩토링 * refactor: CalculateDetailGraduationUsecase 인터페이스 수정 * test: 리팩토링 이후 테스트코드 작성 * refactor: 리팩토링 이후 불필요한 클래스 삭제 * test: 리팩토링 이후 테스트 코드 수정 * fix: DetailCategoryResult categoryName 필드 기본할당 문제 수정 * refactor: code smell 수정 * refactor: code smell 수정 * refactor: 수강 과목 동기화 메서드 네이밍 수정 * refactor: 코드 포맷 수정 * refactor: 코드 오류 수정 --------- Co-authored-by: 5uhwann <5uhwann27@gmail.com> --- ...sicAcademicalCultureGraduationService.java | 102 ++++++++ ...lculateCommonCultureGraduationService.java | 15 +- ...CalculateCoreCultureGraduationService.java | 17 +- ...demicalCultureDetailGraduationService.java | 65 ------ ...lElectiveMajorDetailGraduationService.java | 70 ------ ...MandatoryMajorDetailGraduationService.java | 70 ------ .../service/CalculateGraduationService.java | 161 +++---------- .../CalculateMajorGraduationService.java | 161 +++++++++++++ ...demicalCultureDetailGraduationService.java | 65 ------ ...yElectiveMajorDetailGraduationService.java | 72 ------ ...MandatoryMajorDetailGraduationService.java | 70 ------ ...alculateSingleDetailGraduationService.java | 18 +- ...culateSubMajorDetailGraduationService.java | 27 --- ...lculateCommonCultureGraduationUseCase.java | 4 - ...CalculateCoreCultureGraduationUseCase.java | 5 - .../CalculateDetailGraduationUseCase.java | 2 +- ...demicalCultureDetailGraduationUseCase.java | 4 - ...lElectiveMajorDetailGraduationUseCase.java | 9 - ...MandatoryMajorDetailGraduationUseCase.java | 9 - ...demicalCultureDetailGraduationUseCase.java | 5 - ...yElectiveMajorDetailGraduationUseCase.java | 9 - ...MandatoryMajorDetailGraduationUseCase.java | 9 - ...culateSubMajorDetailGraduationUseCase.java | 4 - .../domain/model/DetailGraduationResult.java | 2 +- .../domain/model/GraduationCategory.java | 4 + .../domain/model/GraduationRequirement.java | 16 ++ .../graduation/domain/model/MajorType.java | 23 ++ ... => BasicAcademicalGraduationManager.java} | 3 +- ...nessBasicAcademicalGraduationManager.java} | 13 +- ...aultBasicAcademicalGraduationManager.java} | 24 +- ...cienceBasicAcademicGraduationManager.java} | 11 +- .../CommonCultureDetailCategoryManager.java | 24 +- ...ager.java => CommonGraduationManager.java} | 6 +- .../CoreCultureDetailCategoryManager.java | 14 +- ...anager.java => CoreGraduationManager.java} | 5 +- .../service/major/ElectiveMajorManager.java | 3 + .../major/MajorGraduationCategory.java | 10 - ...nager.java => MajorGraduationManager.java} | 22 +- .../service/major/MandatoryMajorManager.java | 11 +- .../MandatoryMajorSpecialCaseHandler.java | 5 +- .../major/OptionalMandatoryMajorHandler.java | 25 +- .../major/ReplaceMandatoryMajorHandler.java | 20 +- ...er.java => SubMajorGraduationManager.java} | 5 +- ...culateDetailGraduationUseCaseResolver.java | 9 - ...culateDetailGraduationUseCaseResolver.java | 27 --- .../domain/model/TakenLectureInventory.java | 4 +- .../UpdateStudentInformationCommand.java | 15 ++ .../user/domain/model/User.java | 14 ++ ...teDetailGraduationUseCaseResolverTest.java | 40 ---- ...cademicalCultureGraduationServiceTest.java | 126 ++++++++++ ...ateCommonCultureGraduationServiceTest.java | 30 ++- ...ulateCoreCultureGraduationServiceTest.java | 35 ++- ...calCultureDetailGraduationServiceTest.java | 67 ------ ...ctiveMajorDetailGraduationServiceTest.java | 104 --------- ...atoryMajorDetailGraduationServiceTest.java | 103 -------- .../CalculateMajorGraduationServiceTest.java | 219 ++++++++++++++++++ ...calCultureDetailGraduationServiceTest.java | 67 ------ ...ctiveMajorDetailGraduationServiceTest.java | 107 --------- ...atoryMajorDetailGraduationServiceTest.java | 103 -------- ...lateSingleDetailGraduationServiceTest.java | 39 ++-- .../domain/model/GraduationCategoryTest.java | 21 ++ .../domain/model/MajorTypeTest.java | 37 +++ ...BasicAcademicalGraduationManagerTest.java} | 7 +- ...BasicAcademicalGraduationManagerTest.java} | 7 +- ...SocialScienceBasicAcademicManagerTest.java | 5 +- .../CommonCultureGraduationManagerTest.java | 3 +- .../CoreCultureGraduationManagerTest.java | 2 +- .../major/DataTechnologyMajorTest.java | 14 +- .../major/InternationTradeMajorTest.java | 38 +-- .../OptionalMandatoryMajorHandlerTest.java | 7 +- .../ReplaceMandatoryMajorHandlerTest.java | 10 +- ...ava => SubMajorGraduationManagerTest.java} | 4 +- .../model/TakenLectureInventoryTest.java | 4 +- .../user/domain/model/UserTest.java | 18 ++ 74 files changed, 1043 insertions(+), 1462 deletions(-) create mode 100644 src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateBasicAcademicalCultureGraduationService.java delete mode 100644 src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateDualBasicAcademicalCultureDetailGraduationService.java delete mode 100644 src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateDualElectiveMajorDetailGraduationService.java delete mode 100644 src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateDualMandatoryMajorDetailGraduationService.java create mode 100644 src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateMajorGraduationService.java delete mode 100644 src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculatePrimaryBasicAcademicalCultureDetailGraduationService.java delete mode 100644 src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculatePrimaryElectiveMajorDetailGraduationService.java delete mode 100644 src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculatePrimaryMandatoryMajorDetailGraduationService.java delete mode 100644 src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateSubMajorDetailGraduationService.java delete mode 100644 src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/usecase/CalculateCommonCultureGraduationUseCase.java delete mode 100644 src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/usecase/CalculateCoreCultureGraduationUseCase.java delete mode 100644 src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/usecase/CalculateDualBasicAcademicalCultureDetailGraduationUseCase.java delete mode 100644 src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/usecase/CalculateDualElectiveMajorDetailGraduationUseCase.java delete mode 100644 src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/usecase/CalculateDualMandatoryMajorDetailGraduationUseCase.java delete mode 100644 src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/usecase/CalculatePrimaryBasicAcademicalCultureDetailGraduationUseCase.java delete mode 100644 src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/usecase/CalculatePrimaryElectiveMajorDetailGraduationUseCase.java delete mode 100644 src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/usecase/CalculatePrimaryMandatoryMajorDetailGraduationUseCase.java delete mode 100644 src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/usecase/CalculateSubMajorDetailGraduationUseCase.java create mode 100644 src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/MajorType.java rename src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/{BasicAcademicalManager.java => BasicAcademicalGraduationManager.java} (80%) rename src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/{BusinessBasicAcademicalManager.java => BusinessBasicAcademicalGraduationManager.java} (87%) rename src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/{DefaultBasicAcademicalManager.java => DefaultBasicAcademicalGraduationManager.java} (64%) rename src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/{SocialScienceBasicAcademicManager.java => SocialScienceBasicAcademicGraduationManager.java} (89%) rename src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/commonculture/{CommonCultureGraduationManager.java => CommonGraduationManager.java} (93%) rename src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/coreculture/{CoreCultureGraduationManager.java => CoreGraduationManager.java} (91%) delete mode 100644 src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/MajorGraduationCategory.java rename src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/{MajorManager.java => MajorGraduationManager.java} (88%) rename src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/submajor/{SubMajorManager.java => SubMajorGraduationManager.java} (94%) delete mode 100644 src/main/java/com/plzgraduate/myongjigraduatebe/graduation/support/resolver/CalculateDetailGraduationUseCaseResolver.java delete mode 100644 src/main/java/com/plzgraduate/myongjigraduatebe/graduation/support/resolver/SingleCalculateDetailGraduationUseCaseResolver.java delete mode 100644 src/test/java/com/plzgraduate/myongjigraduatebe/graduation/api/SingleCalculateDetailGraduationUseCaseResolverTest.java create mode 100644 src/test/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateBasicAcademicalCultureGraduationServiceTest.java delete mode 100644 src/test/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateDualBasicAcademicalCultureDetailGraduationServiceTest.java delete mode 100644 src/test/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateDualElectiveMajorDetailGraduationServiceTest.java delete mode 100644 src/test/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateDualMandatoryMajorDetailGraduationServiceTest.java create mode 100644 src/test/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateMajorGraduationServiceTest.java delete mode 100644 src/test/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculatePrimaryBasicAcademicalCultureDetailGraduationServiceTest.java delete mode 100644 src/test/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculatePrimaryElectiveMajorDetailGraduationServiceTest.java delete mode 100644 src/test/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculatePrimaryMandatoryMajorDetailGraduationServiceTest.java create mode 100644 src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/GraduationCategoryTest.java create mode 100644 src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/MajorTypeTest.java rename src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/{BusinessBasicAcademicalManagerTest.java => BusinessBasicAcademicalGraduationManagerTest.java} (93%) rename src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/{DefaultBasicAcademicalManagerTest.java => DefaultBasicAcademicalGraduationManagerTest.java} (94%) rename src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/submajor/{SubMajorManagerTest.java => SubMajorGraduationManagerTest.java} (99%) diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateBasicAcademicalCultureGraduationService.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateBasicAcademicalCultureGraduationService.java new file mode 100644 index 00000000..6d49fe81 --- /dev/null +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateBasicAcademicalCultureGraduationService.java @@ -0,0 +1,102 @@ +package com.plzgraduate.myongjigraduatebe.graduation.application.service; + +import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.DUAL_BASIC_ACADEMICAL_CULTURE; +import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.PRIMARY_BASIC_ACADEMICAL_CULTURE; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.springframework.transaction.annotation.Transactional; + +import com.plzgraduate.myongjigraduatebe.core.meta.UseCase; +import com.plzgraduate.myongjigraduatebe.graduation.application.usecase.CalculateDetailGraduationUseCase; +import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailGraduationResult; +import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory; +import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationRequirement; +import com.plzgraduate.myongjigraduatebe.graduation.domain.model.MajorType; +import com.plzgraduate.myongjigraduatebe.graduation.domain.service.GraduationManager; +import com.plzgraduate.myongjigraduatebe.graduation.domain.service.basicacademicalculture.BasicAcademicalGraduationManager; +import com.plzgraduate.myongjigraduatebe.graduation.domain.service.basicacademicalculture.DefaultBasicAcademicalGraduationManager; +import com.plzgraduate.myongjigraduatebe.lecture.application.port.FindBasicAcademicalCulturePort; +import com.plzgraduate.myongjigraduatebe.lecture.domain.model.BasicAcademicalCultureLecture; +import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; +import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; +import com.plzgraduate.myongjigraduatebe.user.domain.model.StudentCategory; +import com.plzgraduate.myongjigraduatebe.user.domain.model.User; + +import lombok.RequiredArgsConstructor; + +@UseCase +@Transactional(readOnly = true) +@RequiredArgsConstructor +public class CalculateBasicAcademicalCultureGraduationService implements CalculateDetailGraduationUseCase { + + private final FindBasicAcademicalCulturePort findBasicAcademicalCulturePort; + private final List basicAcademicalGraduationManagers; + + @Override + public boolean supports(GraduationCategory graduationCategory) { + return graduationCategory == PRIMARY_BASIC_ACADEMICAL_CULTURE + || graduationCategory == DUAL_BASIC_ACADEMICAL_CULTURE; + } + + @Override + public DetailGraduationResult calculateSingleDetailGraduation(User user, GraduationCategory graduationCategory, + TakenLectureInventory takenLectureInventory, GraduationRequirement graduationRequirement) { + MajorType majorType = MajorType.from(graduationCategory); + String userMajor = user.getMajorByMajorType(majorType); + Set graduationBasicAcademicalCultureLectures = + findBasicAcademicalCulturePort.findBasicAcademicalCulture(userMajor); + GraduationManager basicAcademicalCultureGraduationManager = + determineBasicAcademicalCultureGraduationManager(userMajor); + DetailGraduationResult detailGraduationResult = basicAcademicalCultureGraduationManager.createDetailGraduationResult( + user, takenLectureInventory, graduationBasicAcademicalCultureLectures, + graduationRequirement.getBasicCreditByMajorType(majorType)); + detailGraduationResult.assignGraduationCategory(graduationCategory); + return detailGraduationResult; + } + + public List calculateAllDetailGraduation(User user, + TakenLectureInventory takenLectureInventory, GraduationRequirement graduationRequirement) { + if (user.getStudentCategory() == StudentCategory.DUAL_MAJOR) { + TakenLectureInventory copiedTakenLectureForPrimaryBasicAcademicalCulture = takenLectureInventory.copy(); + TakenLectureInventory copiedTakenLectureForDualBasicAcademicalCulture = takenLectureInventory.copy(); + DetailGraduationResult primaryBasicAcademicalCultureDetailGraduationResult = calculateSingleDetailGraduation( + user, PRIMARY_BASIC_ACADEMICAL_CULTURE, copiedTakenLectureForPrimaryBasicAcademicalCulture, + graduationRequirement); + DetailGraduationResult dualBasicAcademicalCultureDetailGraduationResult = calculateSingleDetailGraduation( + user, DUAL_BASIC_ACADEMICAL_CULTURE, copiedTakenLectureForDualBasicAcademicalCulture, + graduationRequirement); + syncOriginalTakenLectureInventory(takenLectureInventory, + primaryBasicAcademicalCultureDetailGraduationResult, dualBasicAcademicalCultureDetailGraduationResult); + return List.of(primaryBasicAcademicalCultureDetailGraduationResult, + dualBasicAcademicalCultureDetailGraduationResult); + } + DetailGraduationResult primaryBasicAcademicalCultureGraduationResult = calculateSingleDetailGraduation( + user, PRIMARY_BASIC_ACADEMICAL_CULTURE, takenLectureInventory, graduationRequirement); + return List.of(primaryBasicAcademicalCultureGraduationResult); + } + + private GraduationManager determineBasicAcademicalCultureGraduationManager( + String userMajor) { + return basicAcademicalGraduationManagers.stream() + .filter(basicAcademicalManager -> basicAcademicalManager.isSatisfied(userMajor)) + .findFirst() + .orElse(new DefaultBasicAcademicalGraduationManager()); + } + + private void syncOriginalTakenLectureInventory(TakenLectureInventory originalTakenLectureInventory, + DetailGraduationResult primaryBasicAcademicalCultureDetailGraduationResult, + DetailGraduationResult dualBasicAcademicalCultureDetailGraduationResult) { + List primaryBasicAcademicalCultureTakenLectures = + primaryBasicAcademicalCultureDetailGraduationResult.getDetailCategory().get(0).getTakenLectures(); + List dualBasicAcademicalCultureTakenLectures = + dualBasicAcademicalCultureDetailGraduationResult.getDetailCategory().get(0).getTakenLectures(); + + Set basicAcademicalCultureTakenLectures = new HashSet<>(); + basicAcademicalCultureTakenLectures.addAll(primaryBasicAcademicalCultureTakenLectures); + basicAcademicalCultureTakenLectures.addAll(dualBasicAcademicalCultureTakenLectures); + originalTakenLectureInventory.sync(basicAcademicalCultureTakenLectures); + } +} diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateCommonCultureGraduationService.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateCommonCultureGraduationService.java index 977b7421..7ace4a10 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateCommonCultureGraduationService.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateCommonCultureGraduationService.java @@ -4,16 +4,14 @@ import java.util.Set; -import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import com.plzgraduate.myongjigraduatebe.core.meta.UseCase; -import com.plzgraduate.myongjigraduatebe.graduation.application.usecase.CalculateCommonCultureGraduationUseCase; +import com.plzgraduate.myongjigraduatebe.graduation.application.usecase.CalculateDetailGraduationUseCase; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailGraduationResult; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationRequirement; -import com.plzgraduate.myongjigraduatebe.graduation.domain.service.GraduationManager; -import com.plzgraduate.myongjigraduatebe.graduation.domain.service.commonculture.CommonCultureGraduationManager; +import com.plzgraduate.myongjigraduatebe.graduation.domain.service.commonculture.CommonGraduationManager; import com.plzgraduate.myongjigraduatebe.lecture.application.port.FindCommonCulturePort; import com.plzgraduate.myongjigraduatebe.lecture.domain.model.CommonCulture; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; @@ -24,9 +22,10 @@ @UseCase @Transactional(readOnly = true) @RequiredArgsConstructor -public class CalculateCommonCultureGraduationService implements CalculateCommonCultureGraduationUseCase { +public class CalculateCommonCultureGraduationService implements CalculateDetailGraduationUseCase { private final FindCommonCulturePort findCommonCulturePort; + private final CommonGraduationManager commonCultureGraduationManager; @Override public boolean supports(GraduationCategory graduationCategory) { @@ -34,12 +33,10 @@ public boolean supports(GraduationCategory graduationCategory) { } @Override - public DetailGraduationResult calculateDetailGraduation(User user, TakenLectureInventory takenLectureInventory, - GraduationRequirement graduationRequirement) { + public DetailGraduationResult calculateSingleDetailGraduation(User user, GraduationCategory graduationCategory, + TakenLectureInventory takenLectureInventory, GraduationRequirement graduationRequirement) { Set graduationCommonCultures = findCommonCulturePort.findCommonCulture(user); - GraduationManager commonCultureGraduationManager = new CommonCultureGraduationManager(); return commonCultureGraduationManager.createDetailGraduationResult( user, takenLectureInventory, graduationCommonCultures, graduationRequirement.getCommonCultureCredit()); } - } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateCoreCultureGraduationService.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateCoreCultureGraduationService.java index fbe7c073..d5422e28 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateCoreCultureGraduationService.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateCoreCultureGraduationService.java @@ -4,19 +4,15 @@ import java.util.Set; -import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import com.plzgraduate.myongjigraduatebe.core.meta.UseCase; -import com.plzgraduate.myongjigraduatebe.graduation.application.usecase.CalculateCoreCultureGraduationUseCase; +import com.plzgraduate.myongjigraduatebe.graduation.application.usecase.CalculateDetailGraduationUseCase; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailGraduationResult; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationRequirement; -import com.plzgraduate.myongjigraduatebe.graduation.domain.service.GraduationManager; -import com.plzgraduate.myongjigraduatebe.graduation.domain.service.commonculture.CommonCultureGraduationManager; -import com.plzgraduate.myongjigraduatebe.graduation.domain.service.coreculture.CoreCultureGraduationManager; +import com.plzgraduate.myongjigraduatebe.graduation.domain.service.coreculture.CoreGraduationManager; import com.plzgraduate.myongjigraduatebe.lecture.application.port.FindCoreCulturePort; -import com.plzgraduate.myongjigraduatebe.lecture.domain.model.CommonCulture; import com.plzgraduate.myongjigraduatebe.lecture.domain.model.CoreCulture; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; @@ -26,10 +22,10 @@ @UseCase @Transactional(readOnly = true) @RequiredArgsConstructor -public class CalculateCoreCultureGraduationService - implements CalculateCoreCultureGraduationUseCase { +public class CalculateCoreCultureGraduationService implements CalculateDetailGraduationUseCase { private final FindCoreCulturePort findCoreCulturePort; + private final CoreGraduationManager coreCultureGraduationManager; @Override public boolean supports(GraduationCategory graduationCategory) { @@ -37,10 +33,9 @@ public boolean supports(GraduationCategory graduationCategory) { } @Override - public DetailGraduationResult calculateDetailGraduation(User user, TakenLectureInventory takenLectureInventory, - GraduationRequirement graduationRequirement) { + public DetailGraduationResult calculateSingleDetailGraduation(User user, GraduationCategory graduationCategory, + TakenLectureInventory takenLectureInventory, GraduationRequirement graduationRequirement) { Set graduationCoreCultures = findCoreCulturePort.findCoreCulture(user); - GraduationManager coreCultureGraduationManager = new CoreCultureGraduationManager(); return coreCultureGraduationManager.createDetailGraduationResult( user, takenLectureInventory, graduationCoreCultures, graduationRequirement.getCoreCultureCredit()); } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateDualBasicAcademicalCultureDetailGraduationService.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateDualBasicAcademicalCultureDetailGraduationService.java deleted file mode 100644 index b2de4ffb..00000000 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateDualBasicAcademicalCultureDetailGraduationService.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.plzgraduate.myongjigraduatebe.graduation.application.service; - -import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.DUAL_BASIC_ACADEMICAL_CULTURE; - -import java.util.List; -import java.util.Set; - -import org.springframework.transaction.annotation.Transactional; - -import com.plzgraduate.myongjigraduatebe.core.meta.UseCase; -import com.plzgraduate.myongjigraduatebe.graduation.application.usecase.CalculateDualBasicAcademicalCultureDetailGraduationUseCase; -import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailGraduationResult; -import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory; -import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationRequirement; -import com.plzgraduate.myongjigraduatebe.graduation.domain.service.GraduationManager; -import com.plzgraduate.myongjigraduatebe.graduation.domain.service.basicacademicalculture.BasicAcademicalManager; -import com.plzgraduate.myongjigraduatebe.graduation.domain.service.basicacademicalculture.BusinessBasicAcademicalManager; -import com.plzgraduate.myongjigraduatebe.graduation.domain.service.basicacademicalculture.DefaultBasicAcademicalManager; -import com.plzgraduate.myongjigraduatebe.graduation.domain.service.basicacademicalculture.SocialScienceBasicAcademicManager; -import com.plzgraduate.myongjigraduatebe.lecture.application.port.FindBasicAcademicalCulturePort; -import com.plzgraduate.myongjigraduatebe.lecture.domain.model.BasicAcademicalCultureLecture; -import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; -import com.plzgraduate.myongjigraduatebe.user.domain.model.User; - -import lombok.RequiredArgsConstructor; - -@UseCase -@Transactional(readOnly = true) -@RequiredArgsConstructor -public class CalculateDualBasicAcademicalCultureDetailGraduationService implements - CalculateDualBasicAcademicalCultureDetailGraduationUseCase { - - private final FindBasicAcademicalCulturePort findBasicAcademicalCulturePort; - - @Override - public boolean supports(GraduationCategory graduationCategory) { - return graduationCategory == DUAL_BASIC_ACADEMICAL_CULTURE; - } - - @Override - public DetailGraduationResult calculateDetailGraduation(User user, TakenLectureInventory takenLectureInventory, - GraduationRequirement graduationRequirement) { - Set graduationBasicAcademicalCultureLectures = findBasicAcademicalCulturePort.findBasicAcademicalCulture( - user.getDualMajor()); - GraduationManager basicAcademicalCultureGraduationManager = determineBasicAcademicalCultureGraduationManager( - user); - DetailGraduationResult detailGraduationResult = basicAcademicalCultureGraduationManager.createDetailGraduationResult( - user, takenLectureInventory, graduationBasicAcademicalCultureLectures, - graduationRequirement.getDualBasicAcademicalCultureCredit()); - detailGraduationResult.assignGraduationCategory(DUAL_BASIC_ACADEMICAL_CULTURE); - return detailGraduationResult; - } - - private GraduationManager determineBasicAcademicalCultureGraduationManager( - User user) { - List basicAcademicalManagers = List.of( - new BusinessBasicAcademicalManager(), - new SocialScienceBasicAcademicManager()); - - return basicAcademicalManagers.stream() - .filter(basicAcademicalManager -> basicAcademicalManager.isSatisfied(user.getDualMajor())) - .findFirst() - .orElse(new DefaultBasicAcademicalManager()); - } -} diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateDualElectiveMajorDetailGraduationService.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateDualElectiveMajorDetailGraduationService.java deleted file mode 100644 index bf6879bf..00000000 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateDualElectiveMajorDetailGraduationService.java +++ /dev/null @@ -1,70 +0,0 @@ -package com.plzgraduate.myongjigraduatebe.graduation.application.service; - -import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.DUAL_ELECTIVE_MAJOR; -import static com.plzgraduate.myongjigraduatebe.graduation.domain.service.major.MajorGraduationCategory.DUAL; - -import java.util.List; -import java.util.Set; - -import org.springframework.transaction.annotation.Transactional; - -import com.plzgraduate.myongjigraduatebe.core.meta.UseCase; -import com.plzgraduate.myongjigraduatebe.graduation.application.usecase.CalculateDualElectiveMajorDetailGraduationUseCase; -import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailCategoryResult; -import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailGraduationResult; -import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory; -import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationRequirement; -import com.plzgraduate.myongjigraduatebe.graduation.domain.service.GraduationManager; -import com.plzgraduate.myongjigraduatebe.graduation.domain.service.major.MajorManager; -import com.plzgraduate.myongjigraduatebe.lecture.application.port.FindMajorPort; -import com.plzgraduate.myongjigraduatebe.lecture.domain.model.MajorLecture; -import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; -import com.plzgraduate.myongjigraduatebe.user.domain.model.User; - -import lombok.RequiredArgsConstructor; - -@UseCase -@Transactional(readOnly = true) -@RequiredArgsConstructor -public class CalculateDualElectiveMajorDetailGraduationService - implements CalculateDualElectiveMajorDetailGraduationUseCase { - - private final FindMajorPort findMajorPort; - - @Override - public boolean supports(GraduationCategory graduationCategory) { - return graduationCategory == DUAL_ELECTIVE_MAJOR; - } - - @Override - public DetailGraduationResult calculateDetailGraduation(User user, TakenLectureInventory takenLectureInventory, - GraduationRequirement graduationRequirement) { - Set graduationMajorLectures = findMajorPort.findMajor(user.getDualMajor()); - GraduationManager majorGraduationManager = new MajorManager(DUAL); - DetailGraduationResult majorDetailGraduationResult = majorGraduationManager.createDetailGraduationResult(user, - takenLectureInventory, graduationMajorLectures, graduationRequirement.getDualMajorCredit()); - - DetailCategoryResult electiveMajorDetailCategoryResult = separateElectiveMajor(majorDetailGraduationResult); - return DetailGraduationResult.create(DUAL_ELECTIVE_MAJOR, electiveMajorDetailCategoryResult.getTotalCredits(), - List.of(electiveMajorDetailCategoryResult)); - } - - @Override - public DetailGraduationResult isolateDualElectiveMajorDetailGraduation( - DetailGraduationResult dualMajorDetailGraduationResult) { - DetailCategoryResult electiveMajorDetailCategoryResult = separateElectiveMajor( - dualMajorDetailGraduationResult); - return DetailGraduationResult.create(DUAL_ELECTIVE_MAJOR, - electiveMajorDetailCategoryResult.getTotalCredits(), List.of(electiveMajorDetailCategoryResult)); - } - - private DetailCategoryResult separateElectiveMajor( - DetailGraduationResult majorDetailGraduationResult) { - DetailCategoryResult dualElectiveMajorDetailCategoryResult = majorDetailGraduationResult.getDetailCategory().stream() - .filter(detailCategoryResult -> detailCategoryResult.getDetailCategoryName().equals("전공선택")) - .findFirst() - .orElseThrow(() -> new RuntimeException("Not Found DetailCategoryResult(전공 선택)")); - dualElectiveMajorDetailCategoryResult.assignDetailCategoryName("복수전공선택"); - return dualElectiveMajorDetailCategoryResult; - } -} diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateDualMandatoryMajorDetailGraduationService.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateDualMandatoryMajorDetailGraduationService.java deleted file mode 100644 index f358e3d1..00000000 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateDualMandatoryMajorDetailGraduationService.java +++ /dev/null @@ -1,70 +0,0 @@ -package com.plzgraduate.myongjigraduatebe.graduation.application.service; - -import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.DUAL_MANDATORY_MAJOR; -import static com.plzgraduate.myongjigraduatebe.graduation.domain.service.major.MajorGraduationCategory.DUAL; - -import java.util.List; -import java.util.Set; - -import org.springframework.transaction.annotation.Transactional; - -import com.plzgraduate.myongjigraduatebe.core.meta.UseCase; -import com.plzgraduate.myongjigraduatebe.graduation.application.usecase.CalculateDualMandatoryMajorDetailGraduationUseCase; -import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailCategoryResult; -import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailGraduationResult; -import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory; -import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationRequirement; -import com.plzgraduate.myongjigraduatebe.graduation.domain.service.GraduationManager; -import com.plzgraduate.myongjigraduatebe.graduation.domain.service.major.MajorManager; -import com.plzgraduate.myongjigraduatebe.lecture.application.port.FindMajorPort; -import com.plzgraduate.myongjigraduatebe.lecture.domain.model.MajorLecture; -import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; -import com.plzgraduate.myongjigraduatebe.user.domain.model.User; - -import lombok.RequiredArgsConstructor; - -@UseCase -@Transactional(readOnly = true) -@RequiredArgsConstructor -public class CalculateDualMandatoryMajorDetailGraduationService - implements CalculateDualMandatoryMajorDetailGraduationUseCase { - - private final FindMajorPort findMajorPort; - - @Override - public boolean supports(GraduationCategory graduationCategory) { - return graduationCategory == DUAL_MANDATORY_MAJOR; - } - - @Override - public DetailGraduationResult calculateDetailGraduation(User user, TakenLectureInventory takenLectureInventory, - GraduationRequirement graduationRequirement) { - Set graduationMajorLectures = findMajorPort.findMajor(user.getDualMajor()); - GraduationManager majorGraduationManager = new MajorManager(DUAL); - DetailGraduationResult majorDetailGraduationResult = majorGraduationManager.createDetailGraduationResult(user, - takenLectureInventory, graduationMajorLectures, graduationRequirement.getDualMajorCredit()); - - DetailCategoryResult mandatoryMajorDetailCategoryResult = separateMandatoryMajor(majorDetailGraduationResult); - return DetailGraduationResult.create(DUAL_MANDATORY_MAJOR, - mandatoryMajorDetailCategoryResult.getTotalCredits(), List.of(mandatoryMajorDetailCategoryResult)); - } - - @Override - public DetailGraduationResult isolateDualMandatoryMajorDetailGraduation( - DetailGraduationResult dualMajorDetailGraduationResult) { - DetailCategoryResult mandatoryMajorDetailCategoryResult = separateMandatoryMajor( - dualMajorDetailGraduationResult); - return DetailGraduationResult.create(DUAL_MANDATORY_MAJOR, - mandatoryMajorDetailCategoryResult.getTotalCredits(), List.of(mandatoryMajorDetailCategoryResult)); - } - - private DetailCategoryResult separateMandatoryMajor( - DetailGraduationResult majorDetailGraduationResult) { - DetailCategoryResult dualMandatoryMajorDetailCategoryResult = majorDetailGraduationResult.getDetailCategory().stream() - .filter(detailCategoryResult -> detailCategoryResult.getDetailCategoryName().equals("전공필수")) - .findFirst() - .orElseThrow(() -> new RuntimeException("Not Found DetailCategoryResult(전공 필수)")); - dualMandatoryMajorDetailCategoryResult.assignDetailCategoryName("복수전공필수"); - return dualMandatoryMajorDetailCategoryResult; - } -} diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateGraduationService.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateGraduationService.java index 15bfb9fa..c9dd1c3d 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateGraduationService.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateGraduationService.java @@ -1,37 +1,19 @@ package com.plzgraduate.myongjigraduatebe.graduation.application.service; -import static com.plzgraduate.myongjigraduatebe.graduation.domain.service.major.MajorGraduationCategory.DUAL; -import static com.plzgraduate.myongjigraduatebe.graduation.domain.service.major.MajorGraduationCategory.PRIMARY; - import java.util.ArrayList; -import java.util.HashSet; import java.util.List; -import java.util.Set; import org.springframework.transaction.annotation.Transactional; import com.plzgraduate.myongjigraduatebe.core.meta.UseCase; -import com.plzgraduate.myongjigraduatebe.graduation.application.usecase.CalculateCommonCultureGraduationUseCase; -import com.plzgraduate.myongjigraduatebe.graduation.application.usecase.CalculateCoreCultureGraduationUseCase; -import com.plzgraduate.myongjigraduatebe.graduation.application.usecase.CalculateDualBasicAcademicalCultureDetailGraduationUseCase; -import com.plzgraduate.myongjigraduatebe.graduation.application.usecase.CalculateDualElectiveMajorDetailGraduationUseCase; -import com.plzgraduate.myongjigraduatebe.graduation.application.usecase.CalculateDualMandatoryMajorDetailGraduationUseCase; import com.plzgraduate.myongjigraduatebe.graduation.application.usecase.CalculateGraduationUseCase; -import com.plzgraduate.myongjigraduatebe.graduation.application.usecase.CalculatePrimaryBasicAcademicalCultureDetailGraduationUseCase; -import com.plzgraduate.myongjigraduatebe.graduation.application.usecase.CalculatePrimaryElectiveMajorDetailGraduationUseCase; -import com.plzgraduate.myongjigraduatebe.graduation.application.usecase.CalculatePrimaryMandatoryMajorDetailGraduationUseCase; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.ChapelResult; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DefaultGraduationRequirementType; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailGraduationResult; +import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationRequirement; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationResult; -import com.plzgraduate.myongjigraduatebe.graduation.domain.service.GraduationManager; -import com.plzgraduate.myongjigraduatebe.graduation.domain.service.major.MajorManager; -import com.plzgraduate.myongjigraduatebe.graduation.domain.service.submajor.SubMajorManager; import com.plzgraduate.myongjigraduatebe.lecture.application.port.FindBasicAcademicalCulturePort; -import com.plzgraduate.myongjigraduatebe.lecture.application.port.FindMajorPort; -import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; -import com.plzgraduate.myongjigraduatebe.lecture.domain.model.MajorLecture; import com.plzgraduate.myongjigraduatebe.takenlecture.application.usecase.find.FindTakenLectureUseCase; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; import com.plzgraduate.myongjigraduatebe.user.application.usecase.update.UpdateStudentInformationCommand; @@ -43,22 +25,16 @@ import lombok.RequiredArgsConstructor; @UseCase -@Transactional(readOnly = true) +@Transactional @RequiredArgsConstructor class CalculateGraduationService implements CalculateGraduationUseCase { - private final FindMajorPort findMajorPort; private final FindBasicAcademicalCulturePort findBasicAcademicalCulturePort; - private final FindTakenLectureUseCase findTakenLectureUseCase; - private final CalculateCommonCultureGraduationUseCase calculateCommonCultureGraduationUseCase; - private final CalculateCoreCultureGraduationUseCase calculateCoreCultureGraduationUseCase; - private final CalculatePrimaryMandatoryMajorDetailGraduationUseCase calculatePrimaryMandatoryMajorDetailGraduationUseCase; - private final CalculatePrimaryElectiveMajorDetailGraduationUseCase calculatePrimaryElectiveMajorDetailGraduationUseCase; - private final CalculatePrimaryBasicAcademicalCultureDetailGraduationUseCase calculatePrimaryBasicAcademicalCultureDetailGraduationUseCase; - private final CalculateDualMandatoryMajorDetailGraduationUseCase calculateDualMandatoryMajorDetailGraduationUseCase; - private final CalculateDualElectiveMajorDetailGraduationUseCase calculateDualElectiveMajorDetailGraduationUseCase; - private final CalculateDualBasicAcademicalCultureDetailGraduationUseCase calculateDualBasicAcademicalCultureDetailGraduationUseCase; + private final CalculateCommonCultureGraduationService calculateCommonCultureGraduationService; + private final CalculateCoreCultureGraduationService calculateCoreCultureGraduationService; + private final CalculateBasicAcademicalCultureGraduationService calculateBasicAcademicalCultureGraduationService; + private final CalculateMajorGraduationService calculateMajorGraduationService; private final UpdateStudentInformationUseCase updateStudentInformationUseCase; @Override @@ -77,16 +53,6 @@ public GraduationResult calculateGraduation(User user) { return graduationResult; } - private void handleDuplicatedTakenCredit(User user, GraduationResult graduationResult) { - if (user.getStudentCategory() == StudentCategory.DUAL_MAJOR) { - int duplicatedBasicAcademicalCultureCredit = - findBasicAcademicalCulturePort.findDuplicatedLecturesBetweenMajors(user).stream() - .mapToInt(basicAcademicalCulture -> basicAcademicalCulture.getLecture().getCredit()) - .sum(); - graduationResult.deductDuplicatedCredit(duplicatedBasicAcademicalCultureCredit); - } - } - private GraduationRequirement determineGraduationRequirement(User user) { College userCollage = College.findBelongingCollege(user.getPrimaryMajor()); DefaultGraduationRequirementType defaultGraduationRequirement = DefaultGraduationRequirementType.determineGraduationRequirement( @@ -108,105 +74,35 @@ private List generateDetailGraduationResults(User user, generateCoreCultureDetailGraduationResult( user, takenLectureInventory, graduationRequirement) )); - detailGraduationResults.addAll( - generatePrimaryMajorDetailGraduations(user, takenLectureInventory, graduationRequirement)); detailGraduationResults.addAll(generateBasicAcademicalDetailGraduationResult( user, takenLectureInventory, graduationRequirement)); - if (user.getStudentCategory() == StudentCategory.DUAL_MAJOR) { - detailGraduationResults.addAll( - generateDualMajorDetailGraduations(user, takenLectureInventory, graduationRequirement)); - } - if (user.getStudentCategory() == StudentCategory.SUB_MAJOR) { - detailGraduationResults.add( - generateSubMajorDetailGraduationResult(user, takenLectureInventory, graduationRequirement)); - } - + detailGraduationResults.addAll(generateMajorDetailGraduationResult( + user, takenLectureInventory, graduationRequirement)); return detailGraduationResults; } private DetailGraduationResult generateCommonCultureDetailGraduationResult(User user, TakenLectureInventory takenLectureInventory, GraduationRequirement graduationRequirement) { - return calculateCommonCultureGraduationUseCase.calculateDetailGraduation(user, takenLectureInventory, - graduationRequirement); + return calculateCommonCultureGraduationService.calculateSingleDetailGraduation(user, + GraduationCategory.COMMON_CULTURE, takenLectureInventory, graduationRequirement); } private DetailGraduationResult generateCoreCultureDetailGraduationResult(User user, TakenLectureInventory takenLectureInventory, GraduationRequirement graduationRequirement) { - return calculateCoreCultureGraduationUseCase.calculateDetailGraduation(user, takenLectureInventory, - graduationRequirement); + return calculateCoreCultureGraduationService.calculateSingleDetailGraduation(user, + GraduationCategory.CORE_CULTURE, takenLectureInventory, graduationRequirement); } private List generateBasicAcademicalDetailGraduationResult(User user, TakenLectureInventory takenLectureInventory, GraduationRequirement graduationRequirement) { - if (user.getStudentCategory() == StudentCategory.DUAL_MAJOR) { - TakenLectureInventory copiedTakenLectureForPrimaryBasicAcademicalCulture = takenLectureInventory.copy(); - TakenLectureInventory copiedTakenLectureForDualBasicAcademicalCulture = takenLectureInventory.copy(); - DetailGraduationResult primaryBasicAcademicalCultureDetailGraduationResult = calculatePrimaryBasicAcademicalCultureDetailGraduationUseCase.calculateDetailGraduation( - user, copiedTakenLectureForPrimaryBasicAcademicalCulture, graduationRequirement); - DetailGraduationResult dualBasicAcademicalCultureDetailGraduationResult = calculateDualBasicAcademicalCultureDetailGraduationUseCase.calculateDetailGraduation( - user, copiedTakenLectureForDualBasicAcademicalCulture, graduationRequirement); - syncOriginalTakenLectureInventory(takenLectureInventory, - primaryBasicAcademicalCultureDetailGraduationResult, - dualBasicAcademicalCultureDetailGraduationResult); - return List.of(primaryBasicAcademicalCultureDetailGraduationResult, - dualBasicAcademicalCultureDetailGraduationResult); - } - DetailGraduationResult primaryBasicAcademicalCultureGraduationResult = calculatePrimaryBasicAcademicalCultureDetailGraduationUseCase.calculateDetailGraduation( - user, takenLectureInventory, graduationRequirement); - return List.of(primaryBasicAcademicalCultureGraduationResult); - } - - private void syncOriginalTakenLectureInventory(TakenLectureInventory originalTakenLectureInventory, - DetailGraduationResult primaryBasicAcademicalCultureDetailGraduationResult, - DetailGraduationResult dualBasicAcademicalCultureDetailGraduationResult) { - List primaryBasicAcademicalCultureTakenLectures = primaryBasicAcademicalCultureDetailGraduationResult.getDetailCategory() - .get(0) - .getTakenLectures(); - List dualBasicAcademicalCultureTakenLectures = dualBasicAcademicalCultureDetailGraduationResult.getDetailCategory() - .get(0) - .getTakenLectures(); - Set basicAcademicalCultureTakenLectures = new HashSet<>(); - basicAcademicalCultureTakenLectures.addAll(primaryBasicAcademicalCultureTakenLectures); - basicAcademicalCultureTakenLectures.addAll(dualBasicAcademicalCultureTakenLectures); - originalTakenLectureInventory.handleFinishedLectures(basicAcademicalCultureTakenLectures); - } - - private List generatePrimaryMajorDetailGraduations(User user, - TakenLectureInventory takenLectureInventory, GraduationRequirement graduationRequirement) { - Set graduationPrimaryMajorLectures = findMajorPort.findMajor(user.getPrimaryMajor()); - - GraduationManager majorManager = new MajorManager(PRIMARY); - DetailGraduationResult primaryMajorDetailGraduationResult = majorManager.createDetailGraduationResult(user, - takenLectureInventory, graduationPrimaryMajorLectures, graduationRequirement.getPrimaryMajorCredit()); - DetailGraduationResult primaryMandatoryMajorDetailGraduationResult = calculatePrimaryMandatoryMajorDetailGraduationUseCase.isolatePrimaryMandatoryMajorDetailGraduation( - primaryMajorDetailGraduationResult); - DetailGraduationResult primaryElectiveMajorDetailGraduationResult = calculatePrimaryElectiveMajorDetailGraduationUseCase.isolatePrimaryElectiveMajorDetailGraduation( - primaryMajorDetailGraduationResult); - - return List.of(primaryMandatoryMajorDetailGraduationResult, primaryElectiveMajorDetailGraduationResult); - } - - private List generateDualMajorDetailGraduations(User user, - TakenLectureInventory takenLectureInventory, GraduationRequirement graduationRequirement) { - Set graduationDualMajorLectures = findMajorPort.findMajor(user.getDualMajor()); - - GraduationManager majorManager = new MajorManager(DUAL); - DetailGraduationResult dualMajorDetailGraduationResult = majorManager.createDetailGraduationResult(user, - takenLectureInventory, graduationDualMajorLectures, graduationRequirement.getDualMajorCredit()); - DetailGraduationResult dualMandatoryMajorDetailGraduationResult = calculateDualMandatoryMajorDetailGraduationUseCase.isolateDualMandatoryMajorDetailGraduation( - dualMajorDetailGraduationResult); - DetailGraduationResult dualElectiveMajorDetailGraduationResult = calculateDualElectiveMajorDetailGraduationUseCase.isolateDualElectiveMajorDetailGraduation( - dualMajorDetailGraduationResult); - - return List.of(dualMandatoryMajorDetailGraduationResult, dualElectiveMajorDetailGraduationResult); + return calculateBasicAcademicalCultureGraduationService.calculateAllDetailGraduation(user, + takenLectureInventory, graduationRequirement); } - private DetailGraduationResult generateSubMajorDetailGraduationResult(User user, + private List generateMajorDetailGraduationResult(User user, TakenLectureInventory takenLectureInventory, GraduationRequirement graduationRequirement) { - Set graduationSubMajorLectures = findMajorPort.findMajor(user.getSubMajor()); - GraduationManager subMajorManager = new SubMajorManager(); - return subMajorManager.createDetailGraduationResult(user, takenLectureInventory, graduationSubMajorLectures, - graduationRequirement.getSubMajorCredit()); + return calculateMajorGraduationService.calculateAllDetailGraduation(user, takenLectureInventory, + graduationRequirement); } private GraduationResult generateGraduationResult(ChapelResult chapelResult, @@ -218,18 +114,19 @@ private GraduationResult generateGraduationResult(ChapelResult chapelResult, return graduationResult; } + private void handleDuplicatedTakenCredit(User user, GraduationResult graduationResult) { + if (user.getStudentCategory() == StudentCategory.DUAL_MAJOR) { + int duplicatedBasicAcademicalCultureCredit = + findBasicAcademicalCulturePort.findDuplicatedLecturesBetweenMajors(user).stream() + .mapToInt(basicAcademicalCulture -> basicAcademicalCulture.getLecture().getCredit()) + .sum(); + graduationResult.deductDuplicatedCredit(duplicatedBasicAcademicalCultureCredit); + } + } + private void updateUserGraduationInformation(User user, GraduationResult graduationResult) { - UpdateStudentInformationCommand updateStudentInformationCommand = UpdateStudentInformationCommand.builder() - .user(user) - .name(user.getName()) - .studentCategory(user.getStudentCategory()) - .major(user.getPrimaryMajor()) - .dualMajor(user.getDualMajor()) - .subMajor(user.getSubMajor()) - .totalCredit(graduationResult.getTotalCredit()) - .takenCredit(graduationResult.getTakenCredit()) - .graduate(graduationResult.isGraduated()) - .build(); + UpdateStudentInformationCommand updateStudentInformationCommand = UpdateStudentInformationCommand.update(user, + graduationResult); updateStudentInformationUseCase.updateUser(updateStudentInformationCommand); } } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateMajorGraduationService.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateMajorGraduationService.java new file mode 100644 index 00000000..179e3683 --- /dev/null +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateMajorGraduationService.java @@ -0,0 +1,161 @@ +package com.plzgraduate.myongjigraduatebe.graduation.application.service; + +import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.DUAL_ELECTIVE_MAJOR; +import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.DUAL_MANDATORY_MAJOR; +import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.PRIMARY_ELECTIVE_MAJOR; +import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.PRIMARY_MANDATORY_MAJOR; +import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.SUB_MAJOR; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +import org.springframework.transaction.annotation.Transactional; + +import com.plzgraduate.myongjigraduatebe.core.meta.UseCase; +import com.plzgraduate.myongjigraduatebe.graduation.application.usecase.CalculateDetailGraduationUseCase; +import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailCategoryResult; +import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailGraduationResult; +import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory; +import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationRequirement; +import com.plzgraduate.myongjigraduatebe.graduation.domain.model.MajorType; +import com.plzgraduate.myongjigraduatebe.graduation.domain.service.major.MajorGraduationManager; +import com.plzgraduate.myongjigraduatebe.graduation.domain.service.submajor.SubMajorGraduationManager; +import com.plzgraduate.myongjigraduatebe.lecture.application.port.FindMajorPort; +import com.plzgraduate.myongjigraduatebe.lecture.domain.model.MajorLecture; +import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; +import com.plzgraduate.myongjigraduatebe.user.domain.model.StudentCategory; +import com.plzgraduate.myongjigraduatebe.user.domain.model.User; + +import lombok.RequiredArgsConstructor; + +@UseCase +@Transactional(readOnly = true) +@RequiredArgsConstructor +public class CalculateMajorGraduationService implements CalculateDetailGraduationUseCase { + + private final FindMajorPort findMajorPort; + private final MajorGraduationManager majorGraduationManager; + private final SubMajorGraduationManager subMajorGraduationManager; + + @Override + public boolean supports(GraduationCategory graduationCategory) { + return graduationCategory == PRIMARY_MANDATORY_MAJOR + || graduationCategory == PRIMARY_ELECTIVE_MAJOR + || graduationCategory == DUAL_MANDATORY_MAJOR + || graduationCategory == DUAL_ELECTIVE_MAJOR + || graduationCategory == SUB_MAJOR; + } + + @Override + public DetailGraduationResult calculateSingleDetailGraduation(User user, GraduationCategory graduationCategory, + TakenLectureInventory takenLectureInventory, GraduationRequirement graduationRequirement) { + MajorType majorType = MajorType.from(graduationCategory); + + if (majorType == MajorType.SUB) { + return generateSubMajorDetailGraduationResult(user, takenLectureInventory, graduationRequirement); + } + + DetailGraduationResult majorDetailGraduationResult = generateMajorDetailGraduationResult(user, + majorType, takenLectureInventory, graduationRequirement); + + boolean isMandatory = graduationCategory.checkMandatoryIfSeperatedByMandatoryAndElective(); + + if (isMandatory) { + DetailCategoryResult majorDetailCategoryResult = separateMandatoryMajor(graduationCategory, + majorDetailGraduationResult); + return DetailGraduationResult.create(graduationCategory, + majorDetailCategoryResult.getTotalCredits(), List.of(majorDetailCategoryResult)); + } + + DetailCategoryResult majorDetailCategoryResult = separateElectiveMajor(graduationCategory, + majorDetailGraduationResult); + return DetailGraduationResult.create(graduationCategory, + majorDetailCategoryResult.getTotalCredits(), List.of(majorDetailCategoryResult)); + } + + public List calculateAllDetailGraduation(User user, + TakenLectureInventory takenLectureInventory, GraduationRequirement graduationRequirement) { + + DetailGraduationResult primaryMajorDetailGraduationResult = generateMajorDetailGraduationResult(user, + MajorType.PRIMARY, takenLectureInventory, graduationRequirement); + DetailGraduationResult primaryMandatoryMajorDetailGraduationResult = isolateMandatoryMajorDetailGraduation( + PRIMARY_MANDATORY_MAJOR, primaryMajorDetailGraduationResult); + DetailGraduationResult primaryElectiveMajorDetailGraduationResult = isolateElectiveMajorDetailGraduation( + PRIMARY_ELECTIVE_MAJOR, primaryMajorDetailGraduationResult); + + List majorGraduationResults = new ArrayList<>( + List.of(primaryMandatoryMajorDetailGraduationResult, primaryElectiveMajorDetailGraduationResult)); + + if (user.getStudentCategory() == StudentCategory.DUAL_MAJOR) { + DetailGraduationResult dualMajorDetailGraduationResult = generateMajorDetailGraduationResult(user, + MajorType.DUAL, takenLectureInventory, graduationRequirement); + DetailGraduationResult dualMandatoryMajorDetailGraduationResult = isolateMandatoryMajorDetailGraduation( + DUAL_MANDATORY_MAJOR, dualMajorDetailGraduationResult); + DetailGraduationResult dualElectiveMajorDetailGraduationResult = isolateElectiveMajorDetailGraduation( + DUAL_ELECTIVE_MAJOR, dualMajorDetailGraduationResult); + majorGraduationResults.addAll( + List.of(dualMandatoryMajorDetailGraduationResult, dualElectiveMajorDetailGraduationResult)); + } + if (user.getStudentCategory() == StudentCategory.SUB_MAJOR) { + majorGraduationResults.add( + generateSubMajorDetailGraduationResult(user, takenLectureInventory, graduationRequirement)); + } + return majorGraduationResults; + } + + private DetailGraduationResult generateMajorDetailGraduationResult(User user, MajorType majorType, + TakenLectureInventory takenLectureInventory, + GraduationRequirement graduationRequirement) { + Set graduationMajorLectures = findMajorPort.findMajor(user.getMajorByMajorType(majorType)); + return majorGraduationManager.createDetailGraduationResult(user, majorType, + takenLectureInventory, graduationMajorLectures, graduationRequirement.getMajorCreditByMajorType(majorType)); + } + + private DetailGraduationResult generateSubMajorDetailGraduationResult(User user, + TakenLectureInventory takenLectureInventory, + GraduationRequirement graduationRequirement) { + Set graduationSubMajorLectures = findMajorPort.findMajor(user.getSubMajor()); + return subMajorGraduationManager.createDetailGraduationResult(user, takenLectureInventory, + graduationSubMajorLectures, + graduationRequirement.getSubMajorCredit()); + } + + private DetailGraduationResult isolateMandatoryMajorDetailGraduation( + GraduationCategory graduationCategory, DetailGraduationResult majorDetailGraduationResult) { + DetailCategoryResult mandatoryMajorDetailCategoryResult = separateMandatoryMajor( + graduationCategory, majorDetailGraduationResult); + return DetailGraduationResult.create(graduationCategory, + mandatoryMajorDetailCategoryResult.getTotalCredits(), List.of(mandatoryMajorDetailCategoryResult)); + } + + private DetailGraduationResult isolateElectiveMajorDetailGraduation( + GraduationCategory graduationCategory, DetailGraduationResult majorDetailGraduationResult) { + DetailCategoryResult electiveMajorDetailCategoryResult = separateElectiveMajor( + graduationCategory, majorDetailGraduationResult); + return DetailGraduationResult.create(graduationCategory, + electiveMajorDetailCategoryResult.getTotalCredits(), List.of(electiveMajorDetailCategoryResult)); + } + + private DetailCategoryResult separateMandatoryMajor( + GraduationCategory graduationCategory, DetailGraduationResult majorDetailGraduationResult) { + DetailCategoryResult mandatoryMajorDetailCategoryResult = majorDetailGraduationResult.getDetailCategory() + .stream() + .filter(detailCategoryResult -> detailCategoryResult.getDetailCategoryName().equals("전공필수")) + .findFirst() + .orElseThrow(() -> new RuntimeException("Not Found DetailCategoryResult(전공 필수)")); + mandatoryMajorDetailCategoryResult.assignDetailCategoryName(graduationCategory.getName()); + return mandatoryMajorDetailCategoryResult; + } + + private DetailCategoryResult separateElectiveMajor( + GraduationCategory graduationCategory, DetailGraduationResult majorDetailGraduationResult) { + DetailCategoryResult electiveMajorDetailCategoryResult = majorDetailGraduationResult.getDetailCategory() + .stream() + .filter(detailCategoryResult -> detailCategoryResult.getDetailCategoryName().equals("전공선택")) + .findFirst() + .orElseThrow(() -> new RuntimeException("Not Found DetailCategoryResult(전공 선택)")); + electiveMajorDetailCategoryResult.assignDetailCategoryName(graduationCategory.getName()); + return electiveMajorDetailCategoryResult; + } +} diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculatePrimaryBasicAcademicalCultureDetailGraduationService.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculatePrimaryBasicAcademicalCultureDetailGraduationService.java deleted file mode 100644 index 71c85bbf..00000000 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculatePrimaryBasicAcademicalCultureDetailGraduationService.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.plzgraduate.myongjigraduatebe.graduation.application.service; - -import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.PRIMARY_BASIC_ACADEMICAL_CULTURE; - -import java.util.List; -import java.util.Set; - -import org.springframework.transaction.annotation.Transactional; - -import com.plzgraduate.myongjigraduatebe.core.meta.UseCase; -import com.plzgraduate.myongjigraduatebe.graduation.application.usecase.CalculatePrimaryBasicAcademicalCultureDetailGraduationUseCase; -import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailGraduationResult; -import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory; -import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationRequirement; -import com.plzgraduate.myongjigraduatebe.graduation.domain.service.GraduationManager; -import com.plzgraduate.myongjigraduatebe.graduation.domain.service.basicacademicalculture.BasicAcademicalManager; -import com.plzgraduate.myongjigraduatebe.graduation.domain.service.basicacademicalculture.BusinessBasicAcademicalManager; -import com.plzgraduate.myongjigraduatebe.graduation.domain.service.basicacademicalculture.DefaultBasicAcademicalManager; -import com.plzgraduate.myongjigraduatebe.graduation.domain.service.basicacademicalculture.SocialScienceBasicAcademicManager; -import com.plzgraduate.myongjigraduatebe.lecture.application.port.FindBasicAcademicalCulturePort; -import com.plzgraduate.myongjigraduatebe.lecture.domain.model.BasicAcademicalCultureLecture; -import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; -import com.plzgraduate.myongjigraduatebe.user.domain.model.User; - -import lombok.RequiredArgsConstructor; - -@UseCase -@Transactional(readOnly = true) -@RequiredArgsConstructor -public class CalculatePrimaryBasicAcademicalCultureDetailGraduationService - implements CalculatePrimaryBasicAcademicalCultureDetailGraduationUseCase { - - private final FindBasicAcademicalCulturePort findBasicAcademicalCulturePort; - - @Override - public boolean supports(GraduationCategory graduationCategory) { - return graduationCategory == PRIMARY_BASIC_ACADEMICAL_CULTURE; - } - - @Override - public DetailGraduationResult calculateDetailGraduation(User user, TakenLectureInventory takenLectureInventory, - GraduationRequirement graduationRequirement) { - Set graduationBasicAcademicalCultureLectures = findBasicAcademicalCulturePort.findBasicAcademicalCulture( - user.getPrimaryMajor()); - GraduationManager basicAcademicalCultureGraduationManager = determineBasicAcademicalCultureGraduationManager( - user); - DetailGraduationResult detailGraduationResult = basicAcademicalCultureGraduationManager.createDetailGraduationResult( - user, takenLectureInventory, graduationBasicAcademicalCultureLectures, - graduationRequirement.getPrimaryBasicAcademicalCultureCredit()); - detailGraduationResult.assignGraduationCategory(PRIMARY_BASIC_ACADEMICAL_CULTURE); - return detailGraduationResult; - } - - private GraduationManager determineBasicAcademicalCultureGraduationManager( - User user) { - List basicAcademicalManagers = List.of( - new BusinessBasicAcademicalManager(), - new SocialScienceBasicAcademicManager()); - - return basicAcademicalManagers.stream() - .filter(basicAcademicalManager -> basicAcademicalManager.isSatisfied(user.getPrimaryMajor())) - .findFirst() - .orElse(new DefaultBasicAcademicalManager()); - } -} diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculatePrimaryElectiveMajorDetailGraduationService.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculatePrimaryElectiveMajorDetailGraduationService.java deleted file mode 100644 index f898cee5..00000000 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculatePrimaryElectiveMajorDetailGraduationService.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.plzgraduate.myongjigraduatebe.graduation.application.service; - -import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.PRIMARY_ELECTIVE_MAJOR; -import static com.plzgraduate.myongjigraduatebe.graduation.domain.service.major.MajorGraduationCategory.PRIMARY; - -import java.util.List; -import java.util.Set; - -import org.springframework.transaction.annotation.Transactional; - -import com.plzgraduate.myongjigraduatebe.core.meta.UseCase; -import com.plzgraduate.myongjigraduatebe.graduation.application.usecase.CalculatePrimaryElectiveMajorDetailGraduationUseCase; -import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailCategoryResult; -import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailGraduationResult; -import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory; -import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationRequirement; -import com.plzgraduate.myongjigraduatebe.graduation.domain.service.GraduationManager; -import com.plzgraduate.myongjigraduatebe.graduation.domain.service.major.MajorManager; -import com.plzgraduate.myongjigraduatebe.lecture.application.port.FindMajorPort; -import com.plzgraduate.myongjigraduatebe.lecture.domain.model.MajorLecture; -import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; -import com.plzgraduate.myongjigraduatebe.user.domain.model.User; - -import lombok.RequiredArgsConstructor; - -@UseCase -@Transactional(readOnly = true) -@RequiredArgsConstructor -public class CalculatePrimaryElectiveMajorDetailGraduationService - implements CalculatePrimaryElectiveMajorDetailGraduationUseCase { - - private final FindMajorPort findMajorPort; - - @Override - public boolean supports(GraduationCategory graduationCategory) { - return graduationCategory == PRIMARY_ELECTIVE_MAJOR; - } - - @Override - public DetailGraduationResult calculateDetailGraduation(User user, TakenLectureInventory takenLectureInventory, - GraduationRequirement graduationRequirement) { - Set graduationMajorLectures = findMajorPort.findMajor(user.getPrimaryMajor()); - GraduationManager majorGraduationManager = new MajorManager(PRIMARY); - DetailGraduationResult majorDetailGraduationResult = majorGraduationManager.createDetailGraduationResult(user, - takenLectureInventory, graduationMajorLectures, graduationRequirement.getPrimaryMajorCredit()); - - DetailCategoryResult electiveMajorDetailCategoryResult = separateElectiveMajor(majorDetailGraduationResult); - - return DetailGraduationResult.create(PRIMARY_ELECTIVE_MAJOR, - electiveMajorDetailCategoryResult.getTotalCredits(), List.of(electiveMajorDetailCategoryResult)); - } - - @Override - public DetailGraduationResult isolatePrimaryElectiveMajorDetailGraduation( - DetailGraduationResult detailPrimaryMajorGraduationResult) { - DetailCategoryResult electiveMajorDetailCategoryResult = separateElectiveMajor( - detailPrimaryMajorGraduationResult); - return DetailGraduationResult.create(PRIMARY_ELECTIVE_MAJOR, - electiveMajorDetailCategoryResult.getTotalCredits(), List.of(electiveMajorDetailCategoryResult)); - } - - private DetailCategoryResult separateElectiveMajor( - DetailGraduationResult majorDetailGraduationResult) { - DetailCategoryResult primaryElectiveDetailCategoryResult = majorDetailGraduationResult.getDetailCategory() - .stream() - .filter(detailCategoryResult -> detailCategoryResult.getDetailCategoryName().equals("전공선택")) - .findFirst() - .orElseThrow(() -> new RuntimeException("Not Found DetailCategoryResult(전공 선택)")); - primaryElectiveDetailCategoryResult.assignDetailCategoryName("주전공선택"); - return primaryElectiveDetailCategoryResult; - } -} diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculatePrimaryMandatoryMajorDetailGraduationService.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculatePrimaryMandatoryMajorDetailGraduationService.java deleted file mode 100644 index dd23a463..00000000 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculatePrimaryMandatoryMajorDetailGraduationService.java +++ /dev/null @@ -1,70 +0,0 @@ -package com.plzgraduate.myongjigraduatebe.graduation.application.service; - -import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.PRIMARY_MANDATORY_MAJOR; -import static com.plzgraduate.myongjigraduatebe.graduation.domain.service.major.MajorGraduationCategory.PRIMARY; - -import java.util.List; -import java.util.Set; - -import org.springframework.transaction.annotation.Transactional; - -import com.plzgraduate.myongjigraduatebe.core.meta.UseCase; -import com.plzgraduate.myongjigraduatebe.graduation.application.usecase.CalculatePrimaryMandatoryMajorDetailGraduationUseCase; -import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailCategoryResult; -import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailGraduationResult; -import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory; -import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationRequirement; -import com.plzgraduate.myongjigraduatebe.graduation.domain.service.GraduationManager; -import com.plzgraduate.myongjigraduatebe.graduation.domain.service.major.MajorManager; -import com.plzgraduate.myongjigraduatebe.lecture.application.port.FindMajorPort; -import com.plzgraduate.myongjigraduatebe.lecture.domain.model.MajorLecture; -import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; -import com.plzgraduate.myongjigraduatebe.user.domain.model.User; - -import lombok.RequiredArgsConstructor; - -@UseCase -@Transactional(readOnly = true) -@RequiredArgsConstructor -public class CalculatePrimaryMandatoryMajorDetailGraduationService - implements CalculatePrimaryMandatoryMajorDetailGraduationUseCase { - - private final FindMajorPort findMajorPort; - - @Override - public boolean supports(GraduationCategory graduationCategory) { - return graduationCategory == PRIMARY_MANDATORY_MAJOR; - } - - @Override - public DetailGraduationResult calculateDetailGraduation(User user, TakenLectureInventory takenLectureInventory, - GraduationRequirement graduationRequirement) { - Set graduationMajorLectures = findMajorPort.findMajor(user.getPrimaryMajor()); - GraduationManager majorGraduationManager = new MajorManager(PRIMARY); - DetailGraduationResult majorDetailGraduationResult = majorGraduationManager.createDetailGraduationResult(user, - takenLectureInventory, graduationMajorLectures, graduationRequirement.getPrimaryMajorCredit()); - - DetailCategoryResult mandatoryMajorDetailCategoryResult = separateMandatoryMajor(majorDetailGraduationResult); - return DetailGraduationResult.create(PRIMARY_MANDATORY_MAJOR, - mandatoryMajorDetailCategoryResult.getTotalCredits(), List.of(mandatoryMajorDetailCategoryResult)); - } - - @Override - public DetailGraduationResult isolatePrimaryMandatoryMajorDetailGraduation( - DetailGraduationResult primaryMajorDetailGraduationResult) { - DetailCategoryResult mandatoryMajorDetailCategoryResult = separateMandatoryMajor( - primaryMajorDetailGraduationResult); - return DetailGraduationResult.create(PRIMARY_MANDATORY_MAJOR, - mandatoryMajorDetailCategoryResult.getTotalCredits(), List.of(mandatoryMajorDetailCategoryResult)); - } - - private DetailCategoryResult separateMandatoryMajor( - DetailGraduationResult majorDetailGraduationResult) { - DetailCategoryResult primaryMandatoryMajorDetailCategoryResult = majorDetailGraduationResult.getDetailCategory().stream() - .filter(detailCategoryResult -> detailCategoryResult.getDetailCategoryName().equals("전공필수")) - .findFirst() - .orElseThrow(() -> new RuntimeException("Not Found DetailCategoryResult(전공 필수)")); - primaryMandatoryMajorDetailCategoryResult.assignDetailCategoryName("주전공필수"); - return primaryMandatoryMajorDetailCategoryResult; - } -} diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateSingleDetailGraduationService.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateSingleDetailGraduationService.java index 943cf77a..ea4fb083 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateSingleDetailGraduationService.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateSingleDetailGraduationService.java @@ -1,9 +1,10 @@ package com.plzgraduate.myongjigraduatebe.graduation.application.service; +import java.util.List; + import org.springframework.transaction.annotation.Transactional; import com.plzgraduate.myongjigraduatebe.core.meta.UseCase; -import com.plzgraduate.myongjigraduatebe.graduation.support.resolver.CalculateDetailGraduationUseCaseResolver; import com.plzgraduate.myongjigraduatebe.graduation.application.usecase.CalculateDetailGraduationUseCase; import com.plzgraduate.myongjigraduatebe.graduation.application.usecase.CalculateSingleDetailGraduationUseCase; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DefaultGraduationRequirementType; @@ -25,17 +26,26 @@ public class CalculateSingleDetailGraduationService implements CalculateSingleDe private final FindUserUseCase findUserUseCase; private final FindTakenLectureUseCase findTakenLectureUseCase; - private final CalculateDetailGraduationUseCaseResolver calculateDetailGraduationUseCaseResolver; + private final List calculateDetailGraduationUseCases; @Override public DetailGraduationResult calculateSingleDetailGraduation(Long userId, GraduationCategory graduationCategory) { User user = findUserUseCase.findUserById(userId); TakenLectureInventory takenLectures = findTakenLectureUseCase.findTakenLectures(userId); - CalculateDetailGraduationUseCase calculateDetailGraduationUseCase = calculateDetailGraduationUseCaseResolver.resolveCalculateDetailGraduationUseCase( + CalculateDetailGraduationUseCase calculateDetailGraduationUseCase = determineCalculateDetailGraduationUseCase( graduationCategory); GraduationRequirement graduationRequirement = determineGraduationRequirement(user); - return calculateDetailGraduationUseCase.calculateDetailGraduation(user, takenLectures, graduationRequirement); + return calculateDetailGraduationUseCase.calculateSingleDetailGraduation(user, graduationCategory, takenLectures, + graduationRequirement); + } + + private CalculateDetailGraduationUseCase determineCalculateDetailGraduationUseCase( + GraduationCategory graduationCategory) { + return calculateDetailGraduationUseCases.stream() + .filter(calculateDetailGraduationUseCase -> calculateDetailGraduationUseCase.supports(graduationCategory)) + .findFirst() + .orElseThrow(() -> new RuntimeException("No calculate detail graduation case found")); } private GraduationRequirement determineGraduationRequirement(User user) { diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateSubMajorDetailGraduationService.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateSubMajorDetailGraduationService.java deleted file mode 100644 index 8689a183..00000000 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateSubMajorDetailGraduationService.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.plzgraduate.myongjigraduatebe.graduation.application.service; - -import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.*; - -import org.springframework.stereotype.Service; - -import com.plzgraduate.myongjigraduatebe.core.meta.UseCase; -import com.plzgraduate.myongjigraduatebe.graduation.application.usecase.CalculateSubMajorDetailGraduationUseCase; -import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailGraduationResult; -import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory; -import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationRequirement; -import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; -import com.plzgraduate.myongjigraduatebe.user.domain.model.User; - -@UseCase -public class CalculateSubMajorDetailGraduationService implements CalculateSubMajorDetailGraduationUseCase { - @Override - public boolean supports(GraduationCategory graduationCategory) { - return graduationCategory == SUB_MAJOR; - } - - @Override - public DetailGraduationResult calculateDetailGraduation(User user, TakenLectureInventory takenLectureInventory, - GraduationRequirement graduationRequirement) { - return null; - } -} diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/usecase/CalculateCommonCultureGraduationUseCase.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/usecase/CalculateCommonCultureGraduationUseCase.java deleted file mode 100644 index e8b1ec08..00000000 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/usecase/CalculateCommonCultureGraduationUseCase.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.plzgraduate.myongjigraduatebe.graduation.application.usecase; - -public interface CalculateCommonCultureGraduationUseCase extends CalculateDetailGraduationUseCase{ -} diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/usecase/CalculateCoreCultureGraduationUseCase.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/usecase/CalculateCoreCultureGraduationUseCase.java deleted file mode 100644 index f94e99a5..00000000 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/usecase/CalculateCoreCultureGraduationUseCase.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.plzgraduate.myongjigraduatebe.graduation.application.usecase; - -public interface CalculateCoreCultureGraduationUseCase extends CalculateDetailGraduationUseCase { - -} diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/usecase/CalculateDetailGraduationUseCase.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/usecase/CalculateDetailGraduationUseCase.java index 1e6e0cf1..664ecd02 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/usecase/CalculateDetailGraduationUseCase.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/usecase/CalculateDetailGraduationUseCase.java @@ -10,6 +10,6 @@ public interface CalculateDetailGraduationUseCase { boolean supports(GraduationCategory graduationCategory); - DetailGraduationResult calculateDetailGraduation(User user, TakenLectureInventory takenLectureInventory, + DetailGraduationResult calculateSingleDetailGraduation(User user, GraduationCategory graduationCategory, TakenLectureInventory takenLectureInventory, GraduationRequirement graduationRequirement); } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/usecase/CalculateDualBasicAcademicalCultureDetailGraduationUseCase.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/usecase/CalculateDualBasicAcademicalCultureDetailGraduationUseCase.java deleted file mode 100644 index 89eb1937..00000000 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/usecase/CalculateDualBasicAcademicalCultureDetailGraduationUseCase.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.plzgraduate.myongjigraduatebe.graduation.application.usecase; - -public interface CalculateDualBasicAcademicalCultureDetailGraduationUseCase extends CalculateDetailGraduationUseCase { -} diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/usecase/CalculateDualElectiveMajorDetailGraduationUseCase.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/usecase/CalculateDualElectiveMajorDetailGraduationUseCase.java deleted file mode 100644 index f5d152f2..00000000 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/usecase/CalculateDualElectiveMajorDetailGraduationUseCase.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.plzgraduate.myongjigraduatebe.graduation.application.usecase; - -import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailGraduationResult; - -public interface CalculateDualElectiveMajorDetailGraduationUseCase extends CalculateDetailGraduationUseCase { - - DetailGraduationResult isolateDualElectiveMajorDetailGraduation( - DetailGraduationResult dualMajorDetailGraduationResult); -} diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/usecase/CalculateDualMandatoryMajorDetailGraduationUseCase.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/usecase/CalculateDualMandatoryMajorDetailGraduationUseCase.java deleted file mode 100644 index ff21fa6f..00000000 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/usecase/CalculateDualMandatoryMajorDetailGraduationUseCase.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.plzgraduate.myongjigraduatebe.graduation.application.usecase; - -import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailGraduationResult; - -public interface CalculateDualMandatoryMajorDetailGraduationUseCase extends CalculateDetailGraduationUseCase { - - DetailGraduationResult isolateDualMandatoryMajorDetailGraduation( - DetailGraduationResult dualMajorDetailGraduationResult); -} diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/usecase/CalculatePrimaryBasicAcademicalCultureDetailGraduationUseCase.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/usecase/CalculatePrimaryBasicAcademicalCultureDetailGraduationUseCase.java deleted file mode 100644 index b1972c6f..00000000 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/usecase/CalculatePrimaryBasicAcademicalCultureDetailGraduationUseCase.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.plzgraduate.myongjigraduatebe.graduation.application.usecase; - -public interface CalculatePrimaryBasicAcademicalCultureDetailGraduationUseCase - extends CalculateDetailGraduationUseCase { -} diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/usecase/CalculatePrimaryElectiveMajorDetailGraduationUseCase.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/usecase/CalculatePrimaryElectiveMajorDetailGraduationUseCase.java deleted file mode 100644 index f7e32598..00000000 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/usecase/CalculatePrimaryElectiveMajorDetailGraduationUseCase.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.plzgraduate.myongjigraduatebe.graduation.application.usecase; - -import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailGraduationResult; - -public interface CalculatePrimaryElectiveMajorDetailGraduationUseCase extends CalculateDetailGraduationUseCase { - - DetailGraduationResult isolatePrimaryElectiveMajorDetailGraduation( - DetailGraduationResult primaryMajorDetailGraduationResult); -} diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/usecase/CalculatePrimaryMandatoryMajorDetailGraduationUseCase.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/usecase/CalculatePrimaryMandatoryMajorDetailGraduationUseCase.java deleted file mode 100644 index 2b0d616b..00000000 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/usecase/CalculatePrimaryMandatoryMajorDetailGraduationUseCase.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.plzgraduate.myongjigraduatebe.graduation.application.usecase; - -import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailGraduationResult; - -public interface CalculatePrimaryMandatoryMajorDetailGraduationUseCase extends CalculateDetailGraduationUseCase { - - DetailGraduationResult isolatePrimaryMandatoryMajorDetailGraduation( - DetailGraduationResult primaryMajorDetailGraduationResult); -} diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/usecase/CalculateSubMajorDetailGraduationUseCase.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/usecase/CalculateSubMajorDetailGraduationUseCase.java deleted file mode 100644 index f3e27dc0..00000000 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/application/usecase/CalculateSubMajorDetailGraduationUseCase.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.plzgraduate.myongjigraduatebe.graduation.application.usecase; - -public interface CalculateSubMajorDetailGraduationUseCase extends CalculateDetailGraduationUseCase { -} diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/DetailGraduationResult.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/DetailGraduationResult.java index d3802c5f..b6176b57 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/DetailGraduationResult.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/DetailGraduationResult.java @@ -16,7 +16,7 @@ public class DetailGraduationResult { @Builder private DetailGraduationResult(GraduationCategory graduationCategory, boolean isCompleted, int totalCredit, - int takenCredit, + double takenCredit, List detailCategory) { this.graduationCategory = graduationCategory; this.isCompleted = isCompleted; diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/GraduationCategory.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/GraduationCategory.java index a00c9c1c..d160ab11 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/GraduationCategory.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/GraduationCategory.java @@ -32,4 +32,8 @@ public static GraduationCategory of(String name) { .findFirst() .orElseThrow(() -> new IllegalArgumentException("해당 카테고리를 찾을 수 없습니다.")); } + + public boolean checkMandatoryIfSeperatedByMandatoryAndElective() { + return this == PRIMARY_MANDATORY_MAJOR || this == DUAL_MANDATORY_MAJOR; + } } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/GraduationRequirement.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/GraduationRequirement.java index 7697901e..094f511c 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/GraduationRequirement.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/GraduationRequirement.java @@ -71,4 +71,20 @@ private int calculateFreeElectiveCreditWithDualMajorStudent() { - primaryBasicAcademicalCultureCredit - dualBasicAcademicalCultureCredit; return Math.max(freeElectiveCredit, 0); } + + public int getBasicCreditByMajorType(MajorType majorType) { + if(majorType == MajorType.PRIMARY) { + return primaryBasicAcademicalCultureCredit; + } + return dualBasicAcademicalCultureCredit; + } + + public int getMajorCreditByMajorType(MajorType majorType) { + if(majorType == MajorType.PRIMARY) { + return primaryMajorCredit; + } else if(majorType == MajorType.DUAL) { + return dualMajorCredit; + } + return subMajorCredit; + } } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/MajorType.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/MajorType.java new file mode 100644 index 00000000..23013ddd --- /dev/null +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/MajorType.java @@ -0,0 +1,23 @@ +package com.plzgraduate.myongjigraduatebe.graduation.domain.model; + +import lombok.Getter; + +@Getter +public enum MajorType { + PRIMARY, + DUAL, + SUB; + + public static MajorType from(GraduationCategory graduationCategory) { + if(graduationCategory == GraduationCategory.PRIMARY_MANDATORY_MAJOR + || graduationCategory == GraduationCategory.PRIMARY_ELECTIVE_MAJOR + || graduationCategory == GraduationCategory.PRIMARY_BASIC_ACADEMICAL_CULTURE) { + return PRIMARY; + } else if(graduationCategory == GraduationCategory.DUAL_MANDATORY_MAJOR + || graduationCategory == GraduationCategory.DUAL_ELECTIVE_MAJOR + || graduationCategory == GraduationCategory.DUAL_BASIC_ACADEMICAL_CULTURE) { + return DUAL; + } + return SUB; + } +} diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/BasicAcademicalManager.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/BasicAcademicalGraduationManager.java similarity index 80% rename from src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/BasicAcademicalManager.java rename to src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/BasicAcademicalGraduationManager.java index 0aeeb817..752b1923 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/BasicAcademicalManager.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/BasicAcademicalGraduationManager.java @@ -6,9 +6,8 @@ import com.plzgraduate.myongjigraduatebe.graduation.domain.service.GraduationManager; import com.plzgraduate.myongjigraduatebe.lecture.domain.model.BasicAcademicalCultureLecture; import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; -import com.plzgraduate.myongjigraduatebe.user.domain.model.User; -public interface BasicAcademicalManager extends GraduationManager { +public interface BasicAcademicalGraduationManager extends GraduationManager { boolean isSatisfied(String major); default Set convertToLectureSet(Set basicAcademicalCultureLectures) { diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/BusinessBasicAcademicalManager.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/BusinessBasicAcademicalGraduationManager.java similarity index 87% rename from src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/BusinessBasicAcademicalManager.java rename to src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/BusinessBasicAcademicalGraduationManager.java index 2006d2b6..db55fa66 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/BusinessBasicAcademicalManager.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/BusinessBasicAcademicalGraduationManager.java @@ -1,22 +1,23 @@ package com.plzgraduate.myongjigraduatebe.graduation.domain.service.basicacademicalculture; -import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.PRIMARY_BASIC_ACADEMICAL_CULTURE; import static com.plzgraduate.myongjigraduatebe.user.domain.model.College.*; import java.util.HashSet; import java.util.List; import java.util.Set; +import org.springframework.stereotype.Component; + import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailCategoryResult; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailGraduationResult; import com.plzgraduate.myongjigraduatebe.lecture.domain.model.BasicAcademicalCultureLecture; import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture; -import com.plzgraduate.myongjigraduatebe.user.domain.model.College; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; -public class BusinessBasicAcademicalManager implements BasicAcademicalManager { +@Component +public class BusinessBasicAcademicalGraduationManager implements BasicAcademicalGraduationManager { private static final int TWENTY = 20; private static final String BUSINESS_ADMINISTRATION = "경영학과"; @@ -42,7 +43,7 @@ public DetailGraduationResult createDetailGraduationResult(User user, int basicAcademicalCredit) { Set basicAcademicalLectures = convertToLectureSet(graduationLectures); - Set removedTakenLecture = new HashSet<>(); + Set finishedTakenLecture = new HashSet<>(); Set taken = new HashSet<>(); Set finalBasicAcademicalLectures = resetBasicAcademicalLectureSet(basicAcademicalLectures, user); @@ -50,10 +51,10 @@ public DetailGraduationResult createDetailGraduationResult(User user, takenLectureInventory.getTakenLectures().stream() .filter(takenLecture -> finalBasicAcademicalLectures.contains(takenLecture.getLecture())) .forEach(takenLecture -> { - removedTakenLecture.add(takenLecture); + finishedTakenLecture.add(takenLecture); taken.add(takenLecture.getLecture()); }); - takenLectureInventory.handleFinishedTakenLectures(removedTakenLecture); + takenLectureInventory.handleFinishedTakenLectures(finishedTakenLecture); DetailCategoryResult detailCategoryResult = DetailCategoryResult.create( "학문기초교양", true, basicAcademicalCredit); diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/DefaultBasicAcademicalManager.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/DefaultBasicAcademicalGraduationManager.java similarity index 64% rename from src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/DefaultBasicAcademicalManager.java rename to src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/DefaultBasicAcademicalGraduationManager.java index d945b1df..f2754a96 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/DefaultBasicAcademicalManager.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/DefaultBasicAcademicalGraduationManager.java @@ -1,11 +1,16 @@ package com.plzgraduate.myongjigraduatebe.graduation.domain.service.basicacademicalculture; -import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.PRIMARY_BASIC_ACADEMICAL_CULTURE; +import static com.plzgraduate.myongjigraduatebe.user.domain.model.College.HUMANITIES; +import static com.plzgraduate.myongjigraduatebe.user.domain.model.College.ICT; +import static com.plzgraduate.myongjigraduatebe.user.domain.model.College.LAW; +import static com.plzgraduate.myongjigraduatebe.user.domain.model.College.findBelongingCollege; import java.util.HashSet; import java.util.List; import java.util.Set; +import org.springframework.stereotype.Component; + import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailCategoryResult; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailGraduationResult; import com.plzgraduate.myongjigraduatebe.lecture.domain.model.BasicAcademicalCultureLecture; @@ -16,31 +21,30 @@ import lombok.NoArgsConstructor; +@Component @NoArgsConstructor -public class DefaultBasicAcademicalManager implements BasicAcademicalManager { +public class DefaultBasicAcademicalGraduationManager implements BasicAcademicalGraduationManager { @Override public boolean isSatisfied(String major) { - return false; + return List.of(HUMANITIES, LAW, ICT).contains(findBelongingCollege(major)); } @Override - public DetailGraduationResult createDetailGraduationResult(User user, - TakenLectureInventory takenLectureInventory, Set graduationLectures, - int basicAcademicalCredit) { - + public DetailGraduationResult createDetailGraduationResult(User user, TakenLectureInventory takenLectureInventory, + Set graduationLectures, int basicAcademicalCredit) { Set basicAcademicalLectures = convertToLectureSet(graduationLectures); - Set removedTakenLecture = new HashSet<>(); + Set finishedTakenLecture = new HashSet<>(); Set taken = new HashSet<>(); takenLectureInventory.getTakenLectures().stream() .filter(takenLecture -> basicAcademicalLectures.contains(takenLecture.getLecture())) .forEach(takenLecture -> { - removedTakenLecture.add(takenLecture); + finishedTakenLecture.add(takenLecture); taken.add(takenLecture.getLecture()); }); - takenLectureInventory.handleFinishedTakenLectures(removedTakenLecture); + takenLectureInventory.handleFinishedTakenLectures(finishedTakenLecture); DetailCategoryResult detailCategoryResult = DetailCategoryResult.create( "학문기초교양", true, basicAcademicalCredit); diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/SocialScienceBasicAcademicManager.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/SocialScienceBasicAcademicGraduationManager.java similarity index 89% rename from src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/SocialScienceBasicAcademicManager.java rename to src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/SocialScienceBasicAcademicGraduationManager.java index 7343cdde..df9ad3db 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/SocialScienceBasicAcademicManager.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/SocialScienceBasicAcademicGraduationManager.java @@ -7,6 +7,8 @@ import java.util.List; import java.util.Set; +import org.springframework.stereotype.Component; + import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailCategoryResult; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailGraduationResult; import com.plzgraduate.myongjigraduatebe.lecture.domain.model.BasicAcademicalCultureLecture; @@ -15,7 +17,8 @@ import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; -public class SocialScienceBasicAcademicManager implements BasicAcademicalManager { +@Component +public class SocialScienceBasicAcademicGraduationManager implements BasicAcademicalGraduationManager { private static final int TWENTY_THREE_YEAR = 2023; private static final Set lecturesAcceptTakenAfter2023 = Set.of( @@ -41,7 +44,7 @@ public DetailGraduationResult createDetailGraduationResult(User user, int basicAcademicalCredit) { Set basicAcademicalLectures = convertToLectureSet(graduationLectures); - Set removedTakenLecture = new HashSet<>(); + Set finishedTakenLecture = new HashSet<>(); Set taken = new HashSet<>(); takenLectureInventory.getTakenLectures().stream() @@ -49,10 +52,10 @@ public DetailGraduationResult createDetailGraduationResult(User user, .filter(takenLecture -> lecturesAcceptTakenAfter2023.contains(takenLecture.getLecture()) && !takenLecture.takenAfter(TWENTY_THREE_YEAR)) .forEach(takenLecture -> { - removedTakenLecture.add(takenLecture); + finishedTakenLecture.add(takenLecture); taken.add(takenLecture.getLecture()); }); - takenLectureInventory.handleFinishedTakenLectures(removedTakenLecture); + takenLectureInventory.handleFinishedTakenLectures(finishedTakenLecture); DetailCategoryResult detailCategoryResult = DetailCategoryResult.create( "학문기초교양", true, basicAcademicalCredit); diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/commonculture/CommonCultureDetailCategoryManager.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/commonculture/CommonCultureDetailCategoryManager.java index 923c2574..7a807f8b 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/commonculture/CommonCultureDetailCategoryManager.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/commonculture/CommonCultureDetailCategoryManager.java @@ -8,6 +8,8 @@ import java.util.Set; import java.util.stream.Collectors; +import org.springframework.stereotype.Component; + import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailCategoryResult; import com.plzgraduate.myongjigraduatebe.lecture.domain.model.CommonCulture; import com.plzgraduate.myongjigraduatebe.lecture.domain.model.CommonCultureCategory; @@ -16,6 +18,7 @@ import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; +@Component class CommonCultureDetailCategoryManager { private static final List CHRISTAIN_MANDATORY_LECTURE_CODE_LIST = @@ -27,32 +30,25 @@ class CommonCultureDetailCategoryManager { public DetailCategoryResult generate(User user, TakenLectureInventory takenLectureInventory, Set graduationLectures, CommonCultureCategory category) { - Set graduationCommonCultureLectures = categorizeCommonCultures( - graduationLectures, category); - - Set removedTakenLecture = new HashSet<>(); + Set graduationCommonCultureLectures = categorizeCommonCultures(graduationLectures, category); + Set finishedTakenLecture = new HashSet<>(); Set taken = new HashSet<>(); - takenLectureInventory.getTakenLectures().stream() .filter(takenLecture -> graduationCommonCultureLectures.contains(takenLecture.getLecture())) .forEach(takenLecture -> { - removedTakenLecture.add(takenLecture); + finishedTakenLecture.add(takenLecture); taken.add(takenLecture.getLecture()); }); - - + boolean isSatisfiedMandatory = checkMandatorySatisfaction(user, takenLectureInventory, category); + takenLectureInventory.handleFinishedTakenLectures(finishedTakenLecture); DetailCategoryResult commonCultureDetailCategoryResult = DetailCategoryResult.create( - category.getName(), checkMandatorySatisfaction(user, takenLectureInventory, category), - checkCategoryTotalCredit(user, category)); + category.getName(), isSatisfiedMandatory, checkCategoryTotalCredit(user, category)); commonCultureDetailCategoryResult.calculate(taken, graduationCommonCultureLectures); - - takenLectureInventory.handleFinishedTakenLectures(removedTakenLecture); - return commonCultureDetailCategoryResult; } private int checkCategoryTotalCredit(User user, CommonCultureCategory commonCultureCategory) { - if (user.getEnglishLevel() == FREE && commonCultureCategory == ENGLISH){ + if (user.getEnglishLevel() == FREE && commonCultureCategory == ENGLISH) { return 0; } return commonCultureCategory.getTotalCredit(); diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/commonculture/CommonCultureGraduationManager.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/commonculture/CommonGraduationManager.java similarity index 93% rename from src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/commonculture/CommonCultureGraduationManager.java rename to src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/commonculture/CommonGraduationManager.java index ea90105e..76e4dc18 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/commonculture/CommonCultureGraduationManager.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/commonculture/CommonGraduationManager.java @@ -8,7 +8,8 @@ import java.util.Set; import java.util.stream.Collectors; -import com.plzgraduate.myongjigraduatebe.graduation.domain.model.ChapelResult; +import org.springframework.stereotype.Component; + import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailCategoryResult; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailGraduationResult; import com.plzgraduate.myongjigraduatebe.graduation.domain.service.GraduationManager; @@ -17,7 +18,8 @@ import com.plzgraduate.myongjigraduatebe.user.domain.model.User; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; -public class CommonCultureGraduationManager implements GraduationManager { +@Component +public class CommonGraduationManager implements GraduationManager { @Override public DetailGraduationResult createDetailGraduationResult(User user, diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/coreculture/CoreCultureDetailCategoryManager.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/coreculture/CoreCultureDetailCategoryManager.java index 76f2928f..16339019 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/coreculture/CoreCultureDetailCategoryManager.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/coreculture/CoreCultureDetailCategoryManager.java @@ -7,6 +7,8 @@ import java.util.Set; import java.util.stream.Collectors; +import org.springframework.stereotype.Component; + import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailCategoryResult; import com.plzgraduate.myongjigraduatebe.lecture.domain.model.CoreCulture; import com.plzgraduate.myongjigraduatebe.lecture.domain.model.CoreCultureCategory; @@ -15,6 +17,7 @@ import com.plzgraduate.myongjigraduatebe.user.domain.model.User; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; +@Component public class CoreCultureDetailCategoryManager { private static final List ICT_DEPARTMENTS = List.of( @@ -26,14 +29,11 @@ public class CoreCultureDetailCategoryManager { Lecture.from("KMA02155"), Lecture.from("KMA02156")); - public DetailCategoryResult generate(User user, - TakenLectureInventory takenLectureInventory, Set graduationLectures, - CoreCultureCategory category) { - - Set graduationCoreCultureLectures = categorizeCommonCultures(graduationLectures, category); + public DetailCategoryResult generate(User user, TakenLectureInventory takenLectureInventory, + Set graduationLectures, CoreCultureCategory category) { + Set graduationCoreCultureLectures = categorizeCoreCultures(graduationLectures, category); Set finishedTakenLecture = new HashSet<>(); Set taken = new HashSet<>(); - takenLectureInventory.getTakenLectures().stream() .filter(takenLecture -> graduationCoreCultureLectures.contains(takenLecture.getLecture())) .forEach(takenLecture -> { @@ -51,7 +51,7 @@ public DetailCategoryResult generate(User user, return commonCultureDetailCategoryResult; } - private Set categorizeCommonCultures(Set graduationLectures, + private Set categorizeCoreCultures(Set graduationLectures, CoreCultureCategory category) { return graduationLectures.stream() .filter(coreCulture -> coreCulture.getCoreCultureCategory() == category) diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/coreculture/CoreCultureGraduationManager.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/coreculture/CoreGraduationManager.java similarity index 91% rename from src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/coreculture/CoreCultureGraduationManager.java rename to src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/coreculture/CoreGraduationManager.java index e6f53b12..d41f7484 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/coreculture/CoreCultureGraduationManager.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/coreculture/CoreGraduationManager.java @@ -7,6 +7,8 @@ import java.util.Set; import java.util.stream.Collectors; +import org.springframework.stereotype.Component; + import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailCategoryResult; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailGraduationResult; import com.plzgraduate.myongjigraduatebe.graduation.domain.service.GraduationManager; @@ -15,7 +17,8 @@ import com.plzgraduate.myongjigraduatebe.user.domain.model.User; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; -public class CoreCultureGraduationManager implements GraduationManager { +@Component +public class CoreGraduationManager implements GraduationManager { @Override public DetailGraduationResult createDetailGraduationResult(User user, TakenLectureInventory takenLectureInventory, Set graduationLectures, int coreCultureGraduationTotalCredit) { diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/ElectiveMajorManager.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/ElectiveMajorManager.java index 8ac2d32d..175b4a82 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/ElectiveMajorManager.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/ElectiveMajorManager.java @@ -3,11 +3,14 @@ import java.util.HashSet; import java.util.Set; +import org.springframework.stereotype.Component; + import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailCategoryResult; import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; +@Component public class ElectiveMajorManager { private static final String ELECTIVE_MAJOR_NAME = "전공선택"; diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/MajorGraduationCategory.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/MajorGraduationCategory.java deleted file mode 100644 index 15d82803..00000000 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/MajorGraduationCategory.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.plzgraduate.myongjigraduatebe.graduation.domain.service.major; - -import lombok.Getter; - -@Getter -public enum MajorGraduationCategory { - PRIMARY, - DUAL, - SUB -} diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/MajorManager.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/MajorGraduationManager.java similarity index 88% rename from src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/MajorManager.java rename to src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/MajorGraduationManager.java index e964fd68..7fdc0aac 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/MajorManager.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/MajorGraduationManager.java @@ -4,9 +4,11 @@ import java.util.Set; import java.util.stream.Collectors; +import org.springframework.stereotype.Component; + import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailCategoryResult; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailGraduationResult; -import com.plzgraduate.myongjigraduatebe.graduation.domain.service.GraduationManager; +import com.plzgraduate.myongjigraduatebe.graduation.domain.model.MajorType; import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; import com.plzgraduate.myongjigraduatebe.lecture.domain.model.MajorLecture; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture; @@ -15,21 +17,23 @@ import lombok.RequiredArgsConstructor; +@Component @RequiredArgsConstructor -public class MajorManager implements GraduationManager { +public class MajorGraduationManager { - private final MajorGraduationCategory majorGraduationCategory; + private final MandatoryMajorManager mandatoryMajorManager; + private final ElectiveMajorManager electiveMajorManager; /** * * @param user 사용자 + * @param majorType 주전공, 복수전공, 부전공 * @param takenLectureInventory 수강과목 목록 * @param majorLectures 해당 사용자의 전공과목 * @param graduationResultTotalCredit 해당 사용자의 전공 졸업 학점 * @return 전공 카테고리에 대한 졸업 결과 반환 */ - @Override - public DetailGraduationResult createDetailGraduationResult(User user, + public DetailGraduationResult createDetailGraduationResult(User user, MajorType majorType, TakenLectureInventory takenLectureInventory, Set majorLectures, int graduationResultTotalCredit) { removeDuplicateLectureIfTaken(takenLectureInventory, majorLectures); @@ -38,14 +42,8 @@ public DetailGraduationResult createDetailGraduationResult(User user, Set mandatoryLectures = filterMandatoryLectures(majorLectures); Set electiveLectures = filterElectiveLectures(majorLectures); - List mandatoryMajorSpecialCaseHandlers = List.of( - new OptionalMandatoryMajorHandler(), - new ReplaceMandatoryMajorHandler()); - MandatoryMajorManager mandatoryMajorManager = new MandatoryMajorManager(mandatoryMajorSpecialCaseHandlers); - ElectiveMajorManager electiveMajorManager = new ElectiveMajorManager(); - DetailCategoryResult mandantoryDetailCategoryResult = mandatoryMajorManager.createDetailCategoryResult( - user, takenLectureInventory, mandatoryLectures, electiveLectures, majorGraduationCategory); + user, takenLectureInventory, mandatoryLectures, electiveLectures, majorType); int electiveMajorTotalCredit = graduationResultTotalCredit - mandantoryDetailCategoryResult.getTotalCredits(); DetailCategoryResult electiveDetailCategoryResult = electiveMajorManager.createDetailCategoryResult( 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 f28c35b5..81edbea5 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 @@ -4,7 +4,10 @@ import java.util.List; import java.util.Set; +import org.springframework.stereotype.Component; + import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailCategoryResult; +import com.plzgraduate.myongjigraduatebe.graduation.domain.model.MajorType; import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; @@ -12,6 +15,7 @@ import lombok.RequiredArgsConstructor; +@Component @RequiredArgsConstructor public class MandatoryMajorManager { @@ -20,17 +24,16 @@ public class MandatoryMajorManager { private final List mandatoryMajorSpecialCaseHandlers; public DetailCategoryResult createDetailCategoryResult(User user, TakenLectureInventory takenLectureInventory, - Set mandatoryLectures, Set electiveLectures, - MajorGraduationCategory majorGraduationCategory) { + Set mandatoryLectures, Set electiveLectures, MajorType majorType) { Set takenMandatory = new HashSet<>(); Set finishedTakenLecture = new HashSet<>(); boolean isSatisfiedMandatory = true; int removeMandatoryTotalCredit = 0; for (MandatoryMajorSpecialCaseHandler mandatoryMajorSpecialCaseHandler : mandatoryMajorSpecialCaseHandlers) { - if (mandatoryMajorSpecialCaseHandler.isSupport(user, majorGraduationCategory)) { + if (mandatoryMajorSpecialCaseHandler.isSupport(user, majorType)) { MandatorySpecialCaseInformation mandatorySpecialCaseInformation = mandatoryMajorSpecialCaseHandler.getMandatorySpecialCaseInformation( - user, majorGraduationCategory, takenLectureInventory, mandatoryLectures, electiveLectures); + user, majorType, takenLectureInventory, mandatoryLectures, electiveLectures); isSatisfiedMandatory = mandatorySpecialCaseInformation.isCompleteMandatorySpecialCase(); removeMandatoryTotalCredit = mandatorySpecialCaseInformation.getRemovedMandatoryTotalCredit(); } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/MandatoryMajorSpecialCaseHandler.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/MandatoryMajorSpecialCaseHandler.java index 7602e313..b04690f8 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/MandatoryMajorSpecialCaseHandler.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/MandatoryMajorSpecialCaseHandler.java @@ -2,14 +2,15 @@ import java.util.Set; +import com.plzgraduate.myongjigraduatebe.graduation.domain.model.MajorType; import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; public interface MandatoryMajorSpecialCaseHandler { - boolean isSupport(User user, MajorGraduationCategory majorGraduationCategory); + boolean isSupport(User user, MajorType majorType); MandatorySpecialCaseInformation getMandatorySpecialCaseInformation( - User user, MajorGraduationCategory majorGraduationCategory, TakenLectureInventory takenLectureInventory, + User user, MajorType majorType, TakenLectureInventory takenLectureInventory, Set mandatoryLectures, Set electiveLectures); } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/OptionalMandatoryMajorHandler.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/OptionalMandatoryMajorHandler.java index 7adc6ad5..9df5a7ef 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/OptionalMandatoryMajorHandler.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/OptionalMandatoryMajorHandler.java @@ -1,13 +1,13 @@ package com.plzgraduate.myongjigraduatebe.graduation.domain.service.major; -import static com.plzgraduate.myongjigraduatebe.graduation.domain.service.major.MajorGraduationCategory.DUAL; -import static com.plzgraduate.myongjigraduatebe.graduation.domain.service.major.MajorGraduationCategory.PRIMARY; - import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.stream.Collectors; +import org.springframework.stereotype.Component; + +import com.plzgraduate.myongjigraduatebe.graduation.domain.model.MajorType; import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; @@ -19,6 +19,7 @@ * 경영정보의 경우 인적자원관리, 마켓팅원론, 재무관리원론에서 ~18학번까지는 3개 모두 이수, 19학번 이후 택 2 * 경영의 경우 국제통상원론, 국제경양, 경영정보 중 택1 **/ +@Component public class OptionalMandatoryMajorHandler implements MandatoryMajorSpecialCaseHandler { private static final String MANAGEMENT_INFORMATION = "경영정보학과"; @@ -28,8 +29,8 @@ public class OptionalMandatoryMajorHandler implements MandatoryMajorSpecialCaseH private static final int CLASS_OF_17 = 17; private static final int CLASS_OF_19 = 19; - public boolean isSupport(User user, MajorGraduationCategory majorGraduationCategory) { - String calculatingMajor = getCalculatingMajor(user, majorGraduationCategory); + public boolean isSupport(User user, MajorType majorType) { + String calculatingMajor = getCalculatingMajor(user, majorType); if (calculatingMajor.equals(MANAGEMENT_INFORMATION) && user.getEntryYear() >= CLASS_OF_19) { return true; } @@ -41,9 +42,9 @@ public boolean isSupport(User user, MajorGraduationCategory majorGraduationCateg @Override public MandatorySpecialCaseInformation getMandatorySpecialCaseInformation(User user, - MajorGraduationCategory majorGraduationCategory, TakenLectureInventory takenLectureInventory, + MajorType majorType, TakenLectureInventory takenLectureInventory, Set mandatoryLectures, Set electiveLectures) { - OptionalMandatory optionalMandatory = OptionalMandatory.from(getCalculatingMajor(user, majorGraduationCategory)); + OptionalMandatory optionalMandatory = OptionalMandatory.from(getCalculatingMajor(user, majorType)); int removedMandatoryTotalCredit = 0; boolean isCompletedMandatorySpecialCase = checkCompleteOptionalMandatory(takenLectureInventory, mandatoryLectures, electiveLectures, optionalMandatory); @@ -84,13 +85,7 @@ private boolean checkCompleteOptionalMandatory(TakenLectureInventory takenLectur return count >= chooseNum; } - private String getCalculatingMajor(User user, MajorGraduationCategory majorGraduationCategory) { - if (majorGraduationCategory == PRIMARY) { - return user.getPrimaryMajor(); - } - if (majorGraduationCategory == DUAL) { - return user.getDualMajor(); - } - return user.getSubMajor(); + private String getCalculatingMajor(User user, MajorType majorType) { + return user.getMajorByMajorType(majorType); } } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/ReplaceMandatoryMajorHandler.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/ReplaceMandatoryMajorHandler.java index 9ed0b167..4a803ec0 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/ReplaceMandatoryMajorHandler.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/ReplaceMandatoryMajorHandler.java @@ -1,12 +1,13 @@ package com.plzgraduate.myongjigraduatebe.graduation.domain.service.major; -import static com.plzgraduate.myongjigraduatebe.graduation.domain.service.major.MajorGraduationCategory.*; - import java.util.Comparator; import java.util.List; import java.util.Set; import java.util.stream.Collectors; +import org.springframework.stereotype.Component; + +import com.plzgraduate.myongjigraduatebe.graduation.domain.model.MajorType; 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 @@ * 철학과의 경우 답사1, 답사2는 폐지 되었지만 2021번 이전까지 전공필수 * '신유학의 이해' '유학사상의이해' 중 택1 이수 시 대체 인정 */ + +@Component public class ReplaceMandatoryMajorHandler implements MandatoryMajorSpecialCaseHandler { private static final List REPLACED_LECTURES = List.of( Lecture.of("HAI01110", "답사1", 1, 1, null), @@ -27,21 +30,14 @@ public class ReplaceMandatoryMajorHandler implements MandatoryMajorSpecialCaseHa ); @Override - public boolean isSupport(User user, MajorGraduationCategory majorGraduationCategory) { - String major; - if (majorGraduationCategory == PRIMARY) { - major = user.getPrimaryMajor(); - } else if (majorGraduationCategory == DUAL) { - major = user.getDualMajor(); - } else { - major = user.getSubMajor(); - } + public boolean isSupport(User user, MajorType majorType) { + String major = user.getMajorByMajorType(majorType); return major.equals("철학과") && user.getEntryYear() <= 21; } @Override public MandatorySpecialCaseInformation getMandatorySpecialCaseInformation(User user, - MajorGraduationCategory majorGraduationCategory, TakenLectureInventory takenLectureInventory, + MajorType majorType, TakenLectureInventory takenLectureInventory, Set mandatoryLectures, Set electiveLectures) { boolean completeMandatorySpecialCase = checkCompleteReplaceMandatory(takenLectureInventory, mandatoryLectures, electiveLectures); diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/submajor/SubMajorManager.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/submajor/SubMajorGraduationManager.java similarity index 94% rename from src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/submajor/SubMajorManager.java rename to src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/submajor/SubMajorGraduationManager.java index 2c5fd986..29c2a3a3 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/submajor/SubMajorManager.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/submajor/SubMajorGraduationManager.java @@ -5,6 +5,8 @@ import java.util.Set; import java.util.stream.Collectors; +import org.springframework.stereotype.Component; + import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailCategoryResult; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailGraduationResult; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory; @@ -15,7 +17,8 @@ import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; -public class SubMajorManager implements GraduationManager { +@Component +public class SubMajorGraduationManager implements GraduationManager { @Override public DetailGraduationResult createDetailGraduationResult(User user, TakenLectureInventory takenLectureInventory, diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/support/resolver/CalculateDetailGraduationUseCaseResolver.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/support/resolver/CalculateDetailGraduationUseCaseResolver.java deleted file mode 100644 index fa53f676..00000000 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/support/resolver/CalculateDetailGraduationUseCaseResolver.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.plzgraduate.myongjigraduatebe.graduation.support.resolver; - -import com.plzgraduate.myongjigraduatebe.graduation.application.usecase.CalculateDetailGraduationUseCase; -import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory; - -public interface CalculateDetailGraduationUseCaseResolver { - - CalculateDetailGraduationUseCase resolveCalculateDetailGraduationUseCase(GraduationCategory graduationCategory); -} diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/support/resolver/SingleCalculateDetailGraduationUseCaseResolver.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/support/resolver/SingleCalculateDetailGraduationUseCaseResolver.java deleted file mode 100644 index 13795f4b..00000000 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/support/resolver/SingleCalculateDetailGraduationUseCaseResolver.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.plzgraduate.myongjigraduatebe.graduation.support.resolver; - -import java.util.List; - -import org.springframework.stereotype.Component; - -import com.plzgraduate.myongjigraduatebe.graduation.application.usecase.CalculateDetailGraduationUseCase; -import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory; - -import lombok.RequiredArgsConstructor; - -@Component() -@RequiredArgsConstructor -public class SingleCalculateDetailGraduationUseCaseResolver implements CalculateDetailGraduationUseCaseResolver { - - private final List calculateDetailGraduationUseCases; - - @Override - public CalculateDetailGraduationUseCase resolveCalculateDetailGraduationUseCase( - GraduationCategory graduationCategory) { - return calculateDetailGraduationUseCases.stream() - .filter(calculateDetailGraduationUseCase -> calculateDetailGraduationUseCase.supports(graduationCategory)) - .findFirst() - .orElseThrow(() -> new RuntimeException("No calculate detail graduation case found")); - } - -} diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/domain/model/TakenLectureInventory.java b/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/domain/model/TakenLectureInventory.java index 83a089c4..afafa30a 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/domain/model/TakenLectureInventory.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/takenlecture/domain/model/TakenLectureInventory.java @@ -42,10 +42,10 @@ public void handleFinishedTakenLectures(Set finishedTakenLecture) takenLecture.removeAll(finishedTakenLecture); } - public void handleFinishedLectures(Set finishedBasicAcademicalCultureLecture) { + public void sync(Set finishedLectures) { takenLecture.removeAll( takenLecture.stream() - .filter(taken -> finishedBasicAcademicalCultureLecture.contains(taken.getLecture())) + .filter(taken -> finishedLectures.contains(taken.getLecture())) .collect(Collectors.toSet()) ); } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/usecase/update/UpdateStudentInformationCommand.java b/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/usecase/update/UpdateStudentInformationCommand.java index 31a3c684..ca5233b5 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/usecase/update/UpdateStudentInformationCommand.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/user/application/usecase/update/UpdateStudentInformationCommand.java @@ -1,5 +1,6 @@ package com.plzgraduate.myongjigraduatebe.user.application.usecase.update; +import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationResult; import com.plzgraduate.myongjigraduatebe.parsing.domain.ParsingInformation; import com.plzgraduate.myongjigraduatebe.user.domain.model.StudentCategory; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; @@ -53,4 +54,18 @@ public static UpdateStudentInformationCommand of(User user, ParsingInformation p .studentCategory(parsingInformation.getStudentCategory()) .build(); } + + public static UpdateStudentInformationCommand update(User user, GraduationResult graduationResult) { + return UpdateStudentInformationCommand.builder() + .user(user) + .name(user.getName()) + .studentCategory(user.getStudentCategory()) + .major(user.getPrimaryMajor()) + .dualMajor(user.getDualMajor()) + .subMajor(user.getSubMajor()) + .totalCredit(graduationResult.getTotalCredit()) + .takenCredit(graduationResult.getTakenCredit()) + .graduate(graduationResult.isGraduated()) + .build(); + } } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/user/domain/model/User.java b/src/main/java/com/plzgraduate/myongjigraduatebe/user/domain/model/User.java index 43ac2184..c9ca5878 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/user/domain/model/User.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/user/domain/model/User.java @@ -1,10 +1,15 @@ package com.plzgraduate.myongjigraduatebe.user.domain.model; +import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.MajorType.DUAL; +import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.MajorType.PRIMARY; + import java.time.Instant; import java.util.Objects; import org.springframework.security.crypto.password.PasswordEncoder; +import com.plzgraduate.myongjigraduatebe.graduation.domain.model.MajorType; + import lombok.Builder; import lombok.Getter; @@ -105,6 +110,15 @@ public boolean isMyAuthId(String authId) { return this.authId.equals(authId); } + public String getMajorByMajorType(MajorType majorType) { + if(majorType == PRIMARY) { + return primaryMajor; + } else if(majorType == DUAL) { + return dualMajor; + } + return subMajor; + } + private static int parseEntryYearInStudentNumber(String studentNumber) { return Integer.parseInt(studentNumber.substring(2, 4)); } diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/api/SingleCalculateDetailGraduationUseCaseResolverTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/api/SingleCalculateDetailGraduationUseCaseResolverTest.java deleted file mode 100644 index 2d21459e..00000000 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/api/SingleCalculateDetailGraduationUseCaseResolverTest.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.plzgraduate.myongjigraduatebe.graduation.api; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.ValueSource; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.ActiveProfiles; - -import com.plzgraduate.myongjigraduatebe.graduation.application.usecase.CalculateDetailGraduationUseCase; -import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory; -import com.plzgraduate.myongjigraduatebe.graduation.support.resolver.SingleCalculateDetailGraduationUseCaseResolver; - -@SpringBootTest -@ActiveProfiles("test") -class SingleCalculateDetailGraduationUseCaseResolverTest { - - @Autowired - private SingleCalculateDetailGraduationUseCaseResolver singleCalculateDetailGraduationUseCaseResolver; - - @DisplayName("졸업 카테고리를 계산할 수 있는 CalculateDetailGraduationUseCaseResolver 반환한다.") - @ValueSource(strings = - {"COMMON_CULTURE", "CORE_CULTURE", "PRIMARY_MANDATORY_MAJOR", "PRIMARY_ELECTIVE_MAJOR", "DUAL_MANDATORY_MAJOR", - "DUAL_ELECTIVE_MAJOR", "SUB_MAJOR", "PRIMARY_BASIC_ACADEMICAL_CULTURE", "DUAL_BASIC_ACADEMICAL_CULTURE" - }) - @ParameterizedTest - void resolveCalculateDetailGraduationUseCase(String graduationCategoryName) { - //given - GraduationCategory graduationCategory = GraduationCategory.valueOf(graduationCategoryName); - - // when - CalculateDetailGraduationUseCase calculateDetailGraduationUseCase = singleCalculateDetailGraduationUseCaseResolver.resolveCalculateDetailGraduationUseCase( - graduationCategory); - - //then - assertThat(calculateDetailGraduationUseCase.supports(graduationCategory)).isEqualTo(true); - } -} diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateBasicAcademicalCultureGraduationServiceTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateBasicAcademicalCultureGraduationServiceTest.java new file mode 100644 index 00000000..27cea0de --- /dev/null +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateBasicAcademicalCultureGraduationServiceTest.java @@ -0,0 +1,126 @@ +package com.plzgraduate.myongjigraduatebe.graduation.application.service; + +import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.*; +import static com.plzgraduate.myongjigraduatebe.user.domain.model.College.BUSINESS; +import static com.plzgraduate.myongjigraduatebe.user.domain.model.College.ICT; +import static com.plzgraduate.myongjigraduatebe.user.domain.model.StudentCategory.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.BDDMockito.given; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailGraduationResult; +import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationRequirement; +import com.plzgraduate.myongjigraduatebe.graduation.domain.service.basicacademicalculture.BasicAcademicalGraduationManager; +import com.plzgraduate.myongjigraduatebe.graduation.domain.service.basicacademicalculture.BusinessBasicAcademicalGraduationManager; +import com.plzgraduate.myongjigraduatebe.graduation.domain.service.basicacademicalculture.DefaultBasicAcademicalGraduationManager; +import com.plzgraduate.myongjigraduatebe.graduation.domain.service.basicacademicalculture.SocialScienceBasicAcademicGraduationManager; +import com.plzgraduate.myongjigraduatebe.lecture.application.port.FindBasicAcademicalCulturePort; +import com.plzgraduate.myongjigraduatebe.lecture.domain.model.BasicAcademicalCultureLecture; +import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; +import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture; +import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; +import com.plzgraduate.myongjigraduatebe.user.domain.model.User; + +@ExtendWith(MockitoExtension.class) +class CalculateBasicAcademicalCultureGraduationServiceTest { + + @Mock + private FindBasicAcademicalCulturePort findBasicAcademicalCulturePort; + + private CalculateBasicAcademicalCultureGraduationService calculateBasicAcademicalCultureGraduationService; + + private User user; + + @BeforeEach + void setUp() { + List basicAcademicalGraduationManagers = + List.of(new DefaultBasicAcademicalGraduationManager(), new BusinessBasicAcademicalGraduationManager(), new SocialScienceBasicAcademicGraduationManager()); + calculateBasicAcademicalCultureGraduationService = new CalculateBasicAcademicalCultureGraduationService(findBasicAcademicalCulturePort, basicAcademicalGraduationManagers); + user = User.builder() + .id(1L) + .primaryMajor("응용소프트웨어전공") + .dualMajor("경영학과") + .studentCategory(DUAL_MAJOR) + .entryYear(19).build(); + } + + @DisplayName("BASIC_ACADEMICAL_CULTURE 관련 카테고리 일때만 BasicAcademicalCultureGraduationService를 호출한다.") + @Test + void shouldSupportBasicAcademicalCultureCategory() { + assertTrue(calculateBasicAcademicalCultureGraduationService.supports(PRIMARY_BASIC_ACADEMICAL_CULTURE)); + assertTrue(calculateBasicAcademicalCultureGraduationService.supports(DUAL_BASIC_ACADEMICAL_CULTURE)); + assertFalse(calculateBasicAcademicalCultureGraduationService.supports(CORE_CULTURE)); + assertFalse(calculateBasicAcademicalCultureGraduationService.supports(COMMON_CULTURE)); + } + + + @DisplayName("카테고리별 계산 시 유저의 핵심교양 상세 졸업결과를 계산한다.") + @Test + void shouldCalculateSingleDetailGraduationIfPrimaryCategory() { + //given + HashSet graduationCoreCultures = new HashSet<>( + Set.of(BasicAcademicalCultureLecture.of(Lecture.from("KMA02128"), ICT.getName()))); + given(findBasicAcademicalCulturePort.findBasicAcademicalCulture(anyString())).willReturn(graduationCoreCultures); + + HashSet takenLectures = new HashSet<>( + Set.of( + TakenLecture.builder().lecture(Lecture.builder() + .lectureCode("KMA02128") + .credit(3).build()).build())); + TakenLectureInventory takenLectureInventory = TakenLectureInventory.from(takenLectures); + + GraduationRequirement graduationRequirement = GraduationRequirement.builder() + .primaryBasicAcademicalCultureCredit(18).build(); + + //when + DetailGraduationResult detailCoreCultureGraduationResult = calculateBasicAcademicalCultureGraduationService.calculateSingleDetailGraduation( + user, PRIMARY_BASIC_ACADEMICAL_CULTURE, takenLectureInventory, graduationRequirement); + + //then + assertThat(detailCoreCultureGraduationResult) + .extracting("graduationCategory", "isCompleted", "totalCredit", "takenCredit") + .contains(PRIMARY_BASIC_ACADEMICAL_CULTURE, false, 18, 3.0); + } + + @DisplayName("카테고리별 계산 시 유저의 복수전공 핵심교양 상세 졸업결과를 계산한다.") + @Test + void shouldCalculateSingleDetailGraduationIfDualCategory() { + //given + HashSet graduationBasicAcademicalCultures = new HashSet<>( + Set.of(BasicAcademicalCultureLecture.of(Lecture.from("KMA02128"), BUSINESS.getName()))); + + HashSet takenLectures = new HashSet<>( + Set.of( + TakenLecture.builder().lecture(Lecture.builder() + .lectureCode("KMA02128") + .credit(3).build()).build())); + TakenLectureInventory takenLectureInventory = TakenLectureInventory.from(takenLectures); + + GraduationRequirement graduationRequirement = GraduationRequirement.builder() + .dualBasicAcademicalCultureCredit(18).build(); + + + given(findBasicAcademicalCulturePort.findBasicAcademicalCulture(anyString())).willReturn(graduationBasicAcademicalCultures); + + //when + DetailGraduationResult detailCoreCultureGraduationResult = calculateBasicAcademicalCultureGraduationService.calculateSingleDetailGraduation( + user, DUAL_BASIC_ACADEMICAL_CULTURE, takenLectureInventory, graduationRequirement); + + //then + assertThat(detailCoreCultureGraduationResult) + .extracting("graduationCategory", "isCompleted", "totalCredit", "takenCredit") + .contains(DUAL_BASIC_ACADEMICAL_CULTURE, false, 18, 3.0); + } +} diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateCommonCultureGraduationServiceTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateCommonCultureGraduationServiceTest.java index da158ebb..4e813e34 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateCommonCultureGraduationServiceTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateCommonCultureGraduationServiceTest.java @@ -3,11 +3,13 @@ import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.COMMON_CULTURE; import static com.plzgraduate.myongjigraduatebe.lecture.domain.model.CommonCultureCategory.CHRISTIAN_A; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.BDDMockito.given; import java.util.HashSet; import java.util.Set; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -16,7 +18,9 @@ import org.mockito.junit.jupiter.MockitoExtension; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailGraduationResult; +import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationRequirement; +import com.plzgraduate.myongjigraduatebe.graduation.domain.service.commonculture.CommonGraduationManager; import com.plzgraduate.myongjigraduatebe.lecture.application.port.FindCommonCulturePort; import com.plzgraduate.myongjigraduatebe.lecture.domain.model.CommonCulture; import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; @@ -29,12 +33,27 @@ class CalculateCommonCultureGraduationServiceTest { @Mock private FindCommonCulturePort findCommonCulturePort; + @InjectMocks private CalculateCommonCultureGraduationService calculateCommonCultureGraduationService; + @BeforeEach + void setUp() { + CommonGraduationManager commonGraduationManager = new CommonGraduationManager(); + calculateCommonCultureGraduationService = new CalculateCommonCultureGraduationService(findCommonCulturePort, + commonGraduationManager); + } + + @DisplayName("COMMON_CULTURE 카테고리 일때만 CommonCultureGraduationService를 호출한다.") + @Test + void shouldSupportCommonCultureCategory() { + assertTrue(calculateCommonCultureGraduationService.supports(GraduationCategory.COMMON_CULTURE)); + assertFalse(calculateCommonCultureGraduationService.supports(GraduationCategory.CORE_CULTURE)); + } + @DisplayName("유저의 공통교양 상세 졸업결과를 계산한다.") @Test - void calculateCommonCulture() { + void shouldCalculateCommonCulture() { //given User user = User.builder() .id(1L) @@ -42,21 +61,20 @@ void calculateCommonCulture() { .entryYear(19).build(); HashSet graduationCommonCultures = new HashSet<>( Set.of(CommonCulture.of(Lecture.from("KMA00101"), CHRISTIAN_A))); - given(findCommonCulturePort.findCommonCulture(user)).willReturn(graduationCommonCultures); - HashSet takenLectures = new HashSet<>( Set.of( TakenLecture.builder().lecture(Lecture.builder() .lectureCode("KMA00101") .credit(2).build()).build())); TakenLectureInventory takenLectureInventory = TakenLectureInventory.from(takenLectures); - GraduationRequirement graduationRequirement = GraduationRequirement.builder() .commonCultureCredit(17).build(); + given(findCommonCulturePort.findCommonCulture(user)).willReturn(graduationCommonCultures); + //when - DetailGraduationResult detailCommonCultureGraduationResult = calculateCommonCultureGraduationService.calculateDetailGraduation( - user, takenLectureInventory, graduationRequirement); + DetailGraduationResult detailCommonCultureGraduationResult = calculateCommonCultureGraduationService.calculateSingleDetailGraduation( + user, COMMON_CULTURE, takenLectureInventory, graduationRequirement); //then assertThat(detailCommonCultureGraduationResult) diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateCoreCultureGraduationServiceTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateCoreCultureGraduationServiceTest.java index 41f77eca..c4b48953 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateCoreCultureGraduationServiceTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateCoreCultureGraduationServiceTest.java @@ -3,20 +3,24 @@ import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.CORE_CULTURE; import static com.plzgraduate.myongjigraduatebe.lecture.domain.model.CoreCultureCategory.CULTURE_ART; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.BDDMockito.given; import java.util.HashSet; import java.util.Set; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailGraduationResult; +import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationRequirement; +import com.plzgraduate.myongjigraduatebe.graduation.domain.service.coreculture.CoreGraduationManager; import com.plzgraduate.myongjigraduatebe.lecture.application.port.FindCoreCulturePort; import com.plzgraduate.myongjigraduatebe.lecture.domain.model.CoreCulture; import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; @@ -29,20 +33,32 @@ class CalculateCoreCultureGraduationServiceTest { @Mock private FindCoreCulturePort findCoreCulturePort; - @InjectMocks private CalculateCoreCultureGraduationService calculateCoreCultureGraduationService; + @BeforeEach + void setUp() { + calculateCoreCultureGraduationService = new CalculateCoreCultureGraduationService(findCoreCulturePort, new CoreGraduationManager()); + } + + @DisplayName("CORE_CULTURE 카테고리 일때만 CoreCultureGraduationService를 호출한다.") + @Test + void shouldSupportCoreCultureCategory() { + assertTrue(calculateCoreCultureGraduationService.supports(GraduationCategory.CORE_CULTURE)); + assertFalse(calculateCoreCultureGraduationService.supports(GraduationCategory.COMMON_CULTURE)); + } + @DisplayName("유저의 핵심교양 상세 졸업결과를 계산한다.") @Test - void calculateCoreCulture() { + void shouldCalculateCoreCulture() { //given User user = User.builder() .id(1L) .primaryMajor("응용소프트웨어전공") - .entryYear(19).build(); + .entryYear(19) + .build(); HashSet graduationCoreCultures = new HashSet<>( Set.of(CoreCulture.of(Lecture.from("KMA02128"), CULTURE_ART))); - given(findCoreCulturePort.findCoreCulture(user)).willReturn(graduationCoreCultures); + int coreCultureTotalCredit = 12; HashSet takenLectures = new HashSet<>( Set.of( @@ -50,13 +66,14 @@ void calculateCoreCulture() { .lectureCode("KMA02128") .credit(3).build()).build())); TakenLectureInventory takenLectureInventory = TakenLectureInventory.from(takenLectures); - GraduationRequirement graduationRequirement = GraduationRequirement.builder() - .coreCultureCredit(12).build(); + .coreCultureCredit(coreCultureTotalCredit).build(); + + given(findCoreCulturePort.findCoreCulture(user)).willReturn(graduationCoreCultures); //when - DetailGraduationResult detailCoreCultureGraduationResult = calculateCoreCultureGraduationService.calculateDetailGraduation( - user, takenLectureInventory, graduationRequirement); + DetailGraduationResult detailCoreCultureGraduationResult = calculateCoreCultureGraduationService.calculateSingleDetailGraduation( + user, CORE_CULTURE, takenLectureInventory, graduationRequirement); //then assertThat(detailCoreCultureGraduationResult) diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateDualBasicAcademicalCultureDetailGraduationServiceTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateDualBasicAcademicalCultureDetailGraduationServiceTest.java deleted file mode 100644 index d6106bb0..00000000 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateDualBasicAcademicalCultureDetailGraduationServiceTest.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.plzgraduate.myongjigraduatebe.graduation.application.service; - -import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.DUAL_BASIC_ACADEMICAL_CULTURE; -import static com.plzgraduate.myongjigraduatebe.user.domain.model.College.ICT; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.BDDMockito.given; - -import java.util.HashSet; -import java.util.Set; - -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; - -import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailGraduationResult; -import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationRequirement; -import com.plzgraduate.myongjigraduatebe.lecture.application.port.FindBasicAcademicalCulturePort; -import com.plzgraduate.myongjigraduatebe.lecture.domain.model.BasicAcademicalCultureLecture; -import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; -import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture; -import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; -import com.plzgraduate.myongjigraduatebe.user.domain.model.User; - -@ExtendWith(MockitoExtension.class) -class CalculateDualBasicAcademicalCultureDetailGraduationServiceTest { - - @Mock - private FindBasicAcademicalCulturePort findBasicAcademicalCulturePort; - @InjectMocks - private CalculateDualBasicAcademicalCultureDetailGraduationService calculateDualBasicAcademicalCultureDetailGraduationService; - - @DisplayName("유저의 복수전공 핵심교양 상세 졸업결과를 계산한다.") - @Test - void calculateCoreCulture() { - //given - User user = User.builder() - .id(1L) - .dualMajor("응용소프트웨어전공") - .entryYear(19).build(); - HashSet graduationCoreCultures = new HashSet<>( - Set.of(BasicAcademicalCultureLecture.of(Lecture.from("KMA02128"), ICT.getName()))); - given(findBasicAcademicalCulturePort.findBasicAcademicalCulture(user.getDualMajor())).willReturn(graduationCoreCultures); - - HashSet takenLectures = new HashSet<>( - Set.of( - TakenLecture.builder().lecture(Lecture.builder() - .lectureCode("KMA02128") - .credit(3).build()).build())); - TakenLectureInventory takenLectureInventory = TakenLectureInventory.from(takenLectures); - - GraduationRequirement graduationRequirement = GraduationRequirement.builder() - .dualBasicAcademicalCultureCredit(18).build(); - - //when - DetailGraduationResult detailCoreCultureGraduationResult = calculateDualBasicAcademicalCultureDetailGraduationService.calculateDetailGraduation( - user, takenLectureInventory, graduationRequirement); - - //then - assertThat(detailCoreCultureGraduationResult) - .extracting("graduationCategory", "isCompleted", "totalCredit", "takenCredit") - .contains(DUAL_BASIC_ACADEMICAL_CULTURE, false, 18, 3.0); - } - -} diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateDualElectiveMajorDetailGraduationServiceTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateDualElectiveMajorDetailGraduationServiceTest.java deleted file mode 100644 index a57ddf88..00000000 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateDualElectiveMajorDetailGraduationServiceTest.java +++ /dev/null @@ -1,104 +0,0 @@ -package com.plzgraduate.myongjigraduatebe.graduation.application.service; - -import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.DUAL_ELECTIVE_MAJOR; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.BDDMockito.given; - -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; - -import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailCategoryResult; -import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailGraduationResult; -import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationRequirement; -import com.plzgraduate.myongjigraduatebe.lecture.application.port.FindMajorPort; -import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; -import com.plzgraduate.myongjigraduatebe.lecture.domain.model.MajorLecture; -import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture; -import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; -import com.plzgraduate.myongjigraduatebe.user.domain.model.User; - -@ExtendWith(MockitoExtension.class) -class CalculateDualElectiveMajorDetailGraduationServiceTest { - - @Mock - private FindMajorPort findMajorPort; - @InjectMocks - private CalculateDualElectiveMajorDetailGraduationService calculateDualElectiveMajorDetailGraduationService; - - @DisplayName("유저의 복수전공선택 졸업결과를 계산한다.") - @Test - void calculateCoreCulture() { - //given - User user = User.builder() - .id(1L) - .dualMajor("응용소프트웨어전공") - .entryYear(19).build(); - HashSet graduationMajorLectures = new HashSet<>( - Set.of( - MajorLecture.of(Lecture.builder().lectureCode("HEC01211").credit(3).build(), "응용소프트웨어전공", 1, 16, 23), - MajorLecture.of(Lecture.builder().lectureCode("HEC01304").credit(3).build(), "응용소프트웨어전공", 0, 16, 23))); - given(findMajorPort.findMajor(user.getDualMajor())).willReturn(graduationMajorLectures); - - HashSet takenLectures = new HashSet<>( - Set.of( - TakenLecture.builder().lecture(Lecture.builder() - .lectureCode("HEC01211") //전공 필수 - .credit(3).build()).build(), - TakenLecture.builder().lecture(Lecture.builder() - .lectureCode("HEC01304") //전공 선택 - .credit(3).build()).build())); - TakenLectureInventory takenLectureInventory = TakenLectureInventory.from(takenLectures); - - GraduationRequirement graduationRequirement = GraduationRequirement.builder() - .dualMajorCredit(70).build(); - - //when - DetailGraduationResult detailDualMandatoryMajorGraduationResult = calculateDualElectiveMajorDetailGraduationService.calculateDetailGraduation( - user, takenLectureInventory, graduationRequirement); - - //then - assertThat(detailDualMandatoryMajorGraduationResult) - .extracting("graduationCategory", "isCompleted", "totalCredit", "takenCredit") - .contains(DUAL_ELECTIVE_MAJOR, false, 67, 3.0); - } - - @DisplayName("복수전공 졸업결과에서 복수전공선택 졸업결과를 분리한다.") - @Test - void isolateDualElectiveMajorDetailGraduation() { - //given - DetailCategoryResult dualMandatoryMajorDetailCategoryResult = DetailCategoryResult.builder() - .detailCategoryName("전공필수") - .totalCredits(18) - .takenCredits(18) - .build(); - DetailCategoryResult dualElectiveMajorDetailCategoryResult = DetailCategoryResult.builder() - .detailCategoryName("전공선택") - .totalCredits(52) - .takenCredits(52) - .build(); - DetailGraduationResult dualMajorDetailGraduationResult = DetailGraduationResult.createNonCategorizedGraduationResult( - 70, List.of(dualMandatoryMajorDetailCategoryResult, dualElectiveMajorDetailCategoryResult)); - - //when - DetailGraduationResult primaryMandatoryMajorDetailGraduationResult = - calculateDualElectiveMajorDetailGraduationService.isolateDualElectiveMajorDetailGraduation( - dualMajorDetailGraduationResult); - - //then - assertThat(primaryMandatoryMajorDetailGraduationResult) - .extracting("graduationCategory", "totalCredit", "takenCredit") - .contains( - DUAL_ELECTIVE_MAJOR, - dualElectiveMajorDetailCategoryResult.getTotalCredits(), - dualElectiveMajorDetailCategoryResult.getTakenCredits()); - } - -} diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateDualMandatoryMajorDetailGraduationServiceTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateDualMandatoryMajorDetailGraduationServiceTest.java deleted file mode 100644 index e6f9bee4..00000000 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateDualMandatoryMajorDetailGraduationServiceTest.java +++ /dev/null @@ -1,103 +0,0 @@ -package com.plzgraduate.myongjigraduatebe.graduation.application.service; - -import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.DUAL_MANDATORY_MAJOR; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.BDDMockito.given; - -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; - -import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailCategoryResult; -import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailGraduationResult; -import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationRequirement; -import com.plzgraduate.myongjigraduatebe.lecture.application.port.FindMajorPort; -import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; -import com.plzgraduate.myongjigraduatebe.lecture.domain.model.MajorLecture; -import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture; -import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; -import com.plzgraduate.myongjigraduatebe.user.domain.model.User; - -@ExtendWith(MockitoExtension.class) -class CalculateDualMandatoryMajorDetailGraduationServiceTest { - - @Mock - private FindMajorPort findMajorPort; - @InjectMocks - private CalculateDualMandatoryMajorDetailGraduationService calculateDualMandatoryMajorDetailGraduationService; - - @DisplayName("유저의 복수전공필수 졸업결과를 계산한다.") - @Test - void calculateCoreCulture() { - //given - User user = User.builder() - .id(1L) - .dualMajor("응용소프트웨어전공") - .entryYear(19).build(); - HashSet graduationMajorLectures = new HashSet<>( - Set.of( - MajorLecture.of(Lecture.builder().lectureCode("HEC01211").credit(3).build(), "응용소프트웨어전공", 1, 16, 23), - MajorLecture.of(Lecture.builder().lectureCode("HEC01204").credit(3).build(), "응용소프트웨어전공", 1, 16, 23))); - given(findMajorPort.findMajor(user.getDualMajor())).willReturn(graduationMajorLectures); - - HashSet takenLectures = new HashSet<>( - Set.of( - TakenLecture.builder().lecture(Lecture.builder() - .lectureCode("HEC01211") //전공 필수 - .credit(3).build()).build(), - TakenLecture.builder().lecture(Lecture.builder() - .lectureCode("HEC01305") //전공 선택 - .credit(3).build()).build())); - TakenLectureInventory takenLectureInventory = TakenLectureInventory.from(takenLectures); - - GraduationRequirement graduationRequirement = GraduationRequirement.builder() - .dualMajorCredit(70).build(); - - //when - DetailGraduationResult detailDualMandatoryMajorGraduationResult = calculateDualMandatoryMajorDetailGraduationService.calculateDetailGraduation( - user, takenLectureInventory, graduationRequirement); - - //then - assertThat(detailDualMandatoryMajorGraduationResult) - .extracting("graduationCategory", "isCompleted", "totalCredit", "takenCredit") - .contains(DUAL_MANDATORY_MAJOR, false, 6, 3.0); - } - - @DisplayName("복수전공 졸업결과에서 복수전공필수 졸업결과를 분리한다.") - @Test - void isolateDualElectiveMajorDetailGraduation() { - //given - DetailCategoryResult dualMandatoryMajorDetailCategoryResult = DetailCategoryResult.builder() - .detailCategoryName("전공필수") - .totalCredits(18) - .takenCredits(18) - .build(); - DetailCategoryResult dualElectiveMajorDetailCategoryResult = DetailCategoryResult.builder() - .detailCategoryName("전공선택") - .totalCredits(52) - .takenCredits(52) - .build(); - DetailGraduationResult dualMajorDetailGraduationResult = DetailGraduationResult.createNonCategorizedGraduationResult( - 70, List.of(dualMandatoryMajorDetailCategoryResult, dualElectiveMajorDetailCategoryResult)); - - //when - DetailGraduationResult dualMandatoryMajorDetailGraduationResult = calculateDualMandatoryMajorDetailGraduationService.isolateDualMandatoryMajorDetailGraduation( - dualMajorDetailGraduationResult); - - //then - assertThat(dualMandatoryMajorDetailGraduationResult) - .extracting("graduationCategory", "totalCredit", "takenCredit") - .contains( - DUAL_MANDATORY_MAJOR, - dualMandatoryMajorDetailCategoryResult.getTotalCredits(), - dualMandatoryMajorDetailCategoryResult.getTakenCredits()); - } - -} diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateMajorGraduationServiceTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateMajorGraduationServiceTest.java new file mode 100644 index 00000000..2a20f493 --- /dev/null +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateMajorGraduationServiceTest.java @@ -0,0 +1,219 @@ +package com.plzgraduate.myongjigraduatebe.graduation.application.service; + +import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.BDDMockito.given; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailGraduationResult; +import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationRequirement; +import com.plzgraduate.myongjigraduatebe.graduation.domain.service.major.ElectiveMajorManager; +import com.plzgraduate.myongjigraduatebe.graduation.domain.service.major.MajorGraduationManager; +import com.plzgraduate.myongjigraduatebe.graduation.domain.service.major.MandatoryMajorManager; +import com.plzgraduate.myongjigraduatebe.graduation.domain.service.major.OptionalMandatoryMajorHandler; +import com.plzgraduate.myongjigraduatebe.graduation.domain.service.major.ReplaceMandatoryMajorHandler; +import com.plzgraduate.myongjigraduatebe.graduation.domain.service.submajor.SubMajorGraduationManager; +import com.plzgraduate.myongjigraduatebe.lecture.application.port.FindMajorPort; +import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; +import com.plzgraduate.myongjigraduatebe.lecture.domain.model.MajorLecture; +import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture; +import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; +import com.plzgraduate.myongjigraduatebe.user.domain.model.User; + +@ExtendWith(MockitoExtension.class) +class CalculateMajorGraduationServiceTest { + + @Mock + private FindMajorPort findMajorPort; + + private CalculateMajorGraduationService calculateMajorGraduationService; + + + @BeforeEach + void setUp() { + MandatoryMajorManager mandatoryMajorManager = new MandatoryMajorManager( + List.of(new OptionalMandatoryMajorHandler(), new ReplaceMandatoryMajorHandler())); + ElectiveMajorManager electiveMajorManager = new ElectiveMajorManager(); + SubMajorGraduationManager subMajorGraduationManager = new SubMajorGraduationManager(); + MajorGraduationManager majorGraduationManager = new MajorGraduationManager(mandatoryMajorManager, electiveMajorManager); + calculateMajorGraduationService = new CalculateMajorGraduationService(findMajorPort, majorGraduationManager, subMajorGraduationManager); + } + + @DisplayName("MAJOR 관련 카테고리 일때만 MajorGraduationService를 호출한다.") + @Test + void shouldSupportMajorCategory() { + assertTrue(calculateMajorGraduationService.supports(PRIMARY_MANDATORY_MAJOR)); + assertTrue(calculateMajorGraduationService.supports(PRIMARY_ELECTIVE_MAJOR)); + assertTrue(calculateMajorGraduationService.supports(DUAL_MANDATORY_MAJOR)); + assertTrue(calculateMajorGraduationService.supports(DUAL_ELECTIVE_MAJOR)); + assertTrue(calculateMajorGraduationService.supports(SUB_MAJOR)); + assertFalse(calculateMajorGraduationService.supports(COMMON_CULTURE)); + assertFalse(calculateMajorGraduationService.supports(CORE_CULTURE)); + assertFalse(calculateMajorGraduationService.supports(PRIMARY_BASIC_ACADEMICAL_CULTURE)); + assertFalse(calculateMajorGraduationService.supports(DUAL_BASIC_ACADEMICAL_CULTURE)); + } + + @DisplayName("유저의 주전공필수 졸업결과를 계산한다.") + @Test + void shouldCalculateSingleDetailGraduationIfPrimaryMandatory() { + //given + User user = User.builder() + .id(1L) + .primaryMajor("응용소프트웨어전공") + .entryYear(19).build(); + HashSet graduationMajorLectures = new HashSet<>( + Set.of( + MajorLecture.of(Lecture.builder().lectureCode("HEC01211").credit(3).build(), "응용소프트웨어전공", 1, 16, 23), + MajorLecture.of(Lecture.builder().lectureCode("HEC01204").credit(3).build(), "응용소프트웨어전공", 1, 16, 23))); + given(findMajorPort.findMajor(user.getPrimaryMajor())).willReturn(graduationMajorLectures); + + HashSet takenLectures = new HashSet<>( + Set.of( + TakenLecture.builder().lecture(Lecture.builder() + .lectureCode("HEC01211") //전공 필수 + .credit(3).build()).build(), + TakenLecture.builder().lecture(Lecture.builder() + .lectureCode("HEC01305") //전공 선택 + .credit(3).build()).build())); + TakenLectureInventory takenLectureInventory = TakenLectureInventory.from(takenLectures); + + GraduationRequirement graduationRequirement = GraduationRequirement.builder() + .primaryMajorCredit(70).build(); + + //when + DetailGraduationResult detailPrimaryMandatoryMajorGraduationResult = calculateMajorGraduationService.calculateSingleDetailGraduation( + user, PRIMARY_MANDATORY_MAJOR, takenLectureInventory, graduationRequirement); + + //then + assertThat(detailPrimaryMandatoryMajorGraduationResult) + .extracting("graduationCategory", "isCompleted", "totalCredit", "takenCredit") + .contains(PRIMARY_MANDATORY_MAJOR, false, 6, 3.0); + } + + @DisplayName("유저의 주전공선택 상세 졸업결과를 계산한다.") + @Test + void calculateSingleDetailGraduationIfPrimaryElective() { + //given + User user = User.builder() + .id(1L) + .primaryMajor("응용소프트웨어전공") + .entryYear(19).build(); + HashSet graduationMajorLectures = new HashSet<>( + Set.of( + // 전공 필수 + MajorLecture.of(Lecture.builder().lectureCode("HEC01211").credit(3).build(), "응용소프트웨어전공", 1, 16, 23), + // 전공 선택 + MajorLecture.of(Lecture.builder().lectureCode("HEC01305").credit(3).build(), "응용소프트웨어전공", 0, 16, 23), + // 전공 선택 + MajorLecture.of(Lecture.builder().lectureCode("HEC01318").credit(3).build(), "응용소프트웨어전공", 0, 16, 23))); + given(findMajorPort.findMajor(user.getPrimaryMajor())).willReturn(graduationMajorLectures); + + HashSet takenLectures = new HashSet<>( + Set.of( + TakenLecture.builder().lecture(Lecture.builder() + .lectureCode("HEC01211") //전공 필수 + .credit(3).build()).build(), + TakenLecture.builder().lecture(Lecture.builder() + .lectureCode("HEC01305") //전공 선택 + .credit(3).build()).build())); + TakenLectureInventory takenLectureInventory = TakenLectureInventory.from(takenLectures); + + GraduationRequirement graduationRequirement = GraduationRequirement.builder() + .primaryMajorCredit(70).build(); + + //when + DetailGraduationResult detailPrimaryElectiveMajorGraduationResult = calculateMajorGraduationService.calculateSingleDetailGraduation( + user, PRIMARY_ELECTIVE_MAJOR, takenLectureInventory, graduationRequirement); + + //then + assertThat(detailPrimaryElectiveMajorGraduationResult) + .extracting("graduationCategory", "isCompleted", "totalCredit", "takenCredit") + .contains(PRIMARY_ELECTIVE_MAJOR, false, 67, 3.0); + } + + @DisplayName("유저의 복수전공필수 졸업결과를 계산한다.") + @Test + void calculateSingleDetailGraduationIfDualMandatory() { + //given + User user = User.builder() + .id(1L) + .dualMajor("응용소프트웨어전공") + .entryYear(19).build(); + HashSet graduationMajorLectures = new HashSet<>( + Set.of( + MajorLecture.of(Lecture.builder().lectureCode("HEC01211").credit(3).build(), "응용소프트웨어전공", 1, 16, 23), + MajorLecture.of(Lecture.builder().lectureCode("HEC01204").credit(3).build(), "응용소프트웨어전공", 1, 16, 23))); + given(findMajorPort.findMajor(user.getDualMajor())).willReturn(graduationMajorLectures); + + HashSet takenLectures = new HashSet<>( + Set.of( + TakenLecture.builder().lecture(Lecture.builder() + .lectureCode("HEC01211") //전공 필수 + .credit(3).build()).build(), + TakenLecture.builder().lecture(Lecture.builder() + .lectureCode("HEC01305") //전공 선택 + .credit(3).build()).build())); + TakenLectureInventory takenLectureInventory = TakenLectureInventory.from(takenLectures); + + GraduationRequirement graduationRequirement = GraduationRequirement.builder() + .dualMajorCredit(70).build(); + + //when + DetailGraduationResult detailDualMandatoryMajorGraduationResult = calculateMajorGraduationService.calculateSingleDetailGraduation( + user, DUAL_MANDATORY_MAJOR, takenLectureInventory, graduationRequirement); + + //then + assertThat(detailDualMandatoryMajorGraduationResult) + .extracting("graduationCategory", "isCompleted", "totalCredit", "takenCredit") + .contains(DUAL_MANDATORY_MAJOR, false, 6, 3.0); + } + + @DisplayName("유저의 복수전공선택 졸업결과를 계산한다.") + @Test + void calculateCoreCulture() { + //given + User user = User.builder() + .id(1L) + .dualMajor("응용소프트웨어전공") + .entryYear(19).build(); + HashSet graduationMajorLectures = new HashSet<>( + Set.of( + MajorLecture.of(Lecture.builder().lectureCode("HEC01211").credit(3).build(), "응용소프트웨어전공", 1, 16, 23), + MajorLecture.of(Lecture.builder().lectureCode("HEC01304").credit(3).build(), "응용소프트웨어전공", 0, 16, 23))); + given(findMajorPort.findMajor(user.getDualMajor())).willReturn(graduationMajorLectures); + + HashSet takenLectures = new HashSet<>( + Set.of( + TakenLecture.builder().lecture(Lecture.builder() + .lectureCode("HEC01211") //전공 필수 + .credit(3).build()).build(), + TakenLecture.builder().lecture(Lecture.builder() + .lectureCode("HEC01304") //전공 선택 + .credit(3).build()).build())); + TakenLectureInventory takenLectureInventory = TakenLectureInventory.from(takenLectures); + + GraduationRequirement graduationRequirement = GraduationRequirement.builder() + .dualMajorCredit(70).build(); + + //when + DetailGraduationResult detailDualMandatoryMajorGraduationResult = calculateMajorGraduationService.calculateSingleDetailGraduation( + user, DUAL_ELECTIVE_MAJOR, takenLectureInventory, graduationRequirement); + + //then + assertThat(detailDualMandatoryMajorGraduationResult) + .extracting("graduationCategory", "isCompleted", "totalCredit", "takenCredit") + .contains(DUAL_ELECTIVE_MAJOR, false, 67, 3.0); + } +} diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculatePrimaryBasicAcademicalCultureDetailGraduationServiceTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculatePrimaryBasicAcademicalCultureDetailGraduationServiceTest.java deleted file mode 100644 index d0597f36..00000000 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculatePrimaryBasicAcademicalCultureDetailGraduationServiceTest.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.plzgraduate.myongjigraduatebe.graduation.application.service; - -import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.PRIMARY_BASIC_ACADEMICAL_CULTURE; -import static com.plzgraduate.myongjigraduatebe.user.domain.model.College.ICT; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.BDDMockito.given; - -import java.util.HashSet; -import java.util.Set; - -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; - -import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailGraduationResult; -import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationRequirement; -import com.plzgraduate.myongjigraduatebe.lecture.application.port.FindBasicAcademicalCulturePort; -import com.plzgraduate.myongjigraduatebe.lecture.domain.model.BasicAcademicalCultureLecture; -import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; -import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture; -import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; -import com.plzgraduate.myongjigraduatebe.user.domain.model.User; - -@ExtendWith(MockitoExtension.class) -class CalculatePrimaryBasicAcademicalCultureDetailGraduationServiceTest { - - @Mock - private FindBasicAcademicalCulturePort findBasicAcademicalCulturePort; - @InjectMocks - private CalculatePrimaryBasicAcademicalCultureDetailGraduationService calculatePrimaryBasicAcademicalCultureDetailGraduationService; - - @DisplayName("유저의 핵심교양 상세 졸업결과를 계산한다.") - @Test - void calculateCoreCulture() { - //given - User user = User.builder() - .id(1L) - .primaryMajor("응용소프트웨어전공") - .entryYear(19).build(); - HashSet graduationCoreCultures = new HashSet<>( - Set.of(BasicAcademicalCultureLecture.of(Lecture.from("KMA02128"), ICT.getName()))); - given(findBasicAcademicalCulturePort.findBasicAcademicalCulture(user.getPrimaryMajor())).willReturn(graduationCoreCultures); - - HashSet takenLectures = new HashSet<>( - Set.of( - TakenLecture.builder().lecture(Lecture.builder() - .lectureCode("KMA02128") - .credit(3).build()).build())); - TakenLectureInventory takenLectureInventory = TakenLectureInventory.from(takenLectures); - - GraduationRequirement graduationRequirement = GraduationRequirement.builder() - .primaryBasicAcademicalCultureCredit(18).build(); - - //when - DetailGraduationResult detailCoreCultureGraduationResult = calculatePrimaryBasicAcademicalCultureDetailGraduationService.calculateDetailGraduation( - user, takenLectureInventory, graduationRequirement); - - //then - assertThat(detailCoreCultureGraduationResult) - .extracting("graduationCategory", "isCompleted", "totalCredit", "takenCredit") - .contains(PRIMARY_BASIC_ACADEMICAL_CULTURE, false, 18, 3.0); - } - -} diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculatePrimaryElectiveMajorDetailGraduationServiceTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculatePrimaryElectiveMajorDetailGraduationServiceTest.java deleted file mode 100644 index 7f950b90..00000000 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculatePrimaryElectiveMajorDetailGraduationServiceTest.java +++ /dev/null @@ -1,107 +0,0 @@ -package com.plzgraduate.myongjigraduatebe.graduation.application.service; - -import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.PRIMARY_ELECTIVE_MAJOR; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.BDDMockito.given; - -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; - -import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailCategoryResult; -import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailGraduationResult; -import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationRequirement; -import com.plzgraduate.myongjigraduatebe.lecture.application.port.FindMajorPort; -import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; -import com.plzgraduate.myongjigraduatebe.lecture.domain.model.MajorLecture; -import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture; -import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; -import com.plzgraduate.myongjigraduatebe.user.domain.model.User; - -@ExtendWith(MockitoExtension.class) -class CalculatePrimaryElectiveMajorDetailGraduationServiceTest { - - @Mock - private FindMajorPort findMajorPort; - @InjectMocks - private CalculatePrimaryElectiveMajorDetailGraduationService calculatePrimaryElectiveMajorDetailGraduationService; - - @DisplayName("유저의 주전공선택 상세 졸업결과를 계산한다.") - @Test - void calculateCoreCulture() { - //given - User user = User.builder() - .id(1L) - .primaryMajor("응용소프트웨어전공") - .entryYear(19).build(); - HashSet graduationMajorLectures = new HashSet<>( - Set.of( - // 전공 필수 - MajorLecture.of(Lecture.builder().lectureCode("HEC01211").credit(3).build(), "응용소프트웨어전공", 1, 16, 23), - // 전공 선택 - MajorLecture.of(Lecture.builder().lectureCode("HEC01305").credit(3).build(), "응용소프트웨어전공", 0, 16, 23), - // 전공 선택 - MajorLecture.of(Lecture.builder().lectureCode("HEC01318").credit(3).build(), "응용소프트웨어전공", 0, 16, 23))); - given(findMajorPort.findMajor(user.getPrimaryMajor())).willReturn(graduationMajorLectures); - - HashSet takenLectures = new HashSet<>( - Set.of( - TakenLecture.builder().lecture(Lecture.builder() - .lectureCode("HEC01211") //전공 필수 - .credit(3).build()).build(), - TakenLecture.builder().lecture(Lecture.builder() - .lectureCode("HEC01305") //전공 선택 - .credit(3).build()).build())); - TakenLectureInventory takenLectureInventory = TakenLectureInventory.from(takenLectures); - - GraduationRequirement graduationRequirement = GraduationRequirement.builder() - .primaryMajorCredit(70).build(); - - //when - DetailGraduationResult detailPrimaryElectiveMajorGraduationResult = calculatePrimaryElectiveMajorDetailGraduationService.calculateDetailGraduation( - user, takenLectureInventory, graduationRequirement); - - //then - assertThat(detailPrimaryElectiveMajorGraduationResult) - .extracting("graduationCategory", "isCompleted", "totalCredit", "takenCredit") - .contains(PRIMARY_ELECTIVE_MAJOR, false, 67, 3.0); - } - - @DisplayName("주전공 졸업결과에서 주전공선택 졸업결과를 분리한다.") - @Test - void isolatePrimaryElectiveMajorDetailGraduation() { - //given - DetailCategoryResult primaryMandatoryMajorDetailCategoryResult = DetailCategoryResult.builder() - .detailCategoryName("전공필수") - .totalCredits(18) - .takenCredits(18) - .build(); - DetailCategoryResult primaryElectiveMajorDetailCategoryResult = DetailCategoryResult.builder() - .detailCategoryName("전공선택") - .totalCredits(52) - .takenCredits(52) - .build(); - DetailGraduationResult primaryMajorDetailGraduationResult = DetailGraduationResult.createNonCategorizedGraduationResult( - 70, List.of(primaryMandatoryMajorDetailCategoryResult, primaryElectiveMajorDetailCategoryResult)); - - //when - DetailGraduationResult primaryElectiveMajorDetailGraduationResult = calculatePrimaryElectiveMajorDetailGraduationService.isolatePrimaryElectiveMajorDetailGraduation( - primaryMajorDetailGraduationResult); - - //then - assertThat(primaryElectiveMajorDetailGraduationResult) - .extracting("graduationCategory", "totalCredit", "takenCredit") - .contains( - PRIMARY_ELECTIVE_MAJOR, - primaryElectiveMajorDetailCategoryResult.getTotalCredits(), - primaryElectiveMajorDetailCategoryResult.getTakenCredits()); - } - -} diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculatePrimaryMandatoryMajorDetailGraduationServiceTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculatePrimaryMandatoryMajorDetailGraduationServiceTest.java deleted file mode 100644 index b30454ef..00000000 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculatePrimaryMandatoryMajorDetailGraduationServiceTest.java +++ /dev/null @@ -1,103 +0,0 @@ -package com.plzgraduate.myongjigraduatebe.graduation.application.service; - -import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.PRIMARY_MANDATORY_MAJOR; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.BDDMockito.given; - -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; - -import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailCategoryResult; -import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailGraduationResult; -import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationRequirement; -import com.plzgraduate.myongjigraduatebe.lecture.application.port.FindMajorPort; -import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; -import com.plzgraduate.myongjigraduatebe.lecture.domain.model.MajorLecture; -import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture; -import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; -import com.plzgraduate.myongjigraduatebe.user.domain.model.User; - -@ExtendWith(MockitoExtension.class) -class CalculatePrimaryMandatoryMajorDetailGraduationServiceTest { - - @Mock - private FindMajorPort findMajorPort; - @InjectMocks - private CalculatePrimaryMandatoryMajorDetailGraduationService calculatePrimaryMandatoryMajorDetailGraduationService; - - @DisplayName("유저의 주전공필수 졸업결과를 계산한다.") - @Test - void calculateCoreCulture() { - //given - User user = User.builder() - .id(1L) - .primaryMajor("응용소프트웨어전공") - .entryYear(19).build(); - HashSet graduationMajorLectures = new HashSet<>( - Set.of( - MajorLecture.of(Lecture.builder().lectureCode("HEC01211").credit(3).build(), "응용소프트웨어전공", 1, 16, 23), - MajorLecture.of(Lecture.builder().lectureCode("HEC01204").credit(3).build(), "응용소프트웨어전공", 1, 16, 23))); - given(findMajorPort.findMajor(user.getPrimaryMajor())).willReturn(graduationMajorLectures); - - HashSet takenLectures = new HashSet<>( - Set.of( - TakenLecture.builder().lecture(Lecture.builder() - .lectureCode("HEC01211") //전공 필수 - .credit(3).build()).build(), - TakenLecture.builder().lecture(Lecture.builder() - .lectureCode("HEC01305") //전공 선택 - .credit(3).build()).build())); - TakenLectureInventory takenLectureInventory = TakenLectureInventory.from(takenLectures); - - GraduationRequirement graduationRequirement = GraduationRequirement.builder() - .primaryMajorCredit(70).build(); - - //when - DetailGraduationResult detailPrimaryMandatoryMajorGraduationResult = calculatePrimaryMandatoryMajorDetailGraduationService.calculateDetailGraduation( - user, takenLectureInventory, graduationRequirement); - - //then - assertThat(detailPrimaryMandatoryMajorGraduationResult) - .extracting("graduationCategory", "isCompleted", "totalCredit", "takenCredit") - .contains(PRIMARY_MANDATORY_MAJOR, false, 6, 3.0); - } - - @DisplayName("주전공 졸업결과에서 주전공필수 졸업결과를 분리한다.") - @Test - void isolatePrimaryElectiveMajorDetailGraduation() { - //given - DetailCategoryResult primaryMandatoryMajorDetailCategoryResult = DetailCategoryResult.builder() - .detailCategoryName("전공필수") - .totalCredits(18) - .takenCredits(18) - .build(); - DetailCategoryResult primaryElectiveMajorDetailCategoryResult = DetailCategoryResult.builder() - .detailCategoryName("전공선택") - .totalCredits(52) - .takenCredits(52) - .build(); - DetailGraduationResult primaryMajorDetailGraduationResult = DetailGraduationResult.createNonCategorizedGraduationResult( - 70, List.of(primaryMandatoryMajorDetailCategoryResult, primaryElectiveMajorDetailCategoryResult)); - - //when - DetailGraduationResult primaryMandatoryMajorDetailGraduationResult = calculatePrimaryMandatoryMajorDetailGraduationService.isolatePrimaryMandatoryMajorDetailGraduation( - primaryMajorDetailGraduationResult); - - //then - assertThat(primaryMandatoryMajorDetailGraduationResult) - .extracting("graduationCategory", "totalCredit", "takenCredit") - .contains( - PRIMARY_MANDATORY_MAJOR, - primaryMandatoryMajorDetailCategoryResult.getTotalCredits(), - primaryMandatoryMajorDetailCategoryResult.getTakenCredits()); - } - -} diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateSingleDetailGraduationServiceTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateSingleDetailGraduationServiceTest.java index 09ef141e..b9086668 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateSingleDetailGraduationServiceTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/application/service/CalculateSingleDetailGraduationServiceTest.java @@ -1,10 +1,14 @@ package com.plzgraduate.myongjigraduatebe.graduation.application.service; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.then; +import static org.mockito.Mockito.mock; import java.util.HashSet; +import java.util.List; +import java.util.stream.Stream; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.extension.ExtendWith; @@ -14,8 +18,8 @@ import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import com.plzgraduate.myongjigraduatebe.graduation.support.resolver.CalculateDetailGraduationUseCaseResolver; import com.plzgraduate.myongjigraduatebe.graduation.application.usecase.CalculateDetailGraduationUseCase; +import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailGraduationResult; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationRequirement; import com.plzgraduate.myongjigraduatebe.takenlecture.application.usecase.find.FindTakenLectureUseCase; @@ -24,17 +28,14 @@ import com.plzgraduate.myongjigraduatebe.user.domain.model.User; @ExtendWith(MockitoExtension.class) -class -CalculateSingleDetailGraduationServiceTest { +class CalculateSingleDetailGraduationServiceTest { @Mock private FindUserUseCase findUserUseCase; @Mock private FindTakenLectureUseCase findTakenLectureUseCase; @Mock - private CalculateDetailGraduationUseCaseResolver calculateDetailGraduationUseCaseResolver; - @Mock - private CalculateDetailGraduationUseCase calculateDetailGraduationUseCase; + private List calculateDetailGraduationUseCases; @InjectMocks private CalculateSingleDetailGraduationService calculateSingleDetailGraduationService; @@ -51,24 +52,28 @@ void calculateSingleDetailGraduation(String graduationCategoryName) { .id(1L) .entryYear(19) .primaryMajor("응용소프트웨어전공").build(); - given(findUserUseCase.findUserById(user.getId())).willReturn(user); - + GraduationCategory graduationCategory = GraduationCategory.valueOf(graduationCategoryName); + CalculateDetailGraduationUseCase calculateDetailGraduationUseCase = mock(CalculateDetailGraduationUseCase.class); TakenLectureInventory takenLectureInventory = TakenLectureInventory.from(new HashSet<>()); - given(findTakenLectureUseCase.findTakenLectures(user.getId())).willReturn( - takenLectureInventory); - GraduationCategory graduationCategory = GraduationCategory.valueOf(graduationCategoryName); - given(calculateDetailGraduationUseCaseResolver.resolveCalculateDetailGraduationUseCase( - graduationCategory)).willReturn(calculateDetailGraduationUseCase); + given(findUserUseCase.findUserById(user.getId())).willReturn(user); + given(findTakenLectureUseCase.findTakenLectures(user.getId())).willReturn(takenLectureInventory); + given(calculateDetailGraduationUseCases.stream()).willReturn(Stream.of(calculateDetailGraduationUseCase)); + given(calculateDetailGraduationUseCase.supports(graduationCategory)).willReturn(true); + given(calculateDetailGraduationUseCase.calculateSingleDetailGraduation( + any(User.class), any(GraduationCategory.class), + any(TakenLectureInventory.class), any(GraduationRequirement.class))) + .willReturn(DetailGraduationResult.create(graduationCategory, 10, List.of())); // when - calculateSingleDetailGraduationService.calculateSingleDetailGraduation( - user.getId(), graduationCategory); + DetailGraduationResult result = + calculateSingleDetailGraduationService.calculateSingleDetailGraduation(1L, graduationCategory); // then + assertNotNull(result); then(calculateDetailGraduationUseCase).should() - .calculateDetailGraduation(any(User.class), any(TakenLectureInventory.class), - any(GraduationRequirement.class)); + .calculateSingleDetailGraduation(any(User.class), any(GraduationCategory.class), + any(TakenLectureInventory.class), any(GraduationRequirement.class)); } diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/GraduationCategoryTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/GraduationCategoryTest.java new file mode 100644 index 00000000..9f6f08ec --- /dev/null +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/GraduationCategoryTest.java @@ -0,0 +1,21 @@ +package com.plzgraduate.myongjigraduatebe.graduation.domain.model; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; + +class GraduationCategoryTest { + + @DisplayName("전공 관련 GraduationCategory인 경우 전공 필수인지 선택인지 확인한다.") + @CsvSource({"PRIMARY_MANDATORY_MAJOR, true", "DUAL_MANDATORY_MAJOR, true", "PRIMARY_ELECTIVE_MAJOR, false"}) + @ParameterizedTest + void checkMandatoryOrElective(GraduationCategory graduationCategory, boolean isMandatory) { + //when + boolean result = graduationCategory.checkMandatoryIfSeperatedByMandatoryAndElective(); + + //then + assertThat(result).isEqualTo(isMandatory); + } +} diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/MajorTypeTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/MajorTypeTest.java new file mode 100644 index 00000000..674c5c89 --- /dev/null +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/MajorTypeTest.java @@ -0,0 +1,37 @@ +package com.plzgraduate.myongjigraduatebe.graduation.domain.model; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.stream.Stream; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +class MajorTypeTest { + + private static Stream provideGraduationCategoryForCreatingMajorType() { + return Stream.of( + Arguments.of(GraduationCategory.PRIMARY_MANDATORY_MAJOR, MajorType.PRIMARY), + Arguments.of(GraduationCategory.PRIMARY_ELECTIVE_MAJOR, MajorType.PRIMARY), + Arguments.of(GraduationCategory.PRIMARY_BASIC_ACADEMICAL_CULTURE, MajorType.PRIMARY), + Arguments.of(GraduationCategory.DUAL_MANDATORY_MAJOR, MajorType.DUAL), + Arguments.of(GraduationCategory.DUAL_ELECTIVE_MAJOR, MajorType.DUAL), + Arguments.of(GraduationCategory.DUAL_BASIC_ACADEMICAL_CULTURE, MajorType.DUAL), + Arguments.of(GraduationCategory.SUB_MAJOR, MajorType.SUB) + ); + } + + @DisplayName("GraduationCategory별로 올바른 MajorType이 반환되는지 확인한다.") + @MethodSource("provideGraduationCategoryForCreatingMajorType") + @ParameterizedTest + void getMajorByGraduationCategory(GraduationCategory graduationCategory, MajorType majorType) { + + //when + MajorType result = MajorType.from(graduationCategory); + + //then + assertThat(result).isEqualTo(majorType); + } +} diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/BusinessBasicAcademicalManagerTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/BusinessBasicAcademicalGraduationManagerTest.java similarity index 93% rename from src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/BusinessBasicAcademicalManagerTest.java rename to src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/BusinessBasicAcademicalGraduationManagerTest.java index 82f0dbfd..c8a66f1b 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/BusinessBasicAcademicalManagerTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/BusinessBasicAcademicalGraduationManagerTest.java @@ -1,6 +1,5 @@ package com.plzgraduate.myongjigraduatebe.graduation.domain.service.basicacademicalculture; -import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.*; import static org.assertj.core.api.Assertions.assertThat; import java.util.HashSet; @@ -25,7 +24,7 @@ import com.plzgraduate.myongjigraduatebe.user.domain.model.User; @DisplayName("경영대의 학문기초교양 결과를 반환한다.") -class BusinessBasicAcademicalManagerTest { +class BusinessBasicAcademicalGraduationManagerTest { @DisplayName("경영학과의 학문기초교양 결과를 계산한다.") @Nested @@ -45,7 +44,7 @@ class 경영학과_학문기초교양 { TakenLecture.of(user, mockLectureMap.get("KMD02107"), 2019, Semester.FIRST) ))); TakenLectureInventory takenLectureInventory = TakenLectureInventory.from(takenLectures); - BasicAcademicalManager manager = new BusinessBasicAcademicalManager(); + BasicAcademicalGraduationManager manager = new BusinessBasicAcademicalGraduationManager(); //when DetailGraduationResult detailGraduationResult = manager.createDetailGraduationResult(user, @@ -78,7 +77,7 @@ class 경영학과_학문기초교양 { TakenLecture.of(user, mockLectureMap.get("KMD02107"), 2019, Semester.FIRST) ))); TakenLectureInventory takenLectureInventory = TakenLectureInventory.from(takenLectures); - BasicAcademicalManager manager = new BusinessBasicAcademicalManager(); + BasicAcademicalGraduationManager manager = new BusinessBasicAcademicalGraduationManager(); //when DetailGraduationResult detailGraduationResult = manager.createDetailGraduationResult(user, diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/DefaultBasicAcademicalManagerTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/DefaultBasicAcademicalGraduationManagerTest.java similarity index 94% rename from src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/DefaultBasicAcademicalManagerTest.java rename to src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/DefaultBasicAcademicalGraduationManagerTest.java index 9245a3ae..f9bdaf0c 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/DefaultBasicAcademicalManagerTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/DefaultBasicAcademicalGraduationManagerTest.java @@ -15,7 +15,6 @@ import com.plzgraduate.myongjigraduatebe.fixture.UserFixture; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailCategoryResult; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailGraduationResult; -import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory; import com.plzgraduate.myongjigraduatebe.lecture.domain.model.BasicAcademicalCultureLecture; import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.Semester; @@ -24,7 +23,7 @@ import com.plzgraduate.myongjigraduatebe.user.domain.model.User; @DisplayName("기본 단과대에 대해 학문기초교양 결과를 반환한다.") -class DefaultBasicAcademicalManagerTest { +class DefaultBasicAcademicalGraduationManagerTest { @DisplayName("인문대의 학문기초교양을 계산한다.") @Nested @@ -45,7 +44,7 @@ class 인문대_학문기초교양 { TakenLecture.of(user, mockLectureMap.get("KMB02122"), 2021, Semester.FIRST) ))); TakenLectureInventory takenLectureInventory = TakenLectureInventory.from(takenLectures); - BasicAcademicalManager manager = new DefaultBasicAcademicalManager(); + BasicAcademicalGraduationManager manager = new DefaultBasicAcademicalGraduationManager(); //when DetailGraduationResult detailGraduationResult = manager.createDetailGraduationResult(user, @@ -76,7 +75,7 @@ class 인문대_학문기초교양 { TakenLecture.of(user, mockLectureMap.get("KMB02120"), 2020, Semester.FIRST) )); TakenLectureInventory takenLectureInventory = TakenLectureInventory.from(takenLectures); - BasicAcademicalManager manager = new DefaultBasicAcademicalManager(); + BasicAcademicalGraduationManager manager = new DefaultBasicAcademicalGraduationManager(); //when DetailGraduationResult detailGraduationResult = manager.createDetailGraduationResult(user, diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/SocialScienceBasicAcademicManagerTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/SocialScienceBasicAcademicManagerTest.java index e80df1d5..bdd89557 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/SocialScienceBasicAcademicManagerTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/basicacademicalculture/SocialScienceBasicAcademicManagerTest.java @@ -15,7 +15,6 @@ import com.plzgraduate.myongjigraduatebe.fixture.UserFixture; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailCategoryResult; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailGraduationResult; -import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory; import com.plzgraduate.myongjigraduatebe.lecture.domain.model.BasicAcademicalCultureLecture; import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.Semester; @@ -44,7 +43,7 @@ class 이십삼년도_이후_교과목_포함 { TakenLecture.of(user, mockLectureMap.get("KMD02186"), 2023, Semester.SECOND) ))); TakenLectureInventory takenLectureInventory = TakenLectureInventory.from(takenLectures); - BasicAcademicalManager manager = new DefaultBasicAcademicalManager(); + BasicAcademicalGraduationManager manager = new DefaultBasicAcademicalGraduationManager(); //when DetailGraduationResult detailGraduationResult = manager.createDetailGraduationResult(user, @@ -77,7 +76,7 @@ class 이십삼년도_이후_교과목_포함 { TakenLecture.of(user, mockLectureMap.get("KMD02186"), 2020, Semester.SECOND) ))); TakenLectureInventory takenLectureInventory = TakenLectureInventory.from(takenLectures); - BasicAcademicalManager manager = new SocialScienceBasicAcademicManager(); + BasicAcademicalGraduationManager manager = new SocialScienceBasicAcademicGraduationManager(); //when DetailGraduationResult detailGraduationResult = manager.createDetailGraduationResult(user, diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/commonculture/CommonCultureGraduationManagerTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/commonculture/CommonCultureGraduationManagerTest.java index f1e93f58..12225ea8 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/commonculture/CommonCultureGraduationManagerTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/commonculture/CommonCultureGraduationManagerTest.java @@ -15,7 +15,6 @@ import com.plzgraduate.myongjigraduatebe.fixture.CommonCultureFixture; import com.plzgraduate.myongjigraduatebe.fixture.LectureFixture; import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailGraduationResult; -import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory; import com.plzgraduate.myongjigraduatebe.graduation.domain.service.GraduationManager; import com.plzgraduate.myongjigraduatebe.lecture.domain.model.CommonCulture; import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; @@ -28,7 +27,7 @@ class CommonCultureGraduationManagerTest { Map mockLectureMap = LectureFixture.getMockLectureMap(); - GraduationManager graduationManager = new CommonCultureGraduationManager(); + GraduationManager graduationManager = new CommonGraduationManager(); @DisplayName("모든 공통교양 세부 카테고리가 이수 완료일 경우 이수 완료 공통교양 전체 졸업 결과를 생성한다.") @ParameterizedTest diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/coreculture/CoreCultureGraduationManagerTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/coreculture/CoreCultureGraduationManagerTest.java index bd8e3df8..e55eaa6f 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/coreculture/CoreCultureGraduationManagerTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/coreculture/CoreCultureGraduationManagerTest.java @@ -26,7 +26,7 @@ class CoreCultureGraduationManagerTest { Map mockLectureMap = LectureFixture.getMockLectureMap(); - GraduationManager graduationManager = new CoreCultureGraduationManager(); + GraduationManager graduationManager = new CoreGraduationManager(); @DisplayName("모든 핵심교양 세부 카테고리가 이수 완료일 경우 이수 완료 핵심교양 전체 졸업 결과를 생성한다.") @Test diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/DataTechnologyMajorTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/DataTechnologyMajorTest.java index cd8105b2..18efa985 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/DataTechnologyMajorTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/DataTechnologyMajorTest.java @@ -1,6 +1,6 @@ package com.plzgraduate.myongjigraduatebe.graduation.domain.service.major; -import static com.plzgraduate.myongjigraduatebe.graduation.domain.service.major.MajorGraduationCategory.PRIMARY; +import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.MajorType.PRIMARY; import static org.assertj.core.api.Assertions.assertThat; import java.util.HashSet; @@ -66,10 +66,12 @@ class DataTechnologyMajorTest { ))); TakenLectureInventory takenLectureInventory = TakenLectureInventory.from(takenLectures); Set 데이터테크놀로지_전공 = MajorFixture.데이터테크놀로지_전공(); - MajorManager manager = new MajorManager(PRIMARY); + MandatoryMajorManager mandatoryMajorManager = new MandatoryMajorManager(List.of(new OptionalMandatoryMajorHandler(), new ReplaceMandatoryMajorHandler())); + ElectiveMajorManager electiveMajorManager = new ElectiveMajorManager(); + MajorGraduationManager manager = new MajorGraduationManager(mandatoryMajorManager, electiveMajorManager); //when - DetailGraduationResult detailGraduationResult = manager.createDetailGraduationResult(user, + DetailGraduationResult detailGraduationResult = manager.createDetailGraduationResult(user, PRIMARY, takenLectureInventory, 데이터테크놀로지_전공, 70); List detailCategory = detailGraduationResult.getDetailCategory(); DetailCategoryResult mandatoryDetailCategory = detailCategory.get(0); @@ -123,10 +125,12 @@ class DataTechnologyMajorTest { ))); TakenLectureInventory takenLectureInventory = TakenLectureInventory.from(takenLectures); Set 데이터테크놀로지_전공 = MajorFixture.데이터테크놀로지_전공(); - MajorManager manager = new MajorManager(PRIMARY); + MandatoryMajorManager mandatoryMajorManager = new MandatoryMajorManager(List.of(new OptionalMandatoryMajorHandler(), new ReplaceMandatoryMajorHandler())); + ElectiveMajorManager electiveMajorManager = new ElectiveMajorManager(); + MajorGraduationManager manager = new MajorGraduationManager(mandatoryMajorManager, electiveMajorManager); //when - DetailGraduationResult detailGraduationResult = manager.createDetailGraduationResult(user, + DetailGraduationResult detailGraduationResult = manager.createDetailGraduationResult(user, PRIMARY, takenLectureInventory, 데이터테크놀로지_전공, 70); List detailCategory = detailGraduationResult.getDetailCategory(); DetailCategoryResult mandatoryDetailCategory = detailCategory.get(0); diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/InternationTradeMajorTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/InternationTradeMajorTest.java index 119010ba..8ca058a5 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/InternationTradeMajorTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/InternationTradeMajorTest.java @@ -1,6 +1,6 @@ package com.plzgraduate.myongjigraduatebe.graduation.domain.service.major; -import static com.plzgraduate.myongjigraduatebe.graduation.domain.service.major.MajorGraduationCategory.*; +import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.MajorType.*; import static org.assertj.core.api.Assertions.assertThat; import java.util.HashSet; @@ -60,10 +60,12 @@ class InternationTradeMajorTest { ))); TakenLectureInventory takenLectureInventory = TakenLectureInventory.from(takenLectures); Set 국제통상_전공 = MajorFixture.국제통상_전공(); - MajorManager manager = new MajorManager(PRIMARY); + MandatoryMajorManager mandatoryMajorManager = new MandatoryMajorManager(List.of(new OptionalMandatoryMajorHandler(), new ReplaceMandatoryMajorHandler())); + ElectiveMajorManager electiveMajorManager = new ElectiveMajorManager(); + MajorGraduationManager manager = new MajorGraduationManager(mandatoryMajorManager, electiveMajorManager); //when - DetailGraduationResult detailGraduationResult = manager.createDetailGraduationResult(user, + DetailGraduationResult detailGraduationResult = manager.createDetailGraduationResult(user, PRIMARY, takenLectureInventory, 국제통상_전공, 63); List detailCategory = detailGraduationResult.getDetailCategory(); DetailCategoryResult mandatoryDetailCategory = detailCategory.get(0); @@ -116,10 +118,12 @@ class InternationTradeMajorTest { ))); TakenLectureInventory takenLectureInventory = TakenLectureInventory.from(takenLectures); Set 국제통상_전공 = MajorFixture.국제통상_전공(); - MajorManager manager = new MajorManager(PRIMARY); + MandatoryMajorManager mandatoryMajorManager = new MandatoryMajorManager(List.of(new OptionalMandatoryMajorHandler(), new ReplaceMandatoryMajorHandler())); + ElectiveMajorManager electiveMajorManager = new ElectiveMajorManager(); + MajorGraduationManager manager = new MajorGraduationManager(mandatoryMajorManager, electiveMajorManager); //when - DetailGraduationResult detailGraduationResult = manager.createDetailGraduationResult(user, + DetailGraduationResult detailGraduationResult = manager.createDetailGraduationResult(user, PRIMARY, takenLectureInventory, 국제통상_전공, 63); List detailCategory = detailGraduationResult.getDetailCategory(); DetailCategoryResult mandatoryDetailCategory = detailCategory.get(0); @@ -173,10 +177,12 @@ class InternationTradeMajorTest { ))); TakenLectureInventory takenLectureInventory = TakenLectureInventory.from(takenLectures); Set 국제통상_전공 = MajorFixture.국제통상_전공(); - MajorManager manager = new MajorManager(PRIMARY); + MandatoryMajorManager mandatoryMajorManager = new MandatoryMajorManager(List.of(new OptionalMandatoryMajorHandler(), new ReplaceMandatoryMajorHandler())); + ElectiveMajorManager electiveMajorManager = new ElectiveMajorManager(); + MajorGraduationManager manager = new MajorGraduationManager(mandatoryMajorManager, electiveMajorManager); //when - DetailGraduationResult detailGraduationResult = manager.createDetailGraduationResult(user, + DetailGraduationResult detailGraduationResult = manager.createDetailGraduationResult(user, PRIMARY, takenLectureInventory, 국제통상_전공, 63); List detailCategory = detailGraduationResult.getDetailCategory(); DetailCategoryResult mandatoryDetailCategory = detailCategory.get(0); @@ -227,10 +233,12 @@ class InternationTradeMajorTest { ))); TakenLectureInventory takenLectureInventory = TakenLectureInventory.from(takenLectures); Set 국제통상_전공 = MajorFixture.국제통상_전공(); - MajorManager manager = new MajorManager(PRIMARY); + MandatoryMajorManager mandatoryMajorManager = new MandatoryMajorManager(List.of(new OptionalMandatoryMajorHandler(), new ReplaceMandatoryMajorHandler())); + ElectiveMajorManager electiveMajorManager = new ElectiveMajorManager(); + MajorGraduationManager manager = new MajorGraduationManager(mandatoryMajorManager, electiveMajorManager); //when - DetailGraduationResult detailGraduationResult = manager.createDetailGraduationResult(user, + DetailGraduationResult detailGraduationResult = manager.createDetailGraduationResult(user, PRIMARY, takenLectureInventory, 국제통상_전공, 63); List detailCategory = detailGraduationResult.getDetailCategory(); DetailCategoryResult mandatoryDetailCategory = detailCategory.get(0); @@ -266,10 +274,12 @@ class InternationTradeMajorTest { ))); TakenLectureInventory takenLectureInventory = TakenLectureInventory.from(takenLectures); Set 국제통상_전공 = MajorFixture.국제통상_전공(); - MajorManager manager = new MajorManager(PRIMARY); + MandatoryMajorManager mandatoryMajorManager = new MandatoryMajorManager(List.of(new OptionalMandatoryMajorHandler(), new ReplaceMandatoryMajorHandler())); + ElectiveMajorManager electiveMajorManager = new ElectiveMajorManager(); + MajorGraduationManager manager = new MajorGraduationManager(mandatoryMajorManager, electiveMajorManager); //when - DetailGraduationResult detailGraduationResult = manager.createDetailGraduationResult(user, + DetailGraduationResult detailGraduationResult = manager.createDetailGraduationResult(user, PRIMARY, takenLectureInventory, 국제통상_전공, 70); List detailCategory = detailGraduationResult.getDetailCategory(); DetailCategoryResult mandatoryDetailCategory = detailCategory.get(0); @@ -297,10 +307,12 @@ class InternationTradeMajorTest { ))); TakenLectureInventory takenLectureInventory = TakenLectureInventory.from(takenLectures); Set 국제통상_전공 = MajorFixture.국제통상_전공(); - MajorManager manager = new MajorManager(PRIMARY); + MandatoryMajorManager mandatoryMajorManager = new MandatoryMajorManager(List.of(new OptionalMandatoryMajorHandler(), new ReplaceMandatoryMajorHandler())); + ElectiveMajorManager electiveMajorManager = new ElectiveMajorManager(); + MajorGraduationManager manager = new MajorGraduationManager(mandatoryMajorManager, electiveMajorManager); //when - DetailGraduationResult detailGraduationResult = manager.createDetailGraduationResult(user, + DetailGraduationResult detailGraduationResult = manager.createDetailGraduationResult(user, PRIMARY, takenLectureInventory, 국제통상_전공, 70); List detailCategory = detailGraduationResult.getDetailCategory(); DetailCategoryResult electiveDetailCategory = detailCategory.get(1); diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/OptionalMandatoryMajorHandlerTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/OptionalMandatoryMajorHandlerTest.java index 7353ee3e..1ff67a32 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/OptionalMandatoryMajorHandlerTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/major/OptionalMandatoryMajorHandlerTest.java @@ -11,6 +11,7 @@ import com.plzgraduate.myongjigraduatebe.fixture.LectureFixture; import com.plzgraduate.myongjigraduatebe.fixture.UserFixture; +import com.plzgraduate.myongjigraduatebe.graduation.domain.model.MajorType; import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.Semester; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture; @@ -20,7 +21,7 @@ @DisplayName("N개 중에 M개 이상을 수강할 경우 세부조건을 달성한다.") class OptionalMandatoryMajorHandlerTest { private static final User user = UserFixture.경영학과_19학번_ENG12(); - private static final MajorGraduationCategory majorGraduationCategory = MajorGraduationCategory.PRIMARY; + private static final MajorType MAJOR_TYPE = MajorType.PRIMARY; private static final Map mockLectureMap = LectureFixture.getMockLectureMap(); @DisplayName("3개 중에 1개를 수강할 경우 세부조건을 달성한다.") @@ -47,7 +48,7 @@ class OptionalMandatoryMajorHandlerTest { //when MandatoryMajorSpecialCaseHandler exceptionHandler = new OptionalMandatoryMajorHandler(); MandatorySpecialCaseInformation mandatorySpecialCaseInformation = exceptionHandler.getMandatorySpecialCaseInformation( - user, majorGraduationCategory, takenLectureInventory, mandatoryLectures, electiveLectures); + user, MAJOR_TYPE, takenLectureInventory, mandatoryLectures, electiveLectures); boolean isCompleteMandatorySpecialCase = mandatorySpecialCaseInformation.isCompleteMandatorySpecialCase(); int removedMandatoryTotalCredit = mandatorySpecialCaseInformation.getRemovedMandatoryTotalCredit(); @@ -81,7 +82,7 @@ class OptionalMandatoryMajorHandlerTest { //when MandatoryMajorSpecialCaseHandler exceptionHandler = new OptionalMandatoryMajorHandler(); MandatorySpecialCaseInformation mandatorySpecialCaseInformation = exceptionHandler.getMandatorySpecialCaseInformation( - user, majorGraduationCategory, takenLectureInventory, mandatoryLectures, electiveLectures); + user, MAJOR_TYPE, takenLectureInventory, mandatoryLectures, electiveLectures); boolean isCompleteMandatorySpecialCase = mandatorySpecialCaseInformation.isCompleteMandatorySpecialCase(); int removedMandatoryTotalCredit = mandatorySpecialCaseInformation.getRemovedMandatoryTotalCredit(); 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 430a9115..6059f84a 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 @@ -11,7 +11,7 @@ import com.plzgraduate.myongjigraduatebe.fixture.LectureFixture; import com.plzgraduate.myongjigraduatebe.fixture.UserFixture; -import com.plzgraduate.myongjigraduatebe.graduation.domain.service.major.MajorGraduationCategory; +import com.plzgraduate.myongjigraduatebe.graduation.domain.model.MajorType; import com.plzgraduate.myongjigraduatebe.graduation.domain.service.major.MandatoryMajorSpecialCaseHandler; import com.plzgraduate.myongjigraduatebe.graduation.domain.service.major.MandatorySpecialCaseInformation; import com.plzgraduate.myongjigraduatebe.graduation.domain.service.major.ReplaceMandatoryMajorHandler; @@ -24,7 +24,7 @@ @DisplayName("21학번 이전 철학과 학생의 경우 폐지된 전공필수의 대체 과목을 인정한다.") class ReplaceMandatoryMajorHandlerTest { private static final User user = UserFixture.철학과_20학번(); - private static final MajorGraduationCategory majorGraduationCategory = MajorGraduationCategory.PRIMARY; + private static final MajorType MAJOR_TYPE = MajorType.PRIMARY; private static final Map mockLectureMap = LectureFixture.getMockLectureMap(); @DisplayName("답사1와 답사2를 수강했을 경우 세부조건을 달성한다.") @@ -52,7 +52,7 @@ class ReplaceMandatoryMajorHandlerTest { //when MandatoryMajorSpecialCaseHandler exceptionHandler = new ReplaceMandatoryMajorHandler(); MandatorySpecialCaseInformation mandatorySpecialCaseInformation = exceptionHandler.getMandatorySpecialCaseInformation( - user, majorGraduationCategory, takenLectureInventory, mandatoryLectures, electiveLectures); + user, MAJOR_TYPE, takenLectureInventory, mandatoryLectures, electiveLectures); boolean isCompleteMandatorySpecialCase = mandatorySpecialCaseInformation.isCompleteMandatorySpecialCase(); int removedMandatoryTotalCredit = mandatorySpecialCaseInformation.getRemovedMandatoryTotalCredit(); @@ -87,7 +87,7 @@ class ReplaceMandatoryMajorHandlerTest { //when MandatoryMajorSpecialCaseHandler exceptionHandler = new ReplaceMandatoryMajorHandler(); MandatorySpecialCaseInformation mandatorySpecialCaseInformation = exceptionHandler.getMandatorySpecialCaseInformation( - user, majorGraduationCategory, takenLectureInventory, mandatoryLectures, electiveLectures); + user, MAJOR_TYPE, takenLectureInventory, mandatoryLectures, electiveLectures); boolean isCompleteMandatorySpecialCase = mandatorySpecialCaseInformation.isCompleteMandatorySpecialCase(); int removedMandatoryTotalCredit = mandatorySpecialCaseInformation.getRemovedMandatoryTotalCredit(); @@ -118,7 +118,7 @@ class ReplaceMandatoryMajorHandlerTest { //when MandatoryMajorSpecialCaseHandler exceptionHandler = new ReplaceMandatoryMajorHandler(); MandatorySpecialCaseInformation mandatorySpecialCaseInformation = exceptionHandler.getMandatorySpecialCaseInformation( - user, majorGraduationCategory, takenLectureInventory, mandatoryLectures, electiveLectures); + user, MAJOR_TYPE, takenLectureInventory, mandatoryLectures, electiveLectures); boolean isCompleteMandatorySpecialCase = mandatorySpecialCaseInformation.isCompleteMandatorySpecialCase(); int removedMandatoryTotalCredit = mandatorySpecialCaseInformation.getRemovedMandatoryTotalCredit(); diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/submajor/SubMajorManagerTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/submajor/SubMajorGraduationManagerTest.java similarity index 99% rename from src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/submajor/SubMajorManagerTest.java rename to src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/submajor/SubMajorGraduationManagerTest.java index f660182b..a3fba8eb 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/submajor/SubMajorManagerTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/service/submajor/SubMajorGraduationManagerTest.java @@ -20,7 +20,7 @@ import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; import com.plzgraduate.myongjigraduatebe.user.domain.model.User; -class SubMajorManagerTest { +class SubMajorGraduationManagerTest { @DisplayName("부전공 학생의 부전공 졸업 결과를 생성한다.") @Test @@ -41,7 +41,7 @@ void createDetailGraduationResult() { int subMajorGraduationCredit = 21; int takenLecturesCount = takenLectures.size(); - GraduationManager subMajorManager = new SubMajorManager(); + GraduationManager subMajorManager = new SubMajorGraduationManager(); //when DetailGraduationResult detailGraduationResult = subMajorManager.createDetailGraduationResult(user, diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/takenlecture/domain/model/TakenLectureInventoryTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/takenlecture/domain/model/TakenLectureInventoryTest.java index 1a8b7f03..36aa4e6c 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/takenlecture/domain/model/TakenLectureInventoryTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/takenlecture/domain/model/TakenLectureInventoryTest.java @@ -74,7 +74,7 @@ void calculateTotalCredit() { @DisplayName("수강과목 목록에서 처리 완료된 과목을 제거한다.") @Test - void handleFinishedLectures() { + void sync() { //given TakenLectureInventory takenLectureInventory = getTakenLectureInventory(); int beforeHandleSize = takenLectureInventory.getTakenLectures().size(); @@ -84,7 +84,7 @@ void handleFinishedLectures() { )); //when - takenLectureInventory.handleFinishedLectures(finishedLectures); + takenLectureInventory.sync(finishedLectures); //then assertThat(takenLectureInventory.getTakenLectures()) diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/user/domain/model/UserTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/user/domain/model/UserTest.java index e81262ba..902fb143 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/user/domain/model/UserTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/user/domain/model/UserTest.java @@ -7,9 +7,13 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; import org.mockito.Mock; import org.springframework.security.crypto.password.PasswordEncoder; +import com.plzgraduate.myongjigraduatebe.graduation.domain.model.MajorType; + class UserTest { @Mock @@ -161,4 +165,18 @@ void isNotMyAuthId() { //then assertThat(result).isFalse(); } + + @DisplayName("MajorType별 사용자의 전공을 반환하는지 확인한다.") + @CsvSource({"PRIMARY, 융합소프트웨어부", "DUAL, 경영학과", "SUB, 영문학과"}) + @ParameterizedTest + void getMajorByMajorType(MajorType majorType, String major) { + //given + User dualMajorUser = User.builder().id(1L).primaryMajor("융합소프트웨어부").dualMajor("경영학과").subMajor("영문학과").build(); + + //when + String majorByMajorType = dualMajorUser.getMajorByMajorType(majorType); + + //then + assertThat(majorByMajorType).isEqualTo(major); + } }