Skip to content
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

refactor: GonghakDao #60

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions src/main/java/com/example/gimmegonghakauth/InitData.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,75 +49,75 @@ public void initDatabase() {
majorsDao.save(computerMajor);
majorsDao.save(elecInfoMajor);

//19ํ•™๋…„๋„ computerMajor
//24ํ•™๋…„๋„ computerMajor
AbeekDomainBuilder abeek1 = AbeekDomain.builder()
.abeekType(AbeekTypeConst.BSM)
.majorsDomain(computerMajor)
.note("this is a test note")
.year(19)
.year(24)
.minCredit(18);
AbeekDomainBuilder abeek2 = AbeekDomain.builder()
.abeekType(AbeekTypeConst.PROFESSIONAL_NON_MAJOR)
.majorsDomain(computerMajor)
.note("this is a test note")
.year(19)
.year(24)
.minCredit(14);
AbeekDomainBuilder abeek3 = AbeekDomain.builder()
.abeekType(AbeekTypeConst.DESIGN)
.majorsDomain(computerMajor)
.note("this is a test note")
.year(19)
.minCredit(12);
.year(24)
.minCredit(10);
AbeekDomainBuilder abeek4 = AbeekDomain.builder()
.abeekType(AbeekTypeConst.MAJOR)
.majorsDomain(computerMajor)
.note("this is a test note")
.year(19)
.minCredit(60);
.year(24)
.minCredit(45);
AbeekDomainBuilder abeek5 = AbeekDomain.builder()
.abeekType(AbeekTypeConst.MINIMUM_CERTI)
.majorsDomain(computerMajor)
.note("this is a test note")
.year(19)
.minCredit(92);
.year(24)
.minCredit(77);

abeekDao.save(abeek1.build());
abeekDao.save(abeek2.build());
abeekDao.save(abeek3.build());
abeekDao.save(abeek4.build());
abeekDao.save(abeek5.build());

//19ํ•™๋…„๋„ ์ „์ •ํ†ต
//24ํ•™๋…„๋„ ์ „์ •ํ†ต
AbeekDomainBuilder abeek21 = AbeekDomain.builder()
.abeekType(AbeekTypeConst.MSC)
.majorsDomain(elecInfoMajor)
.note("this is a test note")
.year(19)
.minCredit(30);
.year(24)
.minCredit(27);
AbeekDomainBuilder abeek22 = AbeekDomain.builder()
.abeekType(AbeekTypeConst.PROFESSIONAL_NON_MAJOR)
.majorsDomain(elecInfoMajor)
.note("this is a test note")
.year(19)
.year(24)
.minCredit(14);
AbeekDomainBuilder abeek23 = AbeekDomain.builder()
.abeekType(AbeekTypeConst.DESIGN)
.majorsDomain(elecInfoMajor)
.note("this is a test note")
.year(19)
.year(24)
.minCredit(9);
AbeekDomainBuilder abeek24 = AbeekDomain.builder()
.abeekType(AbeekTypeConst.MAJOR)
.majorsDomain(elecInfoMajor)
.note("this is a test note")
.year(19)
.minCredit(54);
.year(24)
.minCredit(45);
AbeekDomainBuilder abeek25 = AbeekDomain.builder()
.abeekType(AbeekTypeConst.MINIMUM_CERTI)
.majorsDomain(elecInfoMajor)
.note("this is a test note")
.year(19)
.minCredit(98);
.year(24)
.minCredit(86);

abeekDao.save(abeek21.build());
abeekDao.save(abeek22.build());
Expand Down
11 changes: 4 additions & 7 deletions src/main/java/com/example/gimmegonghakauth/dao/GonghakDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
public class GonghakDao implements GonghakRepository{

private static final int DIVIDER = 1000000;
private static final int LATEST_YEAR = 24;
private final AbeekDao abeekDao;
private final GonghakCoursesDao gonghakCoursesDao;

Expand All @@ -32,12 +33,10 @@ public AbeekDomain save(AbeekDomain abeekDomain) {
return abeekDomain;
}

// ํ•™๋ฒˆ ์ž…ํ•™๋…„๋„๋ฅผ ๊ธฐ์ค€์œผ๋กœ ํ•ด๋‹น ๋…„๋„์˜ abeekType(์˜์—ญ๋ณ„ ๊ตฌ๋ถ„),minCredit(์˜์—ญ๋ณ„ ์ธ์ฆํ•™์ ) ๋ถˆ๋Ÿฌ์˜จ๋‹ค.
// ์ตœ์‹ ๋…„๋„์˜ abeekType(์˜์—ญ๋ณ„ ๊ตฌ๋ถ„),minCredit(์˜์—ญ๋ณ„ ์ธ์ฆํ•™์ ) ๋ถˆ๋Ÿฌ์˜จ๋‹ค.
@Override
public Optional<GonghakStandardDto> findStandard(Long studentId, MajorsDomain majorsDomain) {
int year = (int) (studentId/DIVIDER);
// log.info("year = {}",year);
return changeToGonghakStandardDto(majorsDomain, year);
public Optional<GonghakStandardDto> findStandard(MajorsDomain majorsDomain){
return changeToGonghakStandardDto(majorsDomain, LATEST_YEAR);
}

// gonghakCourse ์ค‘ ์ด์ˆ˜ํ•œ ๊ณผ๋ชฉ์„ ๋ถˆ๋Ÿฌ์˜จ๋‹ค.
Expand All @@ -60,8 +59,6 @@ private Optional<GonghakStandardDto> changeToGonghakStandardDto(MajorsDomain maj
// year, major๋ฅผ ๊ธฐ์ค€์œผ๋กœ abeek ๋ฐ์ดํ„ฐ๋ฅผ ๋ถˆ๋Ÿฌ์˜จ๋‹ค.
List<AbeekDomain> allByYearAndMajorsDomain = abeekDao.findAllByYearAndMajorsDomain(year, majorsDomain);

log.info("allByYearAndMajorsDomain.isEmpty() = {}", allByYearAndMajorsDomain.isEmpty());

// abeek์„ ๊ธฐ๋ฐ˜์œผ๋กœ abeekType(์˜์—ญ๋ณ„ ๊ตฌ๋ถ„),minCredit(์˜์—ญ๋ณ„ ์ธ์ฆํ•™์ ) ์ €์žฅํ•œ๋‹ค.
allByYearAndMajorsDomain.forEach(
abeekDomain -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public interface GonghakRepository {

AbeekDomain save(AbeekDomain abeekDomain);

Optional<GonghakStandardDto> findStandard(Long studentId, MajorsDomain majorsDomain);
Optional<GonghakStandardDto> findStandard(MajorsDomain majorsDomain);

List<GonghakCoursesByMajorDto> findUserCompletedCourses(Long studentId, MajorsDomain majorsDomain);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public Optional<GonghakResultDto> getResultRatio(UserDomain userDomain) {

// findStandard -> ํ•™๋ฒˆ ์ž…ํ•™๋…„๋„๋ฅผ ๊ธฐ์ค€์œผ๋กœ ํ•ด๋‹น ๋…„๋„์˜ abeekType(์˜์—ญ๋ณ„ ๊ตฌ๋ถ„),minCredit(์˜์—ญ๋ณ„ ์ธ์ฆํ•™์ ) ๋ถˆ๋Ÿฌ์˜จ๋‹ค.
Optional<GonghakStandardDto> standard = gonghakRepository.findStandard(
userDomain.getStudentId(), userDomain.getMajorsDomain());
userDomain.getMajorsDomain());

// default user abeek ํ•™์  ์ƒํƒœ map
Map<AbeekTypeConst, Double> userAbeekCredit = getUserAbeekCreditDefault(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ public GonghakRecommendCoursesDto createRecommendCourses(UserDomain userDomain)
GonghakRecommendCoursesDto gonghakRecommendCoursesDto = new GonghakRecommendCoursesDto();

// findStandard -> ํ•™๋ฒˆ ์ž…ํ•™๋…„๋„๋ฅผ ๊ธฐ์ค€์œผ๋กœ ํ•ด๋‹น ๋…„๋„์˜ abeekType(์˜์—ญ๋ณ„ ๊ตฌ๋ถ„),minCredit(์˜์—ญ๋ณ„ ์ธ์ฆํ•™์ ) ๋ถˆ๋Ÿฌ์˜จ๋‹ค.
Optional<GonghakStandardDto> standard = gonghakRepository.findStandard(
userDomain.getStudentId(), userDomain.getMajorsDomain());
Optional<GonghakStandardDto> standard = gonghakRepository.findStandard(userDomain.getMajorsDomain());

// ์ˆ˜๊ฐ•ํ•˜์ง€ ์•Š์€ ๊ณผ๋ชฉ ์ค‘ "์ „๋ฌธ ๊ต์–‘" ๊ณผ๋ชฉ์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค.
List<IncompletedCoursesDto> professionalNonMajor = gonghakRepository.findUserIncompletedCourses(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ public GonghakRecommendCoursesDto createRecommendCourses(UserDomain userDomain)
GonghakRecommendCoursesDto gonghakRecommendCoursesDto = new GonghakRecommendCoursesDto();

// findStandard -> ํ•™๋ฒˆ ์ž…ํ•™๋…„๋„๋ฅผ ๊ธฐ์ค€์œผ๋กœ ํ•ด๋‹น ๋…„๋„์˜ abeekType(์˜์—ญ๋ณ„ ๊ตฌ๋ถ„),minCredit(์˜์—ญ๋ณ„ ์ธ์ฆํ•™์ ) ๋ถˆ๋Ÿฌ์˜จ๋‹ค.
Optional<GonghakStandardDto> standard = gonghakRepository.findStandard(
userDomain.getStudentId(), userDomain.getMajorsDomain());
Optional<GonghakStandardDto> standard = gonghakRepository.findStandard(userDomain.getMajorsDomain());

// ์ˆ˜๊ฐ•ํ•˜์ง€ ์•Š์€ ๊ณผ๋ชฉ ์ค‘ "์ „๋ฌธ ๊ต์–‘" ๊ณผ๋ชฉ์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค.
List<IncompletedCoursesDto> professionalNonMajor = gonghakRepository.findUserIncompletedCourses(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void displayDaoMethod(){
@Test
@DisplayName("GonghakStandardDto 5๊ฐ€์ง€ ์ƒํƒœ ๋ชจ๋‘ ํฌํ•จ๋˜์–ด์žˆ๋Š”์ง€ ํ™•์ธ")
void findStandardKeySetTest() {
Optional<GonghakStandardDto> standard = gonghakRepository.findStandard(COM_TEST_STUDENT_ID, COM_TEST_MAJORDOMAIN);
Optional<GonghakStandardDto> standard = gonghakRepository.findStandard(COM_TEST_MAJORDOMAIN);
log.info("testStandard status ={}", standard.get().getStandards());
Map<AbeekTypeConst, Integer> testStandard = standard.get().getStandards();
assertThat(testStandard.keySet()).contains(AbeekTypeConst.BSM,AbeekTypeConst.PROFESSIONAL_NON_MAJOR,AbeekTypeConst.DESIGN,AbeekTypeConst.MAJOR,AbeekTypeConst.MINIMUM_CERTI);
Expand Down Expand Up @@ -140,9 +140,7 @@ void findUserCoursesByMajorByGonghakCoursesWithoutCompleteCoursesTest(){
@Test
@DisplayName("findStandard๊ฐ€ ์—†์„ ๋•Œ - Wrong Major")
void findStandardWrongMajorDomainTest(){
Optional<GonghakStandardDto> wrongStandard = gonghakRepository.findStandard(
COM_TEST_STUDENT_ID,
WRONG_TEST_MAJORDOMAIN);
Optional<GonghakStandardDto> wrongStandard = gonghakRepository.findStandard(WRONG_TEST_MAJORDOMAIN);
assertThat(wrongStandard.get().getStandards().isEmpty()).isEqualTo(true);
}
}