두려워하던 탐색 페이지 필터링 및 정렬 구현이 끝났다. (+검색 기능도 추가)
2기 분들과 우리 3기 동기들이 Specification 을 사용한 것을 보고 구현해봤는데 주말부터 오늘까지 매달려서 테스트 코드 작성까지 완료했다.
구현 중 살짝 어려움을 겪었던 카테고리 파트. 정확히 이해를 못하다가 sql 문법과 같은 like, and, between 이라는 것을 깨달았다.
Specification<Content> spec = (root, query, criteriaBuilder) -> null;
if (platform != null) {
spec = spec.and(ContentSpecification.likePlatform(platform));
}
if (type != null) {
spec = spec.and(ContentSpecification.equalType(type));
}
if (genreId != null) {
spec = spec.and(ContentSpecification.likeTmdbGenreId(genreId));
}
if (releaseDate != null) {
spec = spec.and(ContentSpecification.betweenReleaseDate(releaseDate));
}
if (searchTitle != null) {
spec = spec.and(ContentSpecification.likeKorTitle(searchTitle))
.or(ContentSpecification.likeEngTitle(searchTitle));
}
그리고 db 에 밀어넣은 데이터중에 외부 api 로 호출한 TMDB 데이터의 개봉연도는 String 형태로 저장해놓은 탓에 정렬하기가 어려웠었는데, between 을 위해 Integer 형태로 변형해주었다.
'TIL' 카테고리의 다른 글
Plmography 프로젝트 작업 로그 #42 - 배열로 된 데이터 서버로 보내기 (23.02.01 TIL) (0) | 2023.02.01 |
---|---|
Plmography 프로젝트 작업 로그 #41 - JPQL 에서 exists 문법 사용하기 (23.01.31 TIL) (0) | 2023.01.31 |
Plmography 프로젝트 작업 로그 #39 - 비즈니스 로직 테스트 코드는 확실하게! (23.01.20 TIL) (0) | 2023.01.20 |
Plmography 프로젝트 작업 로그 #38 - 상세 페이지 구현 완료 (23.01.19 TIL) (0) | 2023.01.19 |
Plmography 프로젝트 작업 로그 #37 - 컴포넌트 분리 (23.01.18 TIL) (0) | 2023.01.18 |
댓글