feat(todo): QueryDSL로 할 일 단건 조회 구현#8
Merged
Merged
Conversation
- QueryDSL 의존성 및 JPAQueryFactory 설정 추가 - TodoRepository 커스텀 구현체 추가 - findByIdWithUser를 QueryDSL fetchJoin 기반으로 전환 - 할 일 단건 조회 시 User 연관관계를 함께 조회하도록 수정
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
작업 내용
findByIdWithUser를 QueryDSL 기반 구현으로 변경했습니다.JPAQueryFactory설정을 추가했습니다.TodoRepositoryCustom,TodoRepositoryImpl을 추가하여 커스텀 Repository 구조로 분리했습니다.User연관관계를fetchJoin으로 함께 조회하도록 구현했습니다.todo.getUser()접근 시 추가 조회 쿼리가 발생하지 않도록 개선했습니다.변경 파일
build.gradlePersistenceConfigJPAQueryFactoryBean 등록TodoRepositoryTodoRepositoryCustom상속 추가findByIdWithUser제거TodoRepositoryCustomfindByIdWithUser커스텀 메서드 선언TodoRepositoryImplfindByIdWithUser구현leftJoin(todo.user).fetchJoin()으로 User 연관관계 함께 조회TodoRepositoryTestPersistenceConfigimport주요 변경 내용
기존 JPQL 기반 조회를 제거했습니다.
QueryDSL 커스텀 구현으로 변경했습니다.
테스트 방법
Repository 테스트를 통해
findByIdWithUser가 Todo와 User를 함께 조회하는지 확인했습니다.테스트에서 확인한 내용은 다음과 같습니다.
User와Todo를 저장합니다.Todo의 id로findByIdWithUser를 호출합니다.Todo에서User정보에 접근했을 때 정상적으로 값이 조회되는지 확인합니다.해결한 문제
기존 JPQL 조회 방식은 과제 요구사항인 QueryDSL 전환 대상이었습니다.
이번 수정으로
findByIdWithUser를 QueryDSL로 전환했고,fetchJoin을 사용하여 할 일 단건 조회 시 필요한 작성자 정보를 함께 조회하도록 했습니다.고민한 부분
todoRepository.findByIdWithUser(todoId)를 호출하도록 유지하여 변경 범위를 줄였습니다.Todo.user는 LAZY 연관관계이므로 단건 조회 응답 생성 시 추가 쿼리가 발생하지 않도록fetchJoin을 적용했습니다.@DataJpaTest에서는 일반 설정 Bean이 자동으로 포함되지 않을 수 있어, 테스트에서PersistenceConfig를 import하여JPAQueryFactoryBean을 사용할 수 있도록 했습니다.