From a91cf8062a0af4f5eb4d9f79c70d662acbc3a1b9 Mon Sep 17 00:00:00 2001 From: jinhyeon Date: Sat, 30 Nov 2024 10:39:53 +0900 Subject: [PATCH 1/5] =?UTF-8?q?fix:=20=EC=9D=B4=EC=88=98=ED=95=99=EC=A0=90?= =?UTF-8?q?=EC=97=90=EC=84=9C=20=EB=B4=89=EC=82=AC=ED=95=99=EC=A0=90?= =?UTF-8?q?=EC=9D=B4=20=EC=9D=BC=EB=B0=98=EA=B5=90=EC=96=91=EC=9D=B4?= =?UTF-8?q?=EC=95=84=EB=8B=8C=20=EC=9E=90=EC=9C=A0=EC=84=A0=ED=83=9D?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EB=93=A4=EC=96=B4=EA=B0=80=EA=B2=8C?= =?UTF-8?q?=EB=81=94=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../myongjigraduatebe/lecture/domain/model/Lecture.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/domain/model/Lecture.java b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/domain/model/Lecture.java index 45127875..a12b8fd5 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/domain/model/Lecture.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/domain/model/Lecture.java @@ -8,6 +8,7 @@ public class Lecture { private static final String CULTURE_CODE_START_PREFIX = "KM"; + private static final String VOLUNTEER_CREDIT_CODE = "KMA02198"; private final String id; private final String name; @@ -43,7 +44,7 @@ public static Lecture of(String lectureCode, String name, int credit, int isRevo } public boolean isCulture() { - return id.startsWith(CULTURE_CODE_START_PREFIX); + return id.startsWith(CULTURE_CODE_START_PREFIX) && !id.equals(VOLUNTEER_CREDIT_CODE); } @Override From e391fa0681f363a00b085d8e7c920dca6721d537 Mon Sep 17 00:00:00 2001 From: jinhyeon Date: Sat, 30 Nov 2024 10:40:27 +0900 Subject: [PATCH 2/5] =?UTF-8?q?chore:=20=EB=B4=89=EC=82=AC=ED=95=99?= =?UTF-8?q?=EC=A0=90=20=ED=85=8C=EC=8A=A4=ED=8A=B8=EB=A5=BC=20=EC=9C=84?= =?UTF-8?q?=ED=95=B4=20lecture.csv=20=ED=8C=8C=EC=9D=BC=EC=9D=98=20mock=20?= =?UTF-8?q?=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/resources/lecture.csv | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/resources/lecture.csv b/src/test/resources/lecture.csv index 4942d212..bb241cb7 100644 --- a/src/test/resources/lecture.csv +++ b/src/test/resources/lecture.csv @@ -41,6 +41,7 @@ KMA02135, 우주생명마음, 3, 0, KMA02119 KMA02136, SW프로그래밍입문, 3, 0, null KMA02138, 인공지능의세계, 3, 0, null KMA02139, 4차산업혁명의이해, 3, 0, null +KMA02198, 봉사학점, 1, 0, null KMB02127, 한국문화와문자생활, 3, 0, null KMB02119, 영어와영미문화, 3, 1, null KMB02120, 아랍의언어와문화, 3, 0, null From dc99cafadf142524983d9f7c2fb9b89deae8050c Mon Sep 17 00:00:00 2001 From: jinhyeon Date: Sat, 30 Nov 2024 10:42:00 +0900 Subject: [PATCH 3/5] =?UTF-8?q?test:=20=EB=B4=89=EC=82=AC=ED=95=99?= =?UTF-8?q?=EC=A0=90=EC=9D=B4=20=EC=9E=90=EC=9C=A0=EC=84=A0=ED=83=9D=20?= =?UTF-8?q?=ED=95=99=EC=A0=90=EC=9C=BC=EB=A1=9C=20=EB=B0=98=EC=98=81?= =?UTF-8?q?=EB=90=98=EB=8A=94=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=B6=94=EA=B0=80(1=EB=B2=88,=202=EB=B2=88=20?= =?UTF-8?q?=EB=93=A4=EC=97=88=EC=9D=84=20=EB=95=8C)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FreeElectiveGraduationResultTest.java | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/FreeElectiveGraduationResultTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/FreeElectiveGraduationResultTest.java index 1131e53b..b68c93b5 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/FreeElectiveGraduationResultTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/FreeElectiveGraduationResultTest.java @@ -72,4 +72,56 @@ void createFreeElectiveGraduationResult() { remainCreditByTakenLectures + freeElectiveLeftCredit + leftNormalCultureCredit); } + @DisplayName("봉사학점을 한 번 들었을 때 자유선택 졸업 결과를 생성한다.") + @Test + void createFreeElectiveGraduationResult_withOneVolunteerCredit() { + //given + User user = UserFixture.경영학과_19학번_ENG34(); + Set takenLectures = new HashSet<>((Set.of( + TakenLecture.of(user, mockLectureMap.get("KMA02198"), 2021, Semester.FIRST) // 봉사학점 + ))); + TakenLectureInventory takenLectureInventory = TakenLectureInventory.from(takenLectures); + + int totalFreeElectiveCredit = 7; + int leftNormalCultureCredit = 0; + + //when + FreeElectiveGraduationResult freeElectiveGraduationResult = FreeElectiveGraduationResult.create( + totalFreeElectiveCredit, + takenLectureInventory, + List.of(), + leftNormalCultureCredit); + + //then + assertThat(freeElectiveGraduationResult) + .extracting("categoryName", "takenCredit") + .contains(FREE_ELECTIVE.getName(), 1); // 봉사학점 1학점 반영 + } + + @DisplayName("봉사학점을 두 번 들었을 때 자유선택 졸업 결과를 생성한다.") + @Test + void createFreeElectiveGraduationResult_withTwoVolunteerCredits() { + //given + User user = UserFixture.경영학과_19학번_ENG34(); + Set takenLectures = new HashSet<>((Set.of( + TakenLecture.of(user, mockLectureMap.get("KMA02198"), 2021, Semester.FIRST), // 봉사학점 1 + TakenLecture.of(user, mockLectureMap.get("KMA02198"), 2022, Semester.SECOND) // 봉사학점 2 + ))); + TakenLectureInventory takenLectureInventory = TakenLectureInventory.from(takenLectures); + + int totalFreeElectiveCredit = 7; + int leftNormalCultureCredit = 0; + + //when + FreeElectiveGraduationResult freeElectiveGraduationResult = FreeElectiveGraduationResult.create( + totalFreeElectiveCredit, + takenLectureInventory, + List.of(), + leftNormalCultureCredit); + + //then + assertThat(freeElectiveGraduationResult) + .extracting("categoryName", "takenCredit") + .contains(FREE_ELECTIVE.getName(), 2); // 봉사학점 2학점 반영 + } } From db3bf3097281b3d53ba43d089c47d4ea3b9235cd Mon Sep 17 00:00:00 2001 From: jinhyeon Date: Sat, 30 Nov 2024 13:27:14 +0900 Subject: [PATCH 4/5] =?UTF-8?q?refactor:=20=EA=B8=B0=EC=A1=B4=20=EB=B4=89?= =?UTF-8?q?=EC=82=AC=ED=95=99=EC=A0=90=EC=9D=84=20=EA=B5=90=EC=96=91=20?= =?UTF-8?q?=EC=88=98=EC=A4=80=EC=97=90=EC=84=9C=20=EA=B1=B0=EB=A5=B4?= =?UTF-8?q?=EB=8A=94=EA=B2=8C=20=EC=95=84=EB=8B=8C=20=EC=9D=BC=EB=B0=98?= =?UTF-8?q?=EA=B5=90=EC=96=91=20=EC=9D=B4=EC=88=98=ED=95=99=EC=A0=90=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC=EC=97=90=EC=84=9C=20=EA=B1=B0=EB=A5=B4?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../model/NormalCultureGraduationResult.java | 97 ++++++++++--------- .../lecture/domain/model/Lecture.java | 3 +- 2 files changed, 52 insertions(+), 48 deletions(-) diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/NormalCultureGraduationResult.java b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/NormalCultureGraduationResult.java index bddbb187..bd67965b 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/NormalCultureGraduationResult.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/NormalCultureGraduationResult.java @@ -4,65 +4,70 @@ import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture; import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLectureInventory; + import java.util.List; import java.util.Set; +import java.util.stream.Collectors; + import lombok.Builder; import lombok.Getter; @Getter public class NormalCultureGraduationResult { - private final String categoryName; - private final int totalCredit; - private boolean isCompleted; - private int takenCredit; + private static final String VOLUNTEER_CREDIT_CODE = "KMA02198"; - @Builder - private NormalCultureGraduationResult(String categoryName, boolean isCompleted, int totalCredit, - int takenCredit) { - this.categoryName = categoryName; - this.isCompleted = isCompleted; - this.totalCredit = totalCredit; - this.takenCredit = takenCredit; - } + private final String categoryName; + private final int totalCredit; + private boolean isCompleted; + private int takenCredit; - public static NormalCultureGraduationResult create(int totalCredit, - TakenLectureInventory takenLectureInventory, - List detailGraduationResults) { - return NormalCultureGraduationResult.builder() - .categoryName(NORMAL_CULTURE.getName()) - .isCompleted(false) - .totalCredit(totalCredit) - .takenCredit(calculateTakenCredit(takenLectureInventory, detailGraduationResults)) - .build(); - } + @Builder + private NormalCultureGraduationResult(String categoryName, boolean isCompleted, int totalCredit, + int takenCredit) { + this.categoryName = categoryName; + this.isCompleted = isCompleted; + this.totalCredit = totalCredit; + this.takenCredit = takenCredit; + } - private static int calculateTakenCredit(TakenLectureInventory takenLectureInventory, - List detailGraduationResults) { - int remainCreditByDetailGraduationResult = detailGraduationResults.stream() - .mapToInt(DetailGraduationResult::getNormalLeftCredit) - .sum(); + public static NormalCultureGraduationResult create(int totalCredit, + TakenLectureInventory takenLectureInventory, + List detailGraduationResults) { + return NormalCultureGraduationResult.builder() + .categoryName(NORMAL_CULTURE.getName()) + .isCompleted(false) + .totalCredit(totalCredit) + .takenCredit(calculateTakenCredit(takenLectureInventory, detailGraduationResults)) + .build(); + } - Set remainTakenNormalCultures = takenLectureInventory.getCultureLectures(); - int remainCreditByTakenLectures = remainTakenNormalCultures.stream() - .mapToInt(takenLecture -> takenLecture.getLecture() - .getCredit()) - .sum(); + private static int calculateTakenCredit(TakenLectureInventory takenLectureInventory, + List detailGraduationResults) { + int remainCreditByDetailGraduationResult = detailGraduationResults.stream() + .mapToInt(DetailGraduationResult::getNormalLeftCredit) + .sum(); + Set remainTakenNormalCultures = takenLectureInventory.getCultureLectures().stream() + .filter(takenLecture -> !takenLecture.getLecture().getId().equals(VOLUNTEER_CREDIT_CODE)) + .collect(Collectors.toSet()); + int remainCreditByTakenLectures = remainTakenNormalCultures.stream() + .mapToInt(takenLecture -> takenLecture.getLecture().getCredit()) + .sum(); + takenLectureInventory.handleFinishedTakenLectures(remainTakenNormalCultures); + return remainCreditByDetailGraduationResult + remainCreditByTakenLectures; + } - takenLectureInventory.handleFinishedTakenLectures(remainTakenNormalCultures); - return remainCreditByDetailGraduationResult + remainCreditByTakenLectures; - } - public void checkCompleted() { - this.isCompleted = takenCredit >= totalCredit; - } + public void checkCompleted() { + this.isCompleted = takenCredit >= totalCredit; + } - public int getLeftCredit() { - if (totalCredit >= takenCredit) { - return 0; - } - int leftCredit = takenCredit - totalCredit; - this.takenCredit = totalCredit; - return leftCredit; - } + public int getLeftCredit() { + if (totalCredit >= takenCredit) { + return 0; + } + int leftCredit = takenCredit - totalCredit; + this.takenCredit = totalCredit; + return leftCredit; + } } diff --git a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/domain/model/Lecture.java b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/domain/model/Lecture.java index a12b8fd5..45127875 100644 --- a/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/domain/model/Lecture.java +++ b/src/main/java/com/plzgraduate/myongjigraduatebe/lecture/domain/model/Lecture.java @@ -8,7 +8,6 @@ public class Lecture { private static final String CULTURE_CODE_START_PREFIX = "KM"; - private static final String VOLUNTEER_CREDIT_CODE = "KMA02198"; private final String id; private final String name; @@ -44,7 +43,7 @@ public static Lecture of(String lectureCode, String name, int credit, int isRevo } public boolean isCulture() { - return id.startsWith(CULTURE_CODE_START_PREFIX) && !id.equals(VOLUNTEER_CREDIT_CODE); + return id.startsWith(CULTURE_CODE_START_PREFIX); } @Override From 5379ebe35dd5e618601108ad8b687891bf8d5e24 Mon Sep 17 00:00:00 2001 From: jinhyeon Date: Sat, 30 Nov 2024 13:28:01 +0900 Subject: [PATCH 5/5] =?UTF-8?q?test:=20=EC=88=98=EC=A0=95=EC=97=90=20?= =?UTF-8?q?=EB=94=B0=EB=9D=BC=20=EB=B4=89=EC=82=AC=ED=95=99=EC=A0=90?= =?UTF-8?q?=EC=9D=B4=20=EC=9D=BC=EB=B0=98=EA=B5=90=EC=96=91=20=ED=95=99?= =?UTF-8?q?=EC=A0=90=EC=97=90=20=ED=8F=AC=ED=95=A8=EB=90=98=EC=A7=80=20?= =?UTF-8?q?=EC=95=8A=EB=8A=94=EC=A7=80=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../NormalCultureGraduationResultTest.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/NormalCultureGraduationResultTest.java b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/NormalCultureGraduationResultTest.java index 287f47b5..d59d9000 100644 --- a/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/NormalCultureGraduationResultTest.java +++ b/src/test/java/com/plzgraduate/myongjigraduatebe/graduation/domain/model/NormalCultureGraduationResultTest.java @@ -71,5 +71,27 @@ void createNormalCultureGraduationResult() { .contains(NORMAL_CULTURE.getName(), remainTakenNormalCultureCredit + remainCreditByDetailGraduationResult); } + @DisplayName("봉사학점은 일반교양 학점에 포함되지 않는다.") + @Test + void volunteerCreditIsNotIncludedInNormalCulture() { + //given + User user = UserFixture.경영학과_19학번_ENG34(); + Set takenLectures = new HashSet<>((Set.of( + TakenLecture.of(user, mockLectureMap.get("KMA00101"), 2019, Semester.FIRST), + TakenLecture.of(user, mockLectureMap.get("KMA02102"), 2019, Semester.FIRST), + TakenLecture.of(user, mockLectureMap.get("KMA02198"), 2021, Semester.FIRST) // 봉사학점 + ))); + TakenLectureInventory takenLectureInventory = TakenLectureInventory.from(takenLectures); + //when + NormalCultureGraduationResult normalCultureGraduationResult = NormalCultureGraduationResult.create( + 9, + takenLectureInventory, + List.of()); + + //then + assertThat(normalCultureGraduationResult) + .extracting("takenCredit") + .isEqualTo(4); // 봉사학점(1학점)은 제외되고, 나머지 일반교양 학점만 포함 + } }