-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 용어집 내 용어 조회 시 용어 이름으로 정렬 적용 #36
- Loading branch information
1 parent
775046a
commit 7400dff
Showing
7 changed files
with
76 additions
and
19 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
api/src/main/java/vook/server/api/app/TermSearchRepository.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package vook.server.api.app; | ||
|
||
import com.querydsl.jpa.impl.JPAQuery; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.stereotype.Repository; | ||
import vook.server.api.helper.QuerydslHelper; | ||
import vook.server.api.model.QTerm; | ||
import vook.server.api.model.Term; | ||
|
||
import java.util.List; | ||
|
||
@Repository | ||
@RequiredArgsConstructor | ||
public class TermSearchRepository { | ||
|
||
private final JPAQueryFactory queryFactory; | ||
|
||
public List<Term> search(String glossaryUid, Pageable pageable) { | ||
QTerm term = QTerm.term1; | ||
|
||
// fetch join과 pagination을 같이 하면, | ||
// HHH90003004: firstResult/maxResults specified with collection fetch; applying in memory | ||
// 에러가 발생, 이를 피하기 위해 pagination이 포함된 쿼리를 서브 쿼리로 하여 수행 | ||
JPAQuery<Long> termIdQuery = queryFactory | ||
.select(term.id) | ||
.from(term) | ||
.where(term.glossary.uid.eq(glossaryUid)) | ||
.offset(pageable.getOffset()) | ||
.limit(pageable.getPageSize()); | ||
|
||
QuerydslHelper | ||
.toOrderSpecifiers(term, pageable) | ||
.forEach(termIdQuery::orderBy); | ||
|
||
JPAQuery<Term> dataQuery = queryFactory | ||
.selectFrom(term) | ||
.leftJoin(term.synonyms).fetchJoin() | ||
.where(term.id.in(termIdQuery)); | ||
|
||
// In 절에 들어간 입력순대로 출력되지 않음으로 정렬 조건을 다시 한번 설정 | ||
QuerydslHelper | ||
.toOrderSpecifiers(term, pageable) | ||
.forEach(dataQuery::orderBy); | ||
|
||
return dataQuery.fetch(); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,20 @@ | ||
package vook.server.api.app; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.stereotype.Service; | ||
import vook.server.api.model.Glossary; | ||
import vook.server.api.model.Term; | ||
import vook.server.api.model.TermRepository; | ||
|
||
import java.util.List; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class TermService { | ||
|
||
private final TermRepository repository; | ||
private final TermSearchRepository searchRepository; | ||
|
||
public List<Term> findAllBy(Glossary glossary) { | ||
return repository.findAllByGlossary(glossary); | ||
public List<Term> findAllBy(Glossary glossary, Pageable pageable) { | ||
return searchRepository.search(glossary.getUid(), pageable); | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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