Skip to content

Commit

Permalink
feat(isnull-operator): implement ISNULL operator
Browse files Browse the repository at this point in the history
  • Loading branch information
Yves-MENGELLE-OF committed Mar 21, 2024
1 parent 4fbc96e commit 0473dd1
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 2 deletions.
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>
</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,23 @@
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 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", FilterOperation.ISNULL.class, false, null), Boolean.TRUE);
assertNotNull(result);
QueryFilterVisitor visitor = new QueryFilterVisitor();
result.accept(visitor);
assertNotNull(visitor.getValue());
}
}

0 comments on commit 0473dd1

Please sign in to comment.