Skip to content

Commit

Permalink
[DEV-51] 수강필요과목 목록 제거 - 현장실습 (#293)
Browse files Browse the repository at this point in the history
* refactor: haveToLecture 제외 과목(현장실습) 코드 추가

* refactor: swagger 명세 추가

* refactor: 미지원 GraduationCategory 제거

* refactor: 수강필요과목 목록 제외 과목 로직 위치 수정

* refactor: 코드 스멜 제거
  • Loading branch information
5uhwann authored Dec 22, 2024
1 parent 7e19cda commit 8ddb5b0
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -25,6 +23,7 @@ public class DetailCategoryResult {
private int takenCredits;
private int normalLeftCredit;
private int freeElectiveLeftCredit;

@Builder
private DetailCategoryResult(
String detailCategoryName, boolean isCompleted,
Expand Down Expand Up @@ -76,13 +75,11 @@ public void assignDetailCategoryName(String detailCategoryName) {
}

public void calculate(Set<Lecture> taken, Set<Lecture> graduationLectures) {

addTakenLectures(taken);
calculateLeftCredit();
if (!checkCompleted()) {
addMandatoryLectures(taken, graduationLectures);
}

addTakenLectures(taken);
calculateLeftCredit();
if (!checkCompleted()) {
addMandatoryLectures(taken, graduationLectures);
}
}

public void addNormalLeftCredit(int normalLeftCredit) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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("자유선택"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,28 @@
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;

@Component
public class ElectiveMajorManager {

// 현장실습과목(haveToLectrue 제외)
private static final List<String> 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<Lecture> electiveLectures, int electiveMajorTotalCredit) {
Set<Lecture> electiveLectures, int electiveMajorTotalCredit
) {
Set<Lecture> takenElective = new HashSet<>();
Set<TakenLecture> finishedTakenLecture = new HashSet<>();
takenLectureInventory.getTakenLectures()
Expand All @@ -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<Lecture> electiveLectures) {
electiveLectures.removeIf(lecture -> PRACTICE_LECTURE_CODES.contains(lecture.getId()));
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -90,8 +87,8 @@ public String toString() {

public Set<Lecture> 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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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("복수전공", "부전공"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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> user = userPersistenceAdapter.findUserByAuthId(authId);
Expand All @@ -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
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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())
Expand All @@ -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)
Expand Down

0 comments on commit 8ddb5b0

Please sign in to comment.