본문 바로가기
TIL

Plmography 프로젝트 작업 로그 #40 - 탐색 페이지 필터링 구현 (23.01.30 TIL)

by winteringg 2023. 1. 30.

두려워하던 탐색 페이지 필터링 및 정렬 구현이 끝났다. (+검색 기능도 추가)

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 형태로 변형해주었다.

댓글