Skip to content
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
12 changes: 6 additions & 6 deletions src/main/java/com/example/gimmegonghakauth/InitData.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.example.gimmegonghakauth.dao.AbeekDao;
import com.example.gimmegonghakauth.dao.CompletedCoursesDao;
import com.example.gimmegonghakauth.dao.CoursesDao;
import com.example.gimmegonghakauth.dao.GonghakCorusesDao;
import com.example.gimmegonghakauth.dao.GonghakCoursesDao;
import com.example.gimmegonghakauth.dao.MajorsDao;
import com.example.gimmegonghakauth.dao.UserDao;
import com.example.gimmegonghakauth.domain.AbeekDomain;
Expand Down Expand Up @@ -33,7 +33,7 @@ public class InitData {
private final AbeekDao abeekDao;
private final CompletedCoursesDao completedCoursesDao;
private final CoursesDao coursesDao;
private final GonghakCorusesDao gonghakCorusesDao;
private final GonghakCoursesDao gonghakCoursesDao;
private final UserDao userDao;
private final PasswordEncoder passwordEncoder;

Expand Down Expand Up @@ -229,10 +229,10 @@ public void initDatabase() {
.passCategory("인선")
.year(19).build();

gonghakCorusesDao.save(gonghakCourses1);
gonghakCorusesDao.save(gonghakCourses2);
gonghakCorusesDao.save(gonghakCourses3);
gonghakCorusesDao.save(gonghakCourses4);
gonghakCoursesDao.save(gonghakCourses1);
gonghakCoursesDao.save(gonghakCourses2);
gonghakCoursesDao.save(gonghakCourses3);
gonghakCoursesDao.save(gonghakCourses4);
}


Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/example/gimmegonghakauth/InitFileData.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.example.gimmegonghakauth.constant.CourseCategoryConst;
import com.example.gimmegonghakauth.dao.CoursesDao;
import com.example.gimmegonghakauth.dao.GonghakCorusesDao;
import com.example.gimmegonghakauth.dao.GonghakCoursesDao;
import com.example.gimmegonghakauth.dao.MajorsDao;
import com.example.gimmegonghakauth.domain.CoursesDomain;
import com.example.gimmegonghakauth.domain.GonghakCoursesDomain;
Expand All @@ -24,7 +24,7 @@ public class InitFileData {

private final MajorsDao majorsDao;
private final CoursesDao coursesDao;
private final GonghakCorusesDao gonghakCorusesDao;
private final GonghakCoursesDao gonghakCoursesDao;

@EventListener(ApplicationReadyEvent.class)
@Transactional
Expand Down Expand Up @@ -82,7 +82,7 @@ private void inputGonghakCoursesCsv(String csvFilePath) {
try {
Optional<GonghakCoursesDomain> course = mapToGonghakCoursesDomain(data);
if (course.isPresent()) {
gonghakCorusesDao.save(course.get());
gonghakCoursesDao.save(course.get());
}
} catch (Exception e) {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,16 @@
import org.springframework.stereotype.Repository;

@Repository
public interface GonghakCorusesDao extends JpaRepository<GonghakCoursesDomain,Long> {

List<GonghakCoursesDomain> findAllByMajorsDomain(MajorsDomain majorsDomain);
public interface GonghakCoursesDao extends JpaRepository<GonghakCoursesDomain,Long> {

@Query("select new com.example.gimmegonghakauth.dto.GonghakCoursesByMajorDto(GCD.coursesDomain.courseId, GCD.coursesDomain.name, GCD.year, GCD.courseCategory, GCD.passCategory, GCD.designCredit, GCD.coursesDomain.credit) from GonghakCoursesDomain GCD "
+ "join CompletedCoursesDomain GCCD on GCD.coursesDomain = GCCD.coursesDomain "
+ "where GCCD.userDomain.studentId =:studentId and GCD.majorsDomain.id = :majorsId and GCCD.year = GCD.year")
List<GonghakCoursesByMajorDto> findUserCoursesByMajorAndGonghakCoursesWithCompletedCourses(@Param("studentId") Long studentId, @Param("majorsId") Long majorId);
+ "join CompletedCoursesDomain CCD on GCD.coursesDomain = CCD.coursesDomain "
+ "where CCD.userDomain.studentId =:studentId and GCD.majorsDomain.id = :majorsId and CCD.year = GCD.year")
List<GonghakCoursesByMajorDto> findUserCompletedCourses(@Param("studentId") Long studentId, @Param("majorsId") Long majorId);

@Query("select new com.example.gimmegonghakauth.dto.IncompletedCoursesDto(GCD.coursesDomain.name, GCD.courseCategory, GCD.coursesDomain.credit, GCD.designCredit) from GonghakCoursesDomain GCD "
+ "left join CompletedCoursesDomain GCCD on GCCD.coursesDomain = GCD.coursesDomain "
+ "where GCD.majorsDomain = :majorsDomain and GCD.year = :year and GCD.courseCategory = :courseCategory and GCCD.id is null and :studentId is not null")
List<IncompletedCoursesDto> findUserCoursesByMajorAndCourseCategoryAndGonghakCoursesWithoutCompleteCourses(@Param("courseCategory") CourseCategoryConst courseCategory, @Param("studentId") Long studentId, @Param("majorsDomain") MajorsDomain majorsDomain, @Param("year") Long year);
+ "left join CompletedCoursesDomain CCD on CCD.coursesDomain = GCD.coursesDomain "
+ "where GCD.majorsDomain = :majorsDomain and GCD.year = :year and GCD.courseCategory = :courseCategory and CCD.id is null and :studentId is not null")
List<IncompletedCoursesDto> findUserIncompletedCourses(@Param("courseCategory") CourseCategoryConst courseCategory, @Param("studentId") Long studentId, @Param("majorsDomain") MajorsDomain majorsDomain, @Param("year") Long year);

}
13 changes: 6 additions & 7 deletions src/main/java/com/example/gimmegonghakauth/dao/GonghakDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class GonghakDao implements GonghakRepository{

private static final int DIVIDER = 1000000;
private final AbeekDao abeekDao;
private final GonghakCorusesDao gonghakCorusesDao;
private final GonghakCoursesDao gonghakCoursesDao;

@Override
public AbeekDomain save(AbeekDomain abeekDomain) {
Expand All @@ -42,17 +42,16 @@ public Optional<GonghakStandardDto> findStandard(Long studentId, MajorsDomain ma

// gonghakCourse 중 이수한 과목을 불러온다.
@Override
public List<GonghakCoursesByMajorDto> findUserCoursesByMajorByGonghakCoursesWithCompletedCourses(
public List<GonghakCoursesByMajorDto> findUserCompletedCourses(
Long studentId, MajorsDomain majorsDomain) {
return gonghakCorusesDao.findUserCoursesByMajorAndGonghakCoursesWithCompletedCourses(studentId,majorsDomain.getId());
return gonghakCoursesDao.findUserCompletedCourses(studentId,majorsDomain.getId());
}

//
// gonghakCourse 중 이수하지 않은 과목을 불러온다.
@Override
public List<IncompletedCoursesDto> findUserCoursesByMajorByGonghakCoursesWithoutCompleteCourses(
public List<IncompletedCoursesDto> findUserIncompletedCourses(
CourseCategoryConst courseCategory, Long studentId, MajorsDomain majorsDomain) {
return gonghakCorusesDao.findUserCoursesByMajorAndCourseCategoryAndGonghakCoursesWithoutCompleteCourses(
courseCategory, studentId, majorsDomain, studentId/DIVIDER);
return gonghakCoursesDao.findUserIncompletedCourses(courseCategory, studentId, majorsDomain, studentId/DIVIDER);
}

private Optional<GonghakStandardDto> changeToGonghakStandardDto(MajorsDomain majorsDomain, int year) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ public interface GonghakRepository {

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

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

List<IncompletedCoursesDto> findUserCoursesByMajorByGonghakCoursesWithoutCompleteCourses(
List<IncompletedCoursesDto> findUserIncompletedCourses(
CourseCategoryConst courseCategory,Long studentId, MajorsDomain majorsDomain);

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

// user 공학 상태 테이블
// gonghakCourse 중 이수한 과목을 불러온다.
List<GonghakCoursesByMajorDto> userCoursesByMajorByGonghakCoursesWithCompletedCourses = gonghakRepository.findUserCoursesByMajorByGonghakCoursesWithCompletedCourses(
List<GonghakCoursesByMajorDto> userCoursesByMajorByGonghakCoursesWithCompletedCourses = gonghakRepository.findUserCompletedCourses(
userDomain.getStudentId(), userDomain.getMajorsDomain());

// user
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ public GonghakRecommendCoursesDto createRecommendCourses(UserDomain userDomain)
userDomain.getStudentId(), userDomain.getMajorsDomain());

// 수강하지 않은 과목 중 "전문 교양" 과목을 반환한다.
List<IncompletedCoursesDto> professionalNonMajor = gonghakRepository.findUserCoursesByMajorByGonghakCoursesWithoutCompleteCourses(
List<IncompletedCoursesDto> professionalNonMajor = gonghakRepository.findUserIncompletedCourses(
CourseCategoryConst.전문교양, userDomain.getStudentId(), userDomain.getMajorsDomain()
);

// 수강하지 않은 과목 중 "전공" 과목을 반환한다.
List<IncompletedCoursesDto> major = gonghakRepository.findUserCoursesByMajorByGonghakCoursesWithoutCompleteCourses(
List<IncompletedCoursesDto> major = gonghakRepository.findUserIncompletedCourses(
CourseCategoryConst.전공, userDomain.getStudentId(), userDomain.getMajorsDomain()
);

// 수강하지 않은 과목 중 "BSM" 과목을 반환한다.
List<IncompletedCoursesDto> bsm = gonghakRepository.findUserCoursesByMajorByGonghakCoursesWithoutCompleteCourses(
List<IncompletedCoursesDto> bsm = gonghakRepository.findUserIncompletedCourses(
CourseCategoryConst.BSM, userDomain.getStudentId(), userDomain.getMajorsDomain()
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ public GonghakRecommendCoursesDto createRecommendCourses(UserDomain userDomain)
userDomain.getStudentId(), userDomain.getMajorsDomain());

// 수강하지 않은 과목 중 "전문 교양" 과목을 반환한다.
List<IncompletedCoursesDto> professionalNonMajor = gonghakRepository.findUserCoursesByMajorByGonghakCoursesWithoutCompleteCourses(
List<IncompletedCoursesDto> professionalNonMajor = gonghakRepository.findUserIncompletedCourses(
CourseCategoryConst.전문교양, userDomain.getStudentId(), userDomain.getMajorsDomain()
);

// 수강하지 않은 과목 중 "전공" 과목을 반환한다.
List<IncompletedCoursesDto> major = gonghakRepository.findUserCoursesByMajorByGonghakCoursesWithoutCompleteCourses(
List<IncompletedCoursesDto> major = gonghakRepository.findUserIncompletedCourses(
CourseCategoryConst.전공, userDomain.getStudentId(), userDomain.getMajorsDomain()
);

// 수강하지 않은 과목 중 "MSC" 과목을 반환한다.
List<IncompletedCoursesDto> msc = gonghakRepository.findUserCoursesByMajorByGonghakCoursesWithoutCompleteCourses(
List<IncompletedCoursesDto> msc = gonghakRepository.findUserIncompletedCourses(
CourseCategoryConst.MSC, userDomain.getStudentId(), userDomain.getMajorsDomain()
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.example.gimmegonghakauth.Service.GonghakCalculateServiceTest.CalculateTestConfig;
import com.example.gimmegonghakauth.constant.AbeekTypeConst;
import com.example.gimmegonghakauth.dao.AbeekDao;
import com.example.gimmegonghakauth.dao.GonghakCorusesDao;
import com.example.gimmegonghakauth.dao.GonghakCoursesDao;
import com.example.gimmegonghakauth.dao.GonghakDao;
import com.example.gimmegonghakauth.dao.GonghakRepository;
import com.example.gimmegonghakauth.domain.MajorsDomain;
Expand Down Expand Up @@ -51,11 +51,11 @@ class GonghakCalculateServiceTest {
@RequiredArgsConstructor
static class CalculateTestConfig{
private final AbeekDao abeekDao;
private final GonghakCorusesDao gonghakCorusesDao;
private final GonghakCoursesDao gonghakCoursesDao;

@Bean
public GonghakRepository gonghakRepository(){
return new GonghakDao(abeekDao,gonghakCorusesDao);
return new GonghakDao(abeekDao, gonghakCoursesDao);
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void setInit(){
@Test
@DisplayName("dao 메서드 상태 출력")
void displayDaoMethod(){
List<IncompletedCoursesDto> withoutCompleteCourses = gonghakRepository.findUserCoursesByMajorByGonghakCoursesWithoutCompleteCourses(
List<IncompletedCoursesDto> withoutCompleteCourses = gonghakRepository.findUserIncompletedCourses(
CourseCategoryConst.전공, COM_TEST_STUDENT_ID, COM_TEST_MAJORDOMAIN
);

Expand All @@ -64,7 +64,7 @@ void displayDaoMethod(){
}
);

List<GonghakCoursesByMajorDto> withCompletedCourses = gonghakRepository.findUserCoursesByMajorByGonghakCoursesWithCompletedCourses(
List<GonghakCoursesByMajorDto> withCompletedCourses = gonghakRepository.findUserCompletedCourses(
COM_TEST_STUDENT_ID, COM_TEST_MAJORDOMAIN
);

Expand All @@ -89,7 +89,7 @@ void findStandardKeySetTest() {
@Test
@DisplayName("findUserCoursesByMajorByGonghakCoursesWithCompletedCourses 테스트 ")
void findUserCoursesByMajorByGonghakCoursesWithCompletedCoursesTest() {
List<GonghakCoursesByMajorDto> userDataForCalculate = gonghakRepository.findUserCoursesByMajorByGonghakCoursesWithCompletedCourses(
List<GonghakCoursesByMajorDto> userDataForCalculate = gonghakRepository.findUserCompletedCourses(
COM_TEST_STUDENT_ID, COM_TEST_MAJORDOMAIN);

log.info("userDataForCalculate size = {}",userDataForCalculate.size());
Expand Down Expand Up @@ -122,7 +122,7 @@ void findUserCoursesByMajorByGonghakCoursesWithoutCompleteCoursesTest(){

Arrays.stream(CourseCategoryConst.values()).forEach(
courseCategory -> {
List<IncompletedCoursesDto> testCourses = gonghakRepository.findUserCoursesByMajorByGonghakCoursesWithoutCompleteCourses(
List<IncompletedCoursesDto> testCourses = gonghakRepository.findUserIncompletedCourses(
CourseCategoryConst.전공,
COM_TEST_STUDENT_ID,
COM_TEST_MAJORDOMAIN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import com.example.gimmegonghakauth.constant.AbeekTypeConst;
import com.example.gimmegonghakauth.dao.AbeekDao;
import com.example.gimmegonghakauth.dao.GonghakCorusesDao;
import com.example.gimmegonghakauth.dao.GonghakCoursesDao;
import com.example.gimmegonghakauth.dao.GonghakDao;
import com.example.gimmegonghakauth.dao.GonghakRepository;
import com.example.gimmegonghakauth.dao.MajorsDao;
Expand Down Expand Up @@ -39,11 +39,11 @@ public class DomainTest {
@RequiredArgsConstructor
public static class DomainTestConfig {
private final AbeekDao abeekDao;
private final GonghakCorusesDao gonghakCorusesDao;
private final GonghakCoursesDao gonghakCoursesDao;

@Bean
public GonghakRepository gonghakRepository(){
return new GonghakDao(abeekDao,gonghakCorusesDao);
return new GonghakDao(abeekDao, gonghakCoursesDao);
}
}

Expand Down