Skip to content

Commit

Permalink
refactor: 졸업 결과 조회 구현 (#176)
Browse files Browse the repository at this point in the history
* test: Lecture 교양 과목 여부 확인 테스트 작성

* refactor: calculateLeftCredit 누락 로직 추가

* refactor: TakenLecture 일급컬렉션 적용

* test: TakenLectureInventory 테스트 작성

* test: NormalCultureGraduationResult 생성 테스트 작성

* feat: NormalCultureGraduationResult 생성 계산 구현

* refactor: FreeElectiveGraduationResult 생성 테스트 작성

* feat: FreeElectiveGraduationResult 생성 구현

* test: TakenLecture equals 테스트 작성

* test: ChapelResult 이수 완려 여부 체크 테스트

* feat: 채플 졸업 결과 생성 구현

* test: 전체 졸업 결과 - 남은 수강 과목 처리 및 졸업 가능 여부 판단 로직 테스트

* refactor: 전공명 - '학과' 제거

* test: SpringDataGraduationRequirementRepository 테스트 작성

* test: SpringDataCommonCultureRepositoryTest 테스트 작성

* test: LoadGraduationRequirementPersistenceAdapter 테스트 작성

* test: LectureMapper 테스트 작성

* test: BasicAcademicalCultureRepository 테스트 작성

* test: LectureMapper - mapToCBasicAcademicalCulture 테스트 작성

* test: MajorRepository 테스트 작성

* test: LectureMapper - mapToMajor 테스트 작성

* feat: 변경사항 적용

* refactor: 패키지 명 수정에 따른 변경

* refactor: 단과대 text 추가

* refactor: BasicAcademicalCulture 필드 변경 department -> college

* refactor: Major 필드 변경 department -> major

* feat: LoadGraduationRequirementPort 구현

* feat: LoadCommonCulturePort 구현

* feat: LoadCoreCulturePort 구현

* feat: LoadBasicAcademicalCulturePort 구현

* feat: LoadMajorPort 구현

* feat: LoadTakenLecturePort 구현

* test: GraduationResult 졸업결과 생성 로직 추가 테스트

* test: CheckGraduationService 테스트 작성

* feat: 졸업 결과 확인 구현

* refactor: 일반교양 초과 학점 처리

* refactor: 불필요 주석 삭제

* refactor: GraduationResponse 중복 로직 메서드 추출

* refactor: GraduationRequirement 영어 카테고리 학점 이관 로직 구현

* refactor: LoadGraduationRequirementPersistenceAdapter - 졸업 요건 조회 시 영어 레벨 확인 로직 추가

* refactor: 메서드명 수정

* refactor: 영어레벨에 따른 영어 카테고리 만족 조건 로직 및 영어 면제 로직 추가

* test: 테스트 오류 수정

* test: TakenLectureRepository - findByUser 테스트 작성

* refactor: 코드 포맷팅

* refactor: 변경사항 적용

* refactor: code smell 제거

* refactor: 누락 패키지 추가

* test: 테스트 오류 수정

* refactor: 메서드 명 변경

* refactor: 클래스 명 변경

* test: 누락 테스트 추가

* refactor: 메서드 명 변경 및 불필요 클래스 삭제

* refactor: 불필요 상속 제거

* refactor: final 키워드 제거

* refactor: Major 클래스명 변경

* refactor: BasicAcademical 클래스명 변경

* refactor: jpa fetch join 추가

* refactor: 변수 명 수정

* refactor: TakenLectureInventory 정적 팩터리 메서드 추가

* refactor: GraduationResult 채플 점수 변수명 명시

* refactor: 메서드 명 수정

* refactor: 클래스 명 수정

* test: find adapter 누락 테스트 추가

* refactor: 코드스멜 제거

* test: 누락 테스트 추가

* refactor: final 키워드 추가

* refactor: 코드 스멜 제거
  • Loading branch information
5uhwann authored Sep 17, 2023
1 parent f7368ab commit 2307b5c
Show file tree
Hide file tree
Showing 126 changed files with 3,121 additions and 535 deletions.
5 changes: 0 additions & 5 deletions .husky/prepare-commit-msg
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,3 @@ if !(printf '%s\n' "${TYPE_LIST[@]}" | grep -xq $TYPE); then
printf '%s\n' "${TYPE_LIST[@]}"
exit 1
fi

# if [ -n $ISSUE_NUMBER ] && ! [[ $BRANCH_IN_COMMIT -ge 1 ]]; then
if [ -n $ISSUE_NUMBER ] && ! [[ $BRANCH_IN_COMMIT -ge 1 ]]; then
sed -i.bak -e "1s/^/[$ISSUE_NUMBER]/" $1
fi
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
import javax.validation.ValidationException;

@Slf4j
@RestControllerAdvice
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
@Documented
@Component
public @interface UseCase {

@AliasFor(annotation = Component.class)
String value() default "";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.plzgraduate.myongjigraduatebe.graduation.adpater.in.web;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import com.plzgraduate.myongjigraduatebe.core.meta.LoginUser;
import com.plzgraduate.myongjigraduatebe.core.meta.WebAdapter;
import com.plzgraduate.myongjigraduatebe.graduation.adpater.in.web.response.GraduationResponse;
import com.plzgraduate.myongjigraduatebe.graduation.application.port.in.CheckGraduationUseCase;
import com.plzgraduate.myongjigraduatebe.user.domain.model.User;

import lombok.RequiredArgsConstructor;

@WebAdapter
@RequestMapping("/api/v1/graduation")
@RequiredArgsConstructor
class GraduationController {

private final CheckGraduationUseCase checkGraduationUseCase;

@GetMapping("/result")
public GraduationResponse check(@LoginUser User user) {
return checkGraduationUseCase.checkGraduation(user);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.plzgraduate.myongjigraduatebe.graduation.adpater.in.web.response;

import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationResult;
import com.plzgraduate.myongjigraduatebe.user.domain.model.User;

import lombok.Builder;
import lombok.Getter;

@Getter
public class BasicInfoResponse {

private final String name;
private final String studentNumber;
private final String major;
private final int totalCredit;
private final int takenCredit;

@Builder
private BasicInfoResponse(String name, String studentNumber, String major, int totalCredit, int takenCredit) {
this.name = name;
this.studentNumber = studentNumber;
this.major = major;
this.totalCredit = totalCredit;
this.takenCredit = takenCredit;
}

public static BasicInfoResponse of(User user, GraduationResult graduationResult) {
return BasicInfoResponse.builder()
.name(user.getName())
.studentNumber(user.getStudentNumber())
.major(user.getMajor())
.totalCredit(graduationResult.getTotalCredit())
.takenCredit(graduationResult.getTakenCredit()).build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.plzgraduate.myongjigraduatebe.graduation.adpater.in.web.response;

import com.plzgraduate.myongjigraduatebe.graduation.domain.model.ChapelResult;

import lombok.Builder;
import lombok.Getter;

@Getter
public class ChapelResultResponse {

private final int totalCount = 4;
private final int takenCount;
private final boolean completed;

@Builder
private ChapelResultResponse(int takenCount, boolean completed) {
this.takenCount = takenCount;
this.completed = completed;
}

public static ChapelResultResponse from(ChapelResult chapelResult) {
return ChapelResultResponse.builder()
.takenCount(chapelResult.getTakenCount())
.completed(chapelResult.isCompleted()).build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.plzgraduate.myongjigraduatebe.graduation.adpater.in.web.response;

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

import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailCategoryResult;

import lombok.Builder;
import lombok.Getter;

@Getter
public class DetailGraduationCategoryResultResponse {

private final String categoryName;
private final int totalCredits;
private final int takenCredits;
private final List<LectureResponse> takenLectures;
private final List<LectureResponse> haveToLectures;
private final boolean completed;

@Builder
private DetailGraduationCategoryResultResponse(String categoryName, int totalCredits, int takenCredits,
List<LectureResponse> takenLectures, List<LectureResponse> haveToLectures, boolean completed) {
this.categoryName = categoryName;
this.totalCredits = totalCredits;
this.takenCredits = takenCredits;
this.takenLectures = takenLectures;
this.haveToLectures = haveToLectures;
this.completed = completed;
}

public static DetailGraduationCategoryResultResponse from(DetailCategoryResult detailCategoryResult) {
return DetailGraduationCategoryResultResponse.builder()
.categoryName(detailCategoryResult.getDetailCategoryName())
.totalCredits(detailCategoryResult.getTotalCredits())
.takenCredits(detailCategoryResult.getTakenCredits())
.takenLectures(detailCategoryResult.getTakenLectures().stream()
.map(LectureResponse::from)
.collect(Collectors.toList()))
.haveToLectures(detailCategoryResult.getHaveToLectures().stream()
.map(LectureResponse::from)
.collect(Collectors.toList()))
.completed(detailCategoryResult.isCompleted()).build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.plzgraduate.myongjigraduatebe.graduation.adpater.in.web.response;

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

import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailGraduationResult;

import lombok.Builder;
import lombok.Getter;

@Getter
public class DetailGraduationResultResponse {

private final int totalCredit;
private final int takenCredit;
private final List<DetailGraduationCategoryResultResponse> detailCategory;
private final boolean completed;

@Builder
private DetailGraduationResultResponse(int totalCredit, int takenCredit,
List<DetailGraduationCategoryResultResponse> detailCategory, boolean completed) {
this.totalCredit = totalCredit;
this.takenCredit = takenCredit;
this.detailCategory = detailCategory;
this.completed = completed;
}

public static DetailGraduationResultResponse from(DetailGraduationResult detailGraduationResult) {
return DetailGraduationResultResponse.builder()
.totalCredit(detailGraduationResult.getTotalCredit())
.takenCredit(detailGraduationResult.getTakenCredit())
.detailCategory(detailGraduationResult.getDetailCategory().stream()
.map(DetailGraduationCategoryResultResponse::from)
.collect(Collectors.toList()))
.completed(detailGraduationResult.isCompleted()).build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.plzgraduate.myongjigraduatebe.graduation.adpater.in.web.response;

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

import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory;
import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationResult;
import com.plzgraduate.myongjigraduatebe.user.domain.model.User;

import lombok.Builder;
import lombok.Getter;

@Getter
public class GraduationResponse {

private final BasicInfoResponse basicInfo;
private final ChapelResultResponse chapelResult;
private final DetailGraduationResultResponse commonCulture;
private final DetailGraduationResultResponse coreCulture;
private final DetailGraduationResultResponse basicAcademicalCulture;
private final DetailGraduationResultResponse major;
private final RestResultResponse normalCulture;
private final RestResultResponse freeElective;
private final boolean graduated;

@Builder
private GraduationResponse(BasicInfoResponse basicInfo, ChapelResultResponse chapelResult,
DetailGraduationResultResponse commonCulture, DetailGraduationResultResponse coreCulture,
DetailGraduationResultResponse basicAcademicalCulture, DetailGraduationResultResponse major,
RestResultResponse normalCulture, RestResultResponse freeElective, boolean graduated) {
this.basicInfo = basicInfo;
this.chapelResult = chapelResult;
this.commonCulture = commonCulture;
this.coreCulture = coreCulture;
this.basicAcademicalCulture = basicAcademicalCulture;
this.major = major;
this.normalCulture = normalCulture;
this.freeElective = freeElective;
this.graduated = graduated;
}

public static GraduationResponse of(User user, GraduationResult graduationResult) {
return GraduationResponse.builder()
.basicInfo(BasicInfoResponse.of(user, graduationResult))
.chapelResult(ChapelResultResponse.from(graduationResult.getChapelResult()))
.commonCulture(findDetailGraduationResultResponse(graduationResult, COMMON_CULTURE))
.coreCulture(findDetailGraduationResultResponse(graduationResult, CORE_CULTURE))
.basicAcademicalCulture(findDetailGraduationResultResponse(graduationResult, BASIC_ACADEMICAL_CULTURE))
.major(findDetailGraduationResultResponse(graduationResult, MAJOR))
.normalCulture(
RestResultResponse.fromNormalCultureResult(graduationResult.getNormalCultureGraduationResult()))
.freeElective(RestResultResponse.fromFreeElectiveResult(graduationResult.getFreeElectiveGraduationResult()))
.graduated(graduationResult.isGraduated())
.build();
}

private static DetailGraduationResultResponse findDetailGraduationResultResponse(GraduationResult graduationResult,
GraduationCategory graduationCategory) {
return graduationResult.getDetailGraduationResults().stream()
.filter(detailGraduationResult -> detailGraduationResult.getCategoryName()
.equals(graduationCategory.getName()))
.map(DetailGraduationResultResponse::from)
.findFirst()
.orElseThrow(IllegalArgumentException::new);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.plzgraduate.myongjigraduatebe.graduation.adpater.in.web.response;

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

import lombok.Builder;
import lombok.Getter;

@Getter
public class LectureResponse {

private final Long id;
private final String code;
private final String name;
private final int credit;

@Builder
private LectureResponse(Long id, String code, String name, int credit) {
this.id = id;
this.code = code;
this.name = name;
this.credit = credit;
}

public static LectureResponse from(Lecture lecture) {
return LectureResponse.builder()
.id(lecture.getId())
.code(lecture.getLectureCode())
.name(lecture.getName())
.credit(lecture.getCredit()).build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.plzgraduate.myongjigraduatebe.graduation.adpater.in.web.response;

import com.plzgraduate.myongjigraduatebe.graduation.domain.model.FreeElectiveGraduationResult;
import com.plzgraduate.myongjigraduatebe.graduation.domain.model.NormalCultureGraduationResult;

import lombok.Builder;
import lombok.Getter;

@Getter
public class RestResultResponse {

private final int totalCredit;
private final int takenCredit;
private final boolean completed;

@Builder
private RestResultResponse(int totalCredit, int takenCredit, boolean completed) {
this.totalCredit = totalCredit;
this.takenCredit = takenCredit;
this.completed = completed;
}

public static RestResultResponse fromNormalCultureResult(
NormalCultureGraduationResult normalCultureGraduationResult) {
return RestResultResponse.builder()
.totalCredit(normalCultureGraduationResult.getTotalCredit())
.takenCredit(normalCultureGraduationResult.getTakenCredit())
.completed(normalCultureGraduationResult.isCompleted()).build();
}

public static RestResultResponse fromFreeElectiveResult(
FreeElectiveGraduationResult freeElectiveGraduationResult) {
return RestResultResponse.builder()
.totalCredit(freeElectiveGraduationResult.getTotalCredit())
.takenCredit(freeElectiveGraduationResult.getTakenCredit())
.completed(freeElectiveGraduationResult.isCompleted()).build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.plzgraduate.myongjigraduatebe.graduation.adpater.out.persistence;

import com.plzgraduate.myongjigraduatebe.core.meta.PersistenceAdapter;
import com.plzgraduate.myongjigraduatebe.graduation.adpater.out.persistence.entity.GraduationRequirementJpaEntity;
import com.plzgraduate.myongjigraduatebe.graduation.application.port.out.FindGraduationRequirementPort;
import com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationRequirement;
import com.plzgraduate.myongjigraduatebe.user.domain.model.College;
import com.plzgraduate.myongjigraduatebe.user.domain.model.EnglishLevel;
import com.plzgraduate.myongjigraduatebe.user.domain.model.User;

import lombok.RequiredArgsConstructor;

@PersistenceAdapter
@RequiredArgsConstructor
class FindGraduationRequirementPersistenceAdapter implements FindGraduationRequirementPort {

private final GraduationRequirementRepository graduationRequirementRepository;
private final GraduationRequirementMapper mapper;

@Override
public GraduationRequirement findGraduationRequirement(User user) {
if (isDualMajorUser(user)) {
GraduationRequirementJpaEntity dualMajorRequirementEntity = graduationRequirementRepository.findDualMajorRequirementByUser(
College.findBelongingCollege(user.getMajor()), user.getEntryYear());
GraduationRequirement graduationRequirement = mapper.mapToDomainModel(dualMajorRequirementEntity);
checkUserEnglishLevel(user, graduationRequirement);
return graduationRequirement;
}
GraduationRequirementJpaEntity singleMajorRequirementEntity = graduationRequirementRepository.findSingleMajorRequirementByUser(
College.findBelongingCollege(user.getMajor()), user.getEntryYear());
GraduationRequirement graduationRequirement = mapper.mapToDomainModel(singleMajorRequirementEntity);
checkUserEnglishLevel(user, graduationRequirement);
return graduationRequirement;
}

private boolean isDualMajorUser(User user) {
return user.getSubMajor() != null;
}

private void checkUserEnglishLevel(User user, GraduationRequirement graduationRequirement) {
if (user.getEnglishLevel() == EnglishLevel.FREE) {
graduationRequirement.transferEnglishCategoryCredit();
}
}
}
Loading

0 comments on commit 2307b5c

Please sign in to comment.