Skip to content

Commit

Permalink
Feature: Added Inventory Filter
Browse files Browse the repository at this point in the history
  • Loading branch information
ishika28 committed Aug 9, 2020
1 parent 54fd1bc commit 1855883
Showing 1 changed file with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
package com.pemits.webcare.api.inventory.repository.spec;

import com.pemits.webcare.api.inventory.entity.Inventory;
import org.springframework.data.jpa.domain.Specification;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

import org.springframework.data.jpa.domain.Specification;

import com.pemits.webcare.api.inventory.entity.Inventory;

/**
* @Author Mohammad Hussain
* created on 6/29/2020
*/
public class InventorySpec implements Specification<Inventory> {

private static final String FILTER_BY_NAME = "name";

private final String property;
private final String value;

Expand All @@ -25,7 +28,12 @@ public InventorySpec(String property, String value) {

@Override
public Predicate toPredicate(Root<Inventory> root, CriteriaQuery<?> query,
CriteriaBuilder criteriaBuilder) {
return null;
CriteriaBuilder criteriaBuilder) {
switch (property) {
case FILTER_BY_NAME:
return criteriaBuilder.like(root.get(FILTER_BY_NAME), "%" + value + "%");
default:
return null;
}
}
}

0 comments on commit 1855883

Please sign in to comment.