Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT] cost 11일때 10만원 이상 조회 로직 추가 - #123 #124

Merged
merged 1 commit into from
Jul 16, 2024

Conversation

rlarlgnszx
Copy link
Member

🔥Pull requests

⛳️ 작업한 브랜치

👷 작업한 내용

  • 다음 로직으로 수정
    public static Specification<Course> filterByCriteria(CourseGetAllReq courseGetAllReq) {
        return (root, query, criteriaBuilder) -> {
            List<Predicate> predicates = new ArrayList<>();
            addPredicate(predicates, criteriaBuilder, root, "city", courseGetAllReq.city(), criteriaBuilder::equal);
            addPredicate(predicates, criteriaBuilder, root, "country", courseGetAllReq.country(), criteriaBuilder::equal);
            addCostPredicate(predicates, criteriaBuilder, root, courseGetAllReq.cost());
            return criteriaBuilder.and(predicates.toArray(new Predicate[0]));
        };
    }

    private static <T> void addPredicate(List<Predicate> predicates, CriteriaBuilder criteriaBuilder, Root<?> root,
                                         String attributeName, T value,
                                         BiFunction<Path<T>, T, Predicate> predicateFunction) {
        Optional.ofNullable(value)
                .ifPresent(val -> predicates.add(
                        predicateFunction.apply(root.get(attributeName), val))
                );
    }

    private static void addCostPredicate(List<Predicate> predicates, CriteriaBuilder criteriaBuilder, Root<?> root, Integer cost) {
        if (cost != null) {
            if (cost == 11) {
                predicates.add(criteriaBuilder.greaterThan(root.get("cost"), 10));
            } else {
                predicates.add(criteriaBuilder.lessThanOrEqualTo(root.get("cost"), cost));
            }
        }
    }

🚨 참고 사항

📟 관련 이슈

Copy link
Contributor

@gardening-y gardening-y left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수고하셨습니다~!~

@rlarlgnszx rlarlgnszx merged commit d16e09c into develop Jul 16, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEAT] 코스 필터링 조회 cost < 10 추가 구현
2 participants