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(null): adding operators ISNULL and NOTNULL #32

Merged
merged 2 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 3 additions & 2 deletions querydsl-postgrest/pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>fr.ouestfrance.querydsl</groupId>
Expand All @@ -13,7 +14,7 @@
<dependency>
<groupId>fr.ouestfrance.querydsl</groupId>
<artifactId>querydsl</artifactId>
<version>1.2.0</version>
<version>1.3.0-SNAPSHOT</version>
arnaud-thorel-of marked this conversation as resolved.
Show resolved Hide resolved
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package fr.ouestfrance.querydsl.postgrest.mappers;

import fr.ouestfrance.querydsl.FilterOperation;
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, Boolean.TRUE.equals(value) ? Operators.IS : Operators.IS_NOT, null);
}

@Override
public Class<? extends FilterOperation> operation() {
return FilterOperation.ISNULL.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,30 @@
package fr.ouestfrance.querydsl.postgrest.mappers;

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

import java.util.stream.Stream;

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

class IsNullMapperTest {

@Test
void shouldMapIsNull() {
IsNullMapper mapper = new IsNullMapper();
assertNotNull(mapper.operation());
Stream.of(Boolean.TRUE, Boolean.FALSE).forEach(value -> {
Filter result = mapper.map(new SimpleFilter("name", FilterOperation.ISNULL.class, false, null), value);
assertNotNull(result);
QueryFilterVisitor visitor = new QueryFilterVisitor();
result.accept(visitor);
assertNotNull(visitor.getValue());
assertEquals(Boolean.TRUE.equals(value) ? "is.null" : "not.is.null", visitor.getValue());
});

}
}
Loading