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: add between operation #6

Merged
merged 1 commit into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/main/java/fr/ouestfrance/querydsl/FilterOperation.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -80,4 +77,12 @@
@ValidatedBy(BooleanValidator.class)
class ISNULL implements FilterOperation {
}


/**
* Between Operation
*/
@ValidatedBy(HasRangeValidator.class)
class BETWEEN implements FilterOperation {

Check warning on line 86 in src/main/java/fr/ouestfrance/querydsl/FilterOperation.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/fr/ouestfrance/querydsl/FilterOperation.java#L86

Added line #L86 was not covered by tests
}
}
37 changes: 37 additions & 0 deletions src/main/java/fr/ouestfrance/querydsl/service/ext/HasRange.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package fr.ouestfrance.querydsl.service.ext;

/**
* Interface for range values
*
* @param <T> the type of the range (like localDate, String, integers, ...)
*/
public interface HasRange<T> {

/**
* 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();
}
Original file line number Diff line number Diff line change
@@ -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

Check warning on line 10 in src/main/java/fr/ouestfrance/querydsl/service/validators/impl/HasRangeValidator.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/fr/ouestfrance/querydsl/service/validators/impl/HasRangeValidator.java#L10

Added line #L10 was not covered by tests
public class HasRangeValidator implements FilterFieldValidator {
@Override
public boolean validate(Class<?> clazz) {
return HasRange.class.isAssignableFrom(clazz);

Check warning on line 14 in src/main/java/fr/ouestfrance/querydsl/service/validators/impl/HasRangeValidator.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/fr/ouestfrance/querydsl/service/validators/impl/HasRangeValidator.java#L14

Added line #L14 was not covered by tests
}

@Override
public String message() {
return "should be applied to HasRange";

Check warning on line 19 in src/main/java/fr/ouestfrance/querydsl/service/validators/impl/HasRangeValidator.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/fr/ouestfrance/querydsl/service/validators/impl/HasRangeValidator.java#L19

Added line #L19 was not covered by tests
}
}
Loading