diff --git a/src/main/java/fr/ouestfrance/querydsl/FilterOperation.java b/src/main/java/fr/ouestfrance/querydsl/FilterOperation.java index d6c7c43..538b788 100644 --- a/src/main/java/fr/ouestfrance/querydsl/FilterOperation.java +++ b/src/main/java/fr/ouestfrance/querydsl/FilterOperation.java @@ -1,10 +1,7 @@ package fr.ouestfrance.querydsl; import fr.ouestfrance.querydsl.service.validators.ValidatedBy; -import fr.ouestfrance.querydsl.service.validators.impl.BooleanValidator; -import fr.ouestfrance.querydsl.service.validators.impl.CollectionValidator; -import fr.ouestfrance.querydsl.service.validators.impl.ComparableValidator; -import fr.ouestfrance.querydsl.service.validators.impl.StringValidator; +import fr.ouestfrance.querydsl.service.validators.impl.*; /** * Operations allowed by querydsl @@ -80,4 +77,12 @@ class NOTIN implements FilterOperation { @ValidatedBy(BooleanValidator.class) class ISNULL implements FilterOperation { } + + + /** + * Between Operation + */ + @ValidatedBy(HasRangeValidator.class) + class BETWEEN implements FilterOperation { + } } diff --git a/src/main/java/fr/ouestfrance/querydsl/service/ext/HasRange.java b/src/main/java/fr/ouestfrance/querydsl/service/ext/HasRange.java new file mode 100644 index 0000000..e92d031 --- /dev/null +++ b/src/main/java/fr/ouestfrance/querydsl/service/ext/HasRange.java @@ -0,0 +1,37 @@ +package fr.ouestfrance.querydsl.service.ext; + +/** + * Interface for range values + * + * @param the type of the range (like localDate, String, integers, ...) + */ +public interface HasRange { + + /** + * Get the lower bound of the range + * + * @return the lower bound or null if unbounded + */ + T getLower(); + + /** + * Get the upper bound of the range + * + * @return the upper bound or null if unbounded + */ + T getUpper(); + + /** + * Check if the lower bound is inclusive + * + * @return true if the lower bound is inclusive + */ + boolean isLowerInclusive(); + + /** + * Check if the upper bound is inclusive + * + * @return true if the upper bound is inclusive + */ + boolean isUpperInclusive(); +} diff --git a/src/main/java/fr/ouestfrance/querydsl/service/validators/impl/HasRangeValidator.java b/src/main/java/fr/ouestfrance/querydsl/service/validators/impl/HasRangeValidator.java new file mode 100644 index 0000000..041490f --- /dev/null +++ b/src/main/java/fr/ouestfrance/querydsl/service/validators/impl/HasRangeValidator.java @@ -0,0 +1,21 @@ +package fr.ouestfrance.querydsl.service.validators.impl; + +import fr.ouestfrance.querydsl.service.ext.HasRange; +import fr.ouestfrance.querydsl.service.validators.FilterFieldValidator; +import lombok.NoArgsConstructor; + +/** + * Validator that handle filter on HasRange + */ +@NoArgsConstructor +public class HasRangeValidator implements FilterFieldValidator { + @Override + public boolean validate(Class clazz) { + return HasRange.class.isAssignableFrom(clazz); + } + + @Override + public String message() { + return "should be applied to HasRange"; + } +}