-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
핵심교양 졸업 계산 기능 구현 #161
Merged
The head ref may contain hidden characters: "feature/\uD575\uC2EC\uAD50\uC591_\uC878\uC5C5_\uACC4\uC0B0"
Merged
핵심교양 졸업 계산 기능 구현 #161
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
d84c6e7
refactor: 누락 로직 추가
5uhwann 402d970
chore: 핵심교양 데이터 추가
5uhwann f213b23
test: 핵심교양 fixture 작성
5uhwann 37e952e
test: 핵심교양 세부 카테고리 결과 테스트 작성
5uhwann 8cf4316
feat: 핵심교양 세부 카테고리 결과 반환 구현
5uhwann 592507e
test: 불필요 import 제거
5uhwann 65d4f7b
test: fixture 클래스명 변경
5uhwann 3b340f3
test: 핵심교양 세부 졸업 결과 테스트 작성
5uhwann 14d529d
test: 핵심교양 세부 졸업 결과 반환 구현
5uhwann 977d8e4
refactor: 세부 카테고리 잔여 학점 관련 필드 추가
5uhwann 04ad43e
test: 핵심교양 - 과학과기술 예외사항 로직 테스트 작성
5uhwann c7e9723
feat: 핵심교양 - 과학과기술 예외사항 로직 구현
5uhwann 297989b
test: 핵심교양 문화와예술 예외사항 로직 테스트 작성
5uhwann af961c1
test: 핵심교양 문화와예술 예외사항 로직 구현
5uhwann 100c8ae
refactor: DetailCategoryResult leftCredit 계산 로직 수정
5uhwann File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
...gjigraduatebe/graduation/domain/service/coreculture/CoreCultureDetailCategoryManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package com.plzgraduate.myongjigraduatebe.graduation.domain.service.coreculture; | ||
|
||
import static com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.Semester.*; | ||
|
||
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.CoreCulture; | ||
import com.plzgraduate.myongjigraduatebe.lecture.domain.model.CoreCultureCategory; | ||
import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture; | ||
import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture; | ||
import com.plzgraduate.myongjigraduatebe.user.domain.model.StudentInformation; | ||
|
||
public class CoreCultureDetailCategoryManager { | ||
|
||
private static final List<String> ICT_DEPARTMENTS = List.of( | ||
"응용소프트웨어학과", | ||
"데이터테크놀로지학과", | ||
"디지털콘텐츠디자인학과"); | ||
private static final Lecture 과학과기술_예외_과목 = Lecture.from("KMA02136"); | ||
private static final Set<Lecture> 문화와예술_예외_과목 = Set.of( | ||
Lecture.from("KMA02155"), | ||
Lecture.from("KMA02156")); | ||
|
||
public DetailCategoryResult generate(StudentInformation studentInformation, Set<TakenLecture> takenLectures, | ||
Set<CoreCulture> graduationLectures, CoreCultureCategory category) { | ||
Set<Lecture> graduationCoreCultureLectures = categorizeCommonCultures(graduationLectures, category); | ||
Set<TakenLecture> finishedTakenLecture = new HashSet<>(); | ||
Set<Lecture> taken = new HashSet<>(); | ||
|
||
takenLectures.stream() | ||
.filter(takenLecture -> graduationCoreCultureLectures.contains(takenLecture.getLecture())) | ||
.forEach(takenLecture -> { | ||
finishedTakenLecture.add(takenLecture); | ||
taken.add(takenLecture.getLecture()); | ||
}); | ||
takenLectures.removeAll(finishedTakenLecture); | ||
|
||
DetailCategoryResult commonCultureDetailCategoryResult = DetailCategoryResult.create( | ||
category.getName(), true, category.getTotalCredit()); | ||
calculateFreeElectiveLeftCredit(studentInformation, taken, commonCultureDetailCategoryResult); | ||
calculateNormalLeftCredit(taken, finishedTakenLecture, commonCultureDetailCategoryResult); | ||
commonCultureDetailCategoryResult.calculate(taken, graduationCoreCultureLectures); | ||
|
||
return commonCultureDetailCategoryResult; | ||
} | ||
|
||
private Set<Lecture> categorizeCommonCultures(Set<CoreCulture> graduationLectures, | ||
CoreCultureCategory category) { | ||
return graduationLectures.stream() | ||
.filter(coreCulture -> coreCulture.getCoreCultureCategory() == category) | ||
.map(CoreCulture::getLecture) | ||
.collect(Collectors.toSet()); | ||
} | ||
|
||
private void calculateFreeElectiveLeftCredit(StudentInformation studentInformation, Set<Lecture> taken, | ||
DetailCategoryResult commonCultureDetailCategoryResult) { | ||
if (ICT_DEPARTMENTS.contains(studentInformation.getDepartment()) && (taken.contains(과학과기술_예외_과목))) { | ||
taken.remove(과학과기술_예외_과목); | ||
int exceptionLectureCredit = 3; | ||
commonCultureDetailCategoryResult.addFreeElectiveLeftCredit(exceptionLectureCredit); | ||
} | ||
} | ||
|
||
private void calculateNormalLeftCredit(Set<Lecture> taken, Set<TakenLecture> finishedTakenLecture, | ||
DetailCategoryResult commonCultureDetailCategoryResult) { | ||
int normalLeftCredit = finishedTakenLecture.stream() | ||
.filter(takenLecture -> 문화와예술_예외_과목.contains(takenLecture.getLecture()) | ||
&& takenLecture.getYear() == 2022 | ||
&& takenLecture.getSemester() == FIRST) | ||
.mapToInt(takenLecture -> takenLecture.getLecture().getCredit()) | ||
.sum(); | ||
taken.removeAll(문화와예술_예외_과목); | ||
commonCultureDetailCategoryResult.addNormalLeftCredit(normalLeftCredit); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...myongjigraduatebe/graduation/domain/service/coreculture/CoreCultureGraduationManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.plzgraduate.myongjigraduatebe.graduation.domain.service.coreculture; | ||
|
||
import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.CORE_CULTURE; | ||
|
||
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.CoreCulture; | ||
import com.plzgraduate.myongjigraduatebe.lecture.domain.model.CoreCultureCategory; | ||
import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture; | ||
import com.plzgraduate.myongjigraduatebe.user.domain.model.StudentInformation; | ||
|
||
public class CoreCultureGraduationManager implements GraduationManager<CoreCulture> { | ||
@Override | ||
public DetailGraduationResult createDetailGraduationResult(StudentInformation studentInformation, | ||
Set<TakenLecture> takenLectures, Set<CoreCulture> graduationLectures, int coreCultureGraduationTotalCredit) { | ||
CoreCultureDetailCategoryManager coreCultureDetailCategoryManager = new CoreCultureDetailCategoryManager(); | ||
List<DetailCategoryResult> coreCultureDetailCategoryResults = Arrays.stream(CoreCultureCategory.values()) | ||
.map(coreCultureCategory -> coreCultureDetailCategoryManager.generate(studentInformation, takenLectures, | ||
graduationLectures, coreCultureCategory)) | ||
.collect(Collectors.toList()); | ||
|
||
return DetailGraduationResult.create(CORE_CULTURE, coreCultureGraduationTotalCredit, | ||
coreCultureDetailCategoryResults); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/com/plzgraduate/myongjigraduatebe/lecture/domain/model/CoreCulture.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 CoreCulture { | ||||||||
|
||||||||
private Lecture lecture; | ||||||||
private CoreCultureCategory coreCultureCategory; | ||||||||
|
||||||||
@Builder | ||||||||
private CoreCulture(Lecture lecture, CoreCultureCategory coreCultureCategory) { | ||||||||
this.lecture = lecture; | ||||||||
this.coreCultureCategory = coreCultureCategory; | ||||||||
} | ||||||||
|
||||||||
public static CoreCulture of(Lecture lecture, CoreCultureCategory category) { | ||||||||
return CoreCulture.builder() | ||||||||
.lecture(lecture) | ||||||||
.coreCultureCategory(category).build(); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
} | ||||||||
} |
18 changes: 18 additions & 0 deletions
18
...main/java/com/plzgraduate/myongjigraduatebe/lecture/domain/model/CoreCultureCategory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.plzgraduate.myongjigraduatebe.lecture.domain.model; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public enum CoreCultureCategory { | ||
|
||
HISTORY_PHILOSOPHY("역사와철학", 3), | ||
SOCIETY_COMMUNITY("사회와공동체", 3), | ||
CULTURE_ART("문화와예술", 3), | ||
SCIENCE_TECHNOLOGY("과학과기술", 3); | ||
|
||
private final String name; | ||
private final int totalCredit; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/test/java/com/plzgraduate/myongjigraduatebe/fixture/CoreCultureCategoryFixture.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.plzgraduate.myongjigraduatebe.fixture; | ||
|
||
import static com.plzgraduate.myongjigraduatebe.fixture.CoreCultureFixture.핵심교양_과학과기술; | ||
import static com.plzgraduate.myongjigraduatebe.fixture.CoreCultureFixture.핵심교양_문화와예술; | ||
import static com.plzgraduate.myongjigraduatebe.fixture.CoreCultureFixture.핵심교양_사회와공동체; | ||
import static com.plzgraduate.myongjigraduatebe.fixture.CoreCultureFixture.핵심교양_역사와철학; | ||
import static com.plzgraduate.myongjigraduatebe.lecture.domain.model.CoreCultureCategory.*; | ||
|
||
import java.util.Map; | ||
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 CoreCultureCategoryFixture implements ArgumentsProvider { | ||
|
||
@Override | ||
public Stream<? extends Arguments> provideArguments(ExtensionContext context) throws Exception { | ||
return Stream.of( | ||
Arguments.arguments(HISTORY_PHILOSOPHY,핵심교양_역사와철학()), | ||
Arguments.arguments(SOCIETY_COMMUNITY, 핵심교양_사회와공동체()), | ||
Arguments.arguments(CULTURE_ART, 핵심교양_문화와예술()), | ||
Arguments.arguments(SCIENCE_TECHNOLOGY, 핵심교양_과학과기술()) | ||
); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.