From 8ddb5b044fea7aad2e852ffb2efb99742351afdc Mon Sep 17 00:00:00 2001 From: 5uhwann <106325839+5uhwann@users.noreply.github.com> Date: Mon, 23 Dec 2024 08:14:01 +0900 Subject: [PATCH] =?UTF-8?q?[DEV-51]=20=EC=88=98=EA=B0=95=ED=95=84=EC=9A=94?= =?UTF-8?q?=EA=B3=BC=EB=AA=A9=20=EB=AA=A9=EB=A1=9D=20=EC=A0=9C=EA=B1=B0=20?= =?UTF-8?q?-=20=ED=98=84=EC=9E=A5=EC=8B=A4=EC=8A=B5=20(#293)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor: haveToLecture 제외 과목(현장실습) 코드 추가 * refactor: swagger 명세 추가 * refactor: 미지원 GraduationCategory 제거 * refactor: 수강필요과목 목록 제외 과목 로직 위치 수정 * refactor: 코드 스멜 제거 --- .../FindDetailGraduationApiPresentation.java | 10 ++++++-- .../domain/model/DetailCategoryResult.java | 15 +++++------- .../domain/model/GraduationCategory.java | 4 ---- .../service/major/ElectiveMajorManager.java | 21 +++++++++++++--- .../domain/model/TakenLectureInventory.java | 5 +--- .../user/domain/model/StudentCategory.java | 7 +----- .../UserPersistenceAdapterTest.java | 24 +++++++++---------- 7 files changed, 46 insertions(+), 40 deletions(-) diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/api/FindDetailGraduationApiPresentation.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/api/FindDetailGraduationApiPresentation.java index 7de6bea0..0c77e5de 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/api/FindDetailGraduationApiPresentation.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/api/FindDetailGraduationApiPresentation.java @@ -5,6 +5,7 @@ import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.web.bind.annotation.RequestParam; @@ -13,10 +14,15 @@ public interface FindDetailGraduationApiPresentation { @Operation(summary = "졸업 카테고리 상세 결과 조회", description = "유저의 각 졸업 카테고리 상세 결과를 조회한다.") - @Parameter(name = "graduationCategory", description = "상세 조회하고자 하는 졸업 카테고리") @SecurityRequirement(name = "AccessToken") DetailGraduationResultResponse getDetailGraduation( @Parameter(hidden = true) @LoginUser Long userId, - @RequestParam GraduationCategory graduationCategory + @RequestParam @Schema( + type = "string", allowableValues = { + "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", "NORMAL_CULTURE", "FREE_ELECTIVE", "CHAPEL" + } + ) GraduationCategory graduationCategory ); } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/DetailCategoryResult.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/DetailCategoryResult.java index 252798cc..0876addf 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/DetailCategoryResult.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/DetailCategoryResult.java @@ -8,8 +8,6 @@ import java.util.List; import java.util.Set; -import com.plzgraduate.myongjigraduatebe.user.domain.model.StudentCategory; -import com.plzgraduate.myongjigraduatebe.user.domain.model.User; import lombok.Builder; import lombok.Getter; @@ -25,6 +23,7 @@ public class DetailCategoryResult { private int takenCredits; private int normalLeftCredit; private int freeElectiveLeftCredit; + @Builder private DetailCategoryResult( String detailCategoryName, boolean isCompleted, @@ -76,13 +75,11 @@ public void assignDetailCategoryName(String detailCategoryName) { } public void calculate(Set taken, Set graduationLectures) { - - addTakenLectures(taken); - calculateLeftCredit(); - if (!checkCompleted()) { - addMandatoryLectures(taken, graduationLectures); - } - + addTakenLectures(taken); + calculateLeftCredit(); + if (!checkCompleted()) { + addMandatoryLectures(taken, graduationLectures); + } } public void addNormalLeftCredit(int normalLeftCredit) { 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 e9124c38..0498bd0b 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 @@ -19,10 +19,6 @@ public enum GraduationCategory { SUB_MAJOR("부전공"), PRIMARY_BASIC_ACADEMICAL_CULTURE("주학문기초교양"), DUAL_BASIC_ACADEMICAL_CULTURE("복수학문기초교양"), - ASSOCIATED_MANDATORY_MAJOR("연계전공필수"), - ASSOCIATED_ELECTIVE_MAJOR("연계전공선택"), - ASSOCIATED_MANDATORY_CULTURE("연계전공교양필수"), - ASSOCIATED_ELECTIVE_CULTURE("연계전공교양선택"), TRANSFER_CHRISTIAN("편입기독교"), NORMAL_CULTURE("일반교양"), FREE_ELECTIVE("자유선택"), 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 5c8e8ce3..70087232 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 @@ -5,6 +5,7 @@ import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; import java.util.HashSet; +import java.util.List; import java.util.Set; import org.springframework.stereotype.Component; @@ -12,11 +13,20 @@ @Component public class ElectiveMajorManager { + // 현장실습과목(haveToLectrue 제외) + private static final List PRACTICE_LECTURE_CODES = List.of( + "KMR01801", "KMR01802", "KMR01804", "KMR01805", "KMR01851", "KMR01852", "HAH01371", "HFC01412", + "HFM01404", "JDC01361", "JEE01356", "JEE01357", "JEH01493", "JEH01494", "JEI01430", "JEI01467", "JEJ02549", + "JEJ02554", "JEJ02558", "JEJ02559", "JEJ02560", "JEJ02561", "KMD02902", "KMD02903", "KMR01551", "KMR01552", + "KMR01553", "KMR01554", "KMR01555", "KMR01560", "KMR01561", "KMR01562", "KMR01563", "KMR01564", "KMR01566", + "KMR01567", "KMR01703", "KMR01705", "KMR01710", "KMR01712", "KMR01803", "KMR01817" + ); private static final String ELECTIVE_MAJOR_NAME = "전공선택"; public DetailCategoryResult createDetailCategoryResult( TakenLectureInventory takenLectureInventory, - Set electiveLectures, int electiveMajorTotalCredit) { + Set electiveLectures, int electiveMajorTotalCredit + ) { Set takenElective = new HashSet<>(); Set finishedTakenLecture = new HashSet<>(); takenLectureInventory.getTakenLectures() @@ -27,10 +37,15 @@ public DetailCategoryResult createDetailCategoryResult( takenElective.add(takenLecture.getLecture()); }); DetailCategoryResult electiveMajorResult = DetailCategoryResult.create(ELECTIVE_MAJOR_NAME, - true, electiveMajorTotalCredit); + true, electiveMajorTotalCredit + ); + excludePracticeLectureForHaveToLecture(electiveLectures); electiveMajorResult.calculate(takenElective, electiveLectures); takenLectureInventory.handleFinishedTakenLectures(finishedTakenLecture); - return electiveMajorResult; } + + private void excludePracticeLectureForHaveToLecture(Set electiveLectures) { + electiveLectures.removeIf(lecture -> PRACTICE_LECTURE_CODES.contains(lecture.getId())); + } } 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 2f806ebb..f391c92b 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 @@ -1,9 +1,6 @@ package com.plzgraduate.myongjigraduatebe.takenlecture.domain.model; -import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory; import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; - -import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.Set; @@ -90,8 +87,8 @@ public String toString() { public Set getChristianLectures() { return takenLecture.stream() - .filter(taken -> CHRISTIAN_COURSE_CODES.contains(taken.getLecture().getId())) .map(TakenLecture::getLecture) + .filter(lecture -> CHRISTIAN_COURSE_CODES.contains(lecture.getId())) .collect(Collectors.toSet()); } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/user/domain/model/StudentCategory.java b/src/main/java/com/plzgraduate/myongjigraduatebe/user/domain/model/StudentCategory.java index 9c100243..dd17564e 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/user/domain/model/StudentCategory.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/user/domain/model/StudentCategory.java @@ -47,12 +47,7 @@ public enum StudentCategory { ), ASSOCIATED_MAJOR( List.of("연계전공"), - // 현재 미지원 - List.of(COMMON_CULTURE, CORE_CULTURE, PRIMARY_BASIC_ACADEMICAL_CULTURE, - ASSOCIATED_MANDATORY_CULTURE, ASSOCIATED_ELECTIVE_CULTURE, - PRIMARY_MANDATORY_MAJOR, PRIMARY_ELECTIVE_MAJOR, ASSOCIATED_MANDATORY_MAJOR, - ASSOCIATED_ELECTIVE_MAJOR, NORMAL_CULTURE, FREE_ELECTIVE, CHAPEL - ) + List.of() ), DOUBLE_SUB( List.of("복수전공", "부전공"), diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/user/infrastructure/adapter/persistence/UserPersistenceAdapterTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/user/infrastructure/adapter/persistence/UserPersistenceAdapterTest.java index 18ce1ccf..32904579 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/user/infrastructure/adapter/persistence/UserPersistenceAdapterTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/user/infrastructure/adapter/persistence/UserPersistenceAdapterTest.java @@ -24,7 +24,7 @@ class UserPersistenceAdapterTest extends PersistenceTestSupport { @Test void 사용자_저장() { //given - User user = createUser("mju1001", "1q2w3e4r!", "60181666"); + User user = createUser(); //when userPersistenceAdapter.saveUser(user); //then @@ -36,7 +36,7 @@ class UserPersistenceAdapterTest extends PersistenceTestSupport { void 아아디_사용자_조회() { //given String authId = "mju1001"; - UserJpaEntity userEntity = createUserEntity(authId, "1q2w3e4r!", "60181666"); + UserJpaEntity userEntity = createUserEntity(authId, "60181666"); userRepository.save(userEntity); //when Optional user = userPersistenceAdapter.findUserByAuthId(authId); @@ -52,7 +52,7 @@ class UserPersistenceAdapterTest extends PersistenceTestSupport { void findUserByStudentNumber() { //given String studentNumber = "60181666"; - UserJpaEntity userJpaEntity = createUserEntity("mju1001", "1q2w3e4r!", studentNumber); + UserJpaEntity userJpaEntity = createUserEntity("mju1001", studentNumber); userRepository.save(userJpaEntity); //when @@ -69,7 +69,7 @@ void findUserByStudentNumber() { void 중복_아이디_확인() { //given String authId = "mju1001"; - UserJpaEntity user = createUserEntity(authId, "1q2w3e4r!", "60181666"); + UserJpaEntity user = createUserEntity(authId, "60181666"); userRepository.save(user); //when boolean check = userPersistenceAdapter.checkDuplicateAuthId(authId); @@ -83,7 +83,7 @@ void findUserByStudentNumber() { void 중복_학번_확인() { //given String studentNumber = "60181666"; - UserJpaEntity user = createUserEntity("mju1001", "1q2w3e4r!", studentNumber); + UserJpaEntity user = createUserEntity("mju1001", studentNumber); userRepository.save(user); //when boolean check = userPersistenceAdapter.checkDuplicateStudentNumber(studentNumber); @@ -97,7 +97,7 @@ void findUserByStudentNumber() { void deleteUser() { //given String authId = "mju1000"; - UserJpaEntity userJpaEntity = createUserEntity(authId, "1q2w3e4r!", "60181666"); + UserJpaEntity userJpaEntity = createUserEntity(authId, "60181666"); UserJpaEntity savedUserJpaEntity = userRepository.save(userJpaEntity); User user = User.builder() .id(savedUserJpaEntity.getId()) @@ -111,23 +111,23 @@ void deleteUser() { assertThat(foundUser.isPresent()).isFalse(); } - private User createUser(String authId, String password, String studentNumber) { + private User createUser() { return User .builder() - .authId(authId) - .password(password) - .studentNumber(studentNumber) + .authId("mju1001") + .password("1q2w3e4r!") + .studentNumber("60181666") .transferCredit(new TransferCredit(0, 0, 0, 0)) .studentCategory(StudentCategory.NORMAL) .build(); } - private UserJpaEntity createUserEntity(String authId, String password, String studentNumber) { + private UserJpaEntity createUserEntity(String authId, String studentNumber) { return UserJpaEntity .builder() .authId(authId) - .password(password) + .password("1q2w3e4r!") .studentNumber(studentNumber) .transferCredit("0/0/0/0") .studentCategory(StudentCategory.NORMAL)