Skip to content

Commit

Permalink
feat(null): adding operators ISNULL and NOTNULL
Browse files Browse the repository at this point in the history
  • Loading branch information
Yves-MENGELLE-OF committed Mar 20, 2024
1 parent 4fbc96e commit cc46320
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,20 @@ class CS implements FilterOperation {
@ValidatedBy(StringValidator.class)
class CD implements FilterOperation {
}

/**
* Not null.
*
* @since 1.3.3
*/
class ISNULL implements FilterOperation {

Check warning on line 37 in querydsl-postgrest/src/main/java/fr/ouestfrance/querydsl/postgrest/PostgrestFilterOperation.java

View check run for this annotation

Codecov / codecov/patch

querydsl-postgrest/src/main/java/fr/ouestfrance/querydsl/postgrest/PostgrestFilterOperation.java#L37

Added line #L37 was not covered by tests
}

/**
* Is null.
*
* @since 1.3.3
*/
class NOTNULL implements FilterOperation {

Check warning on line 45 in querydsl-postgrest/src/main/java/fr/ouestfrance/querydsl/postgrest/PostgrestFilterOperation.java

View check run for this annotation

Codecov / codecov/patch

querydsl-postgrest/src/main/java/fr/ouestfrance/querydsl/postgrest/PostgrestFilterOperation.java#L45

Added line #L45 was not covered by tests
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package fr.ouestfrance.querydsl.postgrest.mappers;

import fr.ouestfrance.querydsl.FilterOperation;
import fr.ouestfrance.querydsl.postgrest.PostgrestFilterOperation;
import fr.ouestfrance.querydsl.postgrest.model.Filter;
import fr.ouestfrance.querydsl.postgrest.model.impl.QueryFilter;

public class IsNullMapper extends AbstractMapper {

@Override
public Filter getFilter(String field, Object value) {
return QueryFilter.of(field, Operators.IS, null);
}


@Override
public Class<? extends FilterOperation> operation() {
return PostgrestFilterOperation.ISNULL.class;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package fr.ouestfrance.querydsl.postgrest.mappers;

import fr.ouestfrance.querydsl.FilterOperation;
import fr.ouestfrance.querydsl.postgrest.PostgrestFilterOperation;
import fr.ouestfrance.querydsl.postgrest.model.Filter;
import fr.ouestfrance.querydsl.postgrest.model.impl.QueryFilter;

public class NotNullMapper extends AbstractMapper {

@Override
public Filter getFilter(String field, Object value) {
return QueryFilter.of(field, Operators.IS_NOT, null);
}


@Override
public Class<? extends FilterOperation> operation() {
return PostgrestFilterOperation.NOTNULL.class;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ public final class Operators {
* is operation
*/
public static final String IS = "is";
/**
* is not operation
*/
public static final String IS_NOT = "not.is";
/**
* Contains operation for JSON/Range datatype
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package fr.ouestfrance.querydsl.postgrest.mappers;

import fr.ouestfrance.querydsl.model.SimpleFilter;
import fr.ouestfrance.querydsl.postgrest.PostgrestFilterOperation;
import fr.ouestfrance.querydsl.postgrest.builders.QueryFilterVisitor;
import fr.ouestfrance.querydsl.postgrest.model.Filter;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertNotNull;

class IsNullMapperTest {

@Test
void shouldMapIsNull() {
IsNullMapper mapper = new IsNullMapper();
assertNotNull(mapper.operation());
Filter result = mapper.map(new SimpleFilter("name", PostgrestFilterOperation.ISNULL.class, false, null), "John");
assertNotNull(result);
QueryFilterVisitor visitor = new QueryFilterVisitor();
result.accept(visitor);
assertNotNull(visitor.getValue());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package fr.ouestfrance.querydsl.postgrest.mappers;

import fr.ouestfrance.querydsl.model.SimpleFilter;
import fr.ouestfrance.querydsl.postgrest.PostgrestFilterOperation;
import fr.ouestfrance.querydsl.postgrest.builders.QueryFilterVisitor;
import fr.ouestfrance.querydsl.postgrest.model.Filter;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertNotNull;

class NotNullMapperTest {

@Test
void shouldMapNotNull() {
NotNullMapper mapper = new NotNullMapper();
assertNotNull(mapper.operation());
Filter result = mapper.map(new SimpleFilter("name", PostgrestFilterOperation.NOTNULL.class, false, null), "John");
assertNotNull(result);
QueryFilterVisitor visitor = new QueryFilterVisitor();
result.accept(visitor);
assertNotNull(visitor.getValue());
}
}

0 comments on commit cc46320

Please sign in to comment.