I\'m currently building a REST API in which I want clients to easily filter on most properties of a specific entity. Using QueryDSL in combination with Spring Data REST (an
This is what I used for a generic binding for all date fields, always expecting 2 values, from and to.
bindings.bind(Date.class).all((final DateTimePath path, final Collection extends Date> values) -> {
final List extends Date> dates = new ArrayList<>(values);
Collections.sort(dates);
if (dates.size() == 2) {
return path.between(dates.get(0), dates.get(1));
}
throw new IllegalArgumentException("2 date params(from & to) expected for:" + path + " found:" + values);
});
This is for datetime fields. For a date field, when getting a single parameter, path.eq() makes sense I guess.