Skip to content

Commit

Permalink
refactor: 공통교양 졸업사정결과 반환 기능 (#156)
Browse files Browse the repository at this point in the history
* refactor: DetailCategoryResult 계산 메서드 명 수정

* chore: lecture fixture 소스 추가

* refactor: 공통교양 도메인 구성

* test: 공통교양 test fixture 생성

* test: CommonCultureDetailCategoryManager 테스트 작성

* feat: CommonCultureDetailCategoryManager 구현

* style: stream 코드 가독성 개선

* test: 공통 교양 test fixture 세분화

* test: 유저 test fixture 추가

* test: CommonCultureGraduationManager 테스트 작성

* test: CommonCultureGraduationManager 구현

* refactor: 불필요 임포트 제거

* refactor: 졸업 카테고리 이름 설정 방식 수정

* chore: lecture fixture 디지털리터러시의이해 과목 추가

* style: 코딩 컨벤션 준수

* chore: 오타 수정

* refactor: 세부 졸업 카테고리 완료 로직 수정

* test: 공통교양 세부 카테고리(16~19 기독교) 졸업 결과 생성 시 필수 과목 체크 로직 테스트 작성

* feat: 공통교양 세부 카테고리(16~19 기독교) 졸업 결과 생성 시 필수 과목 체크 로직 추가

* style: 불필요 임포트 및 공백 제거

* refactor: 패키지명 오타 수정
  • Loading branch information
5uhwann authored Aug 8, 2023
1 parent 7350f89 commit 96cdb78
Show file tree
Hide file tree
Showing 21 changed files with 522 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class DetailCategoryResult {

private final String detailCategoryName;
private boolean isCompleted;
private final boolean isSatisfiedMandatory;
private final int totalCredits;
private int takenCredits;
private final List<Lecture> takenMandatoryLectures = new ArrayList<>();
Expand All @@ -22,28 +23,33 @@ public class DetailCategoryResult {
private final List<Lecture> haveToElectiveLectures = new ArrayList<>();

@Builder
private DetailCategoryResult(String detailCategoryName, boolean isCompleted, int totalCredits, int takenCredits) {
private DetailCategoryResult(String detailCategoryName, boolean isCompleted, boolean isSatisfiedMandatory,
int totalCredits, int takenCredits) {
this.detailCategoryName = detailCategoryName;
this.isCompleted = isCompleted;
this.isSatisfiedMandatory = isSatisfiedMandatory;
this.totalCredits = totalCredits;
this.takenCredits = takenCredits;
}

public static DetailCategoryResult create(String detailCategoryName, int totalCredits) {
public static DetailCategoryResult create(String detailCategoryName, boolean isSatisfiedMandatory,
int totalCredits) {
return DetailCategoryResult.builder()
.detailCategoryName(detailCategoryName)
.isCompleted(false)
.isSatisfiedMandatory(isSatisfiedMandatory)
.totalCredits(totalCredits)
.takenCredits(0)
.build();
}

public void calculateBasicAcademicCulture(Set<Lecture> taken, Set<Lecture> basicAcademicalLectures) {
public void calculate(Set<Lecture> taken, Set<Lecture> basicAcademicalLectures) {
addTakenLectures(taken);
if(!checkCompleted()) {
addMandatoryLectures(taken, basicAcademicalLectures);
}
}

private void addTakenLectures(Set<Lecture> taken) {
taken.forEach(lecture -> {
takenMandatoryLectures.add(lecture);
Expand All @@ -57,7 +63,7 @@ private void addMandatoryLectures(Set<Lecture> taken, Set<Lecture> basicAcademic
}

private boolean checkCompleted() {
isCompleted = totalCredits <= takenCredits;
isCompleted = totalCredits <= takenCredits && isSatisfiedMandatory;
return isCompleted;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ private DetailGraduationResult(String categoryName, boolean isCompleted, int tot

public static DetailGraduationResult create(GraduationCategory graduationCategory, int totalCredit, List<DetailCategoryResult> detailCategoryResults) {
return DetailGraduationResult.builder()
.categoryName(graduationCategory.name())
.categoryName(graduationCategory.getName())
.isCompleted(checkIsCompleted(detailCategoryResults))
.totalCredit(totalCredit)
.takenCredit(calculateTakenCredit(detailCategoryResults))
Expand All @@ -47,6 +47,8 @@ private static boolean checkIsCompleted(List<DetailCategoryResult> detailCategor
}

private static int calculateTakenCredit(List<DetailCategoryResult> detailCategoryResults) {
return detailCategoryResults.stream().mapToInt(DetailCategoryResult::getTakenCredits).sum();
return detailCategoryResults.stream()
.mapToInt(DetailCategoryResult::getTakenCredits)
.sum();
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.plzgraduate.myongjigraduatebe.graduation.domain.service.basicacademicculture;
package com.plzgraduate.myongjigraduatebe.graduation.domain.service.basicacademicalculture;

import java.util.Set;
import java.util.stream.Collectors;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.plzgraduate.myongjigraduatebe.graduation.domain.service.basicacademicculture;
package com.plzgraduate.myongjigraduatebe.graduation.domain.service.basicacademicalculture;

import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.BASIC_ACADEMICAL_CULTURE;

Expand Down Expand Up @@ -39,7 +39,7 @@ public DetailGraduationResult createDetailGraduationResult(StudentInformation st
Set<BasicAcademicalCulture> graduationLectures, int basicAcademicalCredit) {
Set<Lecture> basicAcademicalLectures = convertToLectureSet(graduationLectures);
DetailCategoryResult detailCategoryResult = DetailCategoryResult.create(
BASIC_ACADEMICAL_CULTURE.name(), basicAcademicalCredit);
BASIC_ACADEMICAL_CULTURE.getName(), true, basicAcademicalCredit);

Set<TakenLecture> removedTakenLecture = new HashSet<>();
Set<Lecture> taken = new HashSet<>();
Expand All @@ -53,7 +53,7 @@ public DetailGraduationResult createDetailGraduationResult(StudentInformation st
taken.add(takenLecture.getLecture());
});

detailCategoryResult.calculateBasicAcademicCulture(taken, basicAcademicalLectures);
detailCategoryResult.calculate(taken, basicAcademicalLectures);
takenLectures.removeAll(removedTakenLecture);

return DetailGraduationResult.create(BASIC_ACADEMICAL_CULTURE, basicAcademicalCredit,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.plzgraduate.myongjigraduatebe.graduation.domain.service.basicacademicculture;
package com.plzgraduate.myongjigraduatebe.graduation.domain.service.basicacademicalculture;

import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.BASIC_ACADEMICAL_CULTURE;

Expand Down Expand Up @@ -28,7 +28,7 @@ public DetailGraduationResult createDetailGraduationResult(StudentInformation st
Set<BasicAcademicalCulture> graduationLectures, int basicAcademicalCredit) {

DetailCategoryResult detailCategoryResult = DetailCategoryResult.create(
BASIC_ACADEMICAL_CULTURE.name(), basicAcademicalCredit);
BASIC_ACADEMICAL_CULTURE.getName(), true, basicAcademicalCredit);

Set<Lecture> basicAcademicalLectures = convertToLectureSet(graduationLectures);

Expand All @@ -42,7 +42,7 @@ public DetailGraduationResult createDetailGraduationResult(StudentInformation st
taken.add(takenLecture.getLecture());
});

detailCategoryResult.calculateBasicAcademicCulture(taken, basicAcademicalLectures);
detailCategoryResult.calculate(taken, basicAcademicalLectures);
takenLectures.removeAll(removedTakenLecture);

return DetailGraduationResult.create(BASIC_ACADEMICAL_CULTURE, basicAcademicalCredit,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.plzgraduate.myongjigraduatebe.graduation.domain.service.basicacademicculture;
package com.plzgraduate.myongjigraduatebe.graduation.domain.service.basicacademicalculture;

import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.BASIC_ACADEMICAL_CULTURE;

Expand Down Expand Up @@ -39,7 +39,7 @@ public DetailGraduationResult createDetailGraduationResult(StudentInformation st
Set<Lecture> basicAcademicalLectures = convertToLectureSet(graduationLectures);

DetailCategoryResult detailCategoryResult = DetailCategoryResult.create(
BASIC_ACADEMICAL_CULTURE.name(), basicAcademicalCredit);
BASIC_ACADEMICAL_CULTURE.getName(), true, basicAcademicalCredit);
Set<TakenLecture> removedTakenLecture = new HashSet<>();
Set<Lecture> taken = new HashSet<>();

Expand All @@ -52,7 +52,7 @@ public DetailGraduationResult createDetailGraduationResult(StudentInformation st
taken.add(takenLecture.getLecture());
});

detailCategoryResult.calculateBasicAcademicCulture(taken, basicAcademicalLectures);
detailCategoryResult.calculate(taken, basicAcademicalLectures);
takenLectures.removeAll(removedTakenLecture);

return DetailGraduationResult.create(BASIC_ACADEMICAL_CULTURE, 12, List.of(detailCategoryResult));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.plzgraduate.myongjigraduatebe.graduation.domain.service.commonculture;

import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailCategoryResult;
import com.plzgraduate.myongjigraduatebe.lecture.domain.model.CommonCulture;
import com.plzgraduate.myongjigraduatebe.lecture.domain.model.CommonCultureCategory;
import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture;
import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture;

class CommonCultureDetailCategoryManager {

private static final List<String> MANDATORY_LECTURE_CODE_LIST = List.of("KMA02100", "KMA00100", "KMA00101");

public DetailCategoryResult generate(Set<TakenLecture> takenLectures,
Set<CommonCulture> graduationLectures, CommonCultureCategory category) {
DetailCategoryResult commonCultureDetailCategoryResult = DetailCategoryResult.create(
category.getName(), checkMandatorySatisfaction(takenLectures, category), category.getTotalCredit());
Set<Lecture> taken = new HashSet<>();

Set<Lecture> graduationCommonCultureLectures = categorizeCommonCultures(
graduationLectures, category);

takenLectures.stream()
.filter(takenLecture -> graduationCommonCultureLectures.contains(takenLecture.getLecture()))
.forEach(takenLecture -> taken.add(takenLecture.getLecture()));

commonCultureDetailCategoryResult.calculate(taken, graduationCommonCultureLectures);

return commonCultureDetailCategoryResult;
}

private boolean checkMandatorySatisfaction(Set<TakenLecture> takenLectures, CommonCultureCategory category) {
if (category == CommonCultureCategory.CHRISTIAN_A) {
return takenLectures.stream()
.anyMatch(
takenLecture -> MANDATORY_LECTURE_CODE_LIST.contains(takenLecture.getLecture().getLectureCode()));
}
return true;
}

private Set<Lecture> categorizeCommonCultures(Set<CommonCulture> graduationLectures,
CommonCultureCategory category) {
return graduationLectures.stream()
.filter(commonCulture -> commonCulture.getCommonCultureCategory() == category)
.map(CommonCulture::getLecture)
.collect(Collectors.toSet());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.plzgraduate.myongjigraduatebe.graduation.domain.service.commonculture;

import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.*;

import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

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.lecture.domain.model.CommonCulture;
import com.plzgraduate.myongjigraduatebe.lecture.domain.model.CommonCultureCategory;
import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture;
import com.plzgraduate.myongjigraduatebe.user.domain.model.StudentInformation;

public class CommonCultureGraduationManager implements GraduationManager<CommonCulture> {

@Override
public DetailGraduationResult createDetailGraduationResult(StudentInformation studentInformation,
Set<TakenLecture> takenLectures,
Set<CommonCulture> graduationLectures, int commonCultureGraduationTotalCredit) {
CommonCultureDetailCategoryManager commonCultureDetailCategoryManager = new CommonCultureDetailCategoryManager();
List<DetailCategoryResult> commonCultureDetailCategoryResults = Arrays.stream(CommonCultureCategory.values())
.filter(
commonCultureCategory -> commonCultureCategory.isContainsEntryYear(studentInformation.getEntryYear()))
.map(commonCultureCategory -> commonCultureDetailCategoryManager.generate(takenLectures,
graduationLectures, commonCultureCategory))
.collect(Collectors.toList());

return DetailGraduationResult.create(COMMON_CULTURE, commonCultureGraduationTotalCredit,
commonCultureDetailCategoryResults);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.plzgraduate.myongjigraduatebe.lecture.domain.model;

import lombok.Builder;
import lombok.Getter;

@Getter
public class CommonCulture {

private Lecture lecture;
private CommonCultureCategory commonCultureCategory;

@Builder
private CommonCulture(Lecture lecture, CommonCultureCategory commonCultureCategory) {
this.lecture = lecture;
this.commonCultureCategory = commonCultureCategory;
}

public static CommonCulture of(Lecture lecture, CommonCultureCategory category) {
return CommonCulture.builder()
.lecture(lecture)
.commonCultureCategory(category).build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.plzgraduate.myongjigraduatebe.lecture.domain.model;

import java.util.List;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
public enum CommonCultureCategory {
CHRISTIAN_A("기독교", 4, List.of(16, 17, 18, 19)),
CHRISTIAN_B("기독교",4, List.of(20, 21, 22, 23)),
EXPRESSION("사고와 표현", 3, List.of(16, 17, 18, 19, 20 ,21, 22, 23)),
CAREER("진로", 2, List.of(18, 19, 20, 21, 22)),
DIGITAL_LITERACY("진로와디지털리터러시", 2, List.of(23));

private final String name;
private final int totalCredit;
private final List<Integer> containsEntryYears;

public boolean isContainsEntryYear(int entryYear) {
return containsEntryYears.contains(entryYear);
}

}
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
package com.plzgraduate.myongjigraduatebe.fixture;

import static org.assertj.core.api.Assertions.*;

import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import com.plzgraduate.myongjigraduatebe.lecture.domain.model.BasicAcademicalCulture;
import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.plzgraduate.myongjigraduatebe.fixture;

import static com.plzgraduate.myongjigraduatebe.fixture.CommonCultureFixture.*;
import static com.plzgraduate.myongjigraduatebe.lecture.domain.model.CommonCultureCategory.*;

import java.util.stream.Stream;

import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.ArgumentsProvider;


public class CommonCultureCategoryFixture implements ArgumentsProvider {

@Override
public Stream<? extends Arguments> provideArguments(ExtensionContext context) throws Exception {
return Stream.of(
Arguments.arguments(CHRISTIAN_A, 공통교양_16_17()),
Arguments.arguments(CHRISTIAN_A, 공통교양_18_19()),
Arguments.arguments(CHRISTIAN_B, 공통교양_20_21_22()),
Arguments.arguments(CHRISTIAN_B, 공통교양_23()),
Arguments.arguments(EXPRESSION, 공통교양_16_17()),
Arguments.arguments(EXPRESSION, 공통교양_18_19()),
Arguments.arguments(EXPRESSION, 공통교양_20_21_22()),
Arguments.arguments(EXPRESSION, 공통교양_23()),
Arguments.arguments(CAREER, 공통교양_18_19()),
Arguments.arguments(CAREER, 공통교양_20_21_22()),
Arguments.arguments(DIGITAL_LITERACY, 공통교양_23())
);
}
}
Loading

0 comments on commit 96cdb78

Please sign in to comment.