Skip to content

Commit

Permalink
refactor: 전공 실습 과목 조회 로직 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
5uhwann committed Nov 20, 2024
1 parent 1777f51 commit 1c85415
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@

public interface MajorLectureRepository extends JpaRepository<MajorLectureJpaEntity, Long> {

@Query("select m from MajorLectureJpaEntity m join fetch m.lectureJpaEntity where m.major = :major")
@Query("select m from MajorLectureJpaEntity m join fetch m.lectureJpaEntity where m.major = :major or m.major = '실습'")
List<MajorLectureJpaEntity> findAllByMajor(@Param("major") String major);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,40 +12,44 @@

class MajorLectureRepositoryTest extends PersistenceTestSupport {

@Autowired
private LectureRepository lectureRepository;
@Autowired
private MajorLectureRepository majorLectureRepository;


@DisplayName("유저의 전공에 해당하는 전공 과목을 조회한다.")
@Test
void findAllByMajor() {
//given
LectureJpaEntity lectureJpaEntity = LectureJpaEntity.builder()
.id("TEST")
.build();
lectureRepository.save(lectureJpaEntity);

MajorLectureJpaEntity majorLectureJpaEntityA = MajorLectureJpaEntity.builder()
.lectureJpaEntity(lectureJpaEntity)
.major("응용소프트웨어")
.build();
MajorLectureJpaEntity majorLectureJpaEntityB = MajorLectureJpaEntity.builder()
.lectureJpaEntity(lectureJpaEntity)
.major("데이터테크놀로지")
.build();
majorLectureRepository.saveAll(List.of(majorLectureJpaEntityA, majorLectureJpaEntityB));

String major = "응용소프트웨어";

//when
List<MajorLectureJpaEntity> majorLectures = majorLectureRepository.findAllByMajor(major);

//then
assertThat(majorLectures).hasSize(1)
.extracting("major")
.contains(major);
}
@Autowired
private LectureRepository lectureRepository;
@Autowired
private MajorLectureRepository majorLectureRepository;


@DisplayName("유저의 전공에 해당하는 전공 과목을 조회한다.")
@Test
void findAllByMajor() {
//given
LectureJpaEntity lectureJpaEntity = LectureJpaEntity.builder()
.id("TEST")
.build();
lectureRepository.save(lectureJpaEntity);

MajorLectureJpaEntity majorLectureJpaEntityA = MajorLectureJpaEntity.builder()
.lectureJpaEntity(lectureJpaEntity)
.major("응용소프트웨어")
.build();
MajorLectureJpaEntity majorLectureJpaEntityB = MajorLectureJpaEntity.builder()
.lectureJpaEntity(lectureJpaEntity)
.major("데이터테크놀로지")
.build();
MajorLectureJpaEntity majorLectureJpaEntityC = MajorLectureJpaEntity.builder()
.lectureJpaEntity(lectureJpaEntity)
.major("실습")
.build();
majorLectureRepository.saveAll(List.of(majorLectureJpaEntityA, majorLectureJpaEntityB, majorLectureJpaEntityC));

String major = "응용소프트웨어";

//when
List<MajorLectureJpaEntity> majorLectures = majorLectureRepository.findAllByMajor(major);

//then
assertThat(majorLectures).hasSize(2)
.extracting("major")
.containsExactlyInAnyOrder(major, "실습");
}

}

0 comments on commit 1c85415

Please sign in to comment.