27 lines
812 B
Java
27 lines
812 B
Java
package com.krylov.refound.util;
|
|
|
|
import com.krylov.refound.entity.Post;
|
|
import org.springframework.data.jpa.domain.Specification;
|
|
|
|
public class PostSpecification {
|
|
public static Specification<Post> hasSearch(String search) {
|
|
return (root, query, cb) -> {
|
|
if (search == null || search.isBlank()) {
|
|
return cb.conjunction();
|
|
}
|
|
String pattern = "%" + search.toLowerCase() + "%";
|
|
return cb.or(
|
|
cb.like(cb.lower(root.get("title")), pattern),
|
|
cb.like(cb.lower(root.get("description")), pattern)
|
|
);
|
|
};
|
|
}
|
|
|
|
public static Specification<Post> hasType(String type) {
|
|
return (root, query, cb) -> {
|
|
if (type == null || type.isBlank()) return cb.conjunction();
|
|
return cb.equal(cb.lower(root.get("type")), type.toLowerCase());
|
|
};
|
|
}
|
|
}
|