Skip to content

Commit

Permalink
Feature/Add IS NULL and IS NOT NULL filters (#35)
Browse files Browse the repository at this point in the history
Co-authored-by: Dmytro Zasiadko <dmytro@2amigos.us>
  • Loading branch information
segoddnja and segoddnja authored Sep 27, 2021
1 parent 3260731 commit 3c8058c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
22 changes: 22 additions & 0 deletions src/Application/CriteriaBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,28 @@ public function filterLike(string $field, $value): self
return $this;
}

/**
* Adds new filter for IS NULL operator
* @param string $field
* @return $this
*/
public function filterIsNull(string $field): self
{
$this->filter($field, Filter::IS_NULL, null);
return $this;
}

/**
* Adds new filter for IS NOT NULL operator
* @param string $field
* @return $this
*/
public function filterIsNotNull(string $field): self
{
$this->filter($field, Filter::IS_NOT_NULL, null);
return $this;
}

/**
* Sets the order by field parameter.
*
Expand Down
2 changes: 2 additions & 0 deletions src/Domain/Criteria/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ final class Filter implements ValueObject
public const IN = 'in';
public const NOT_IN = 'notIn';
public const LIKE = 'like';
public const IS_NULL = 'isNull';
public const IS_NOT_NULL = 'isNotNull';

/**
* The filter field name.
Expand Down
6 changes: 4 additions & 2 deletions tests/Application/CriteriaBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ public function testShouldAddFiltersToCriteria(): void
->filterIn('address.state', ['FL', 'NY'])
->filterNotIn('address.zip', [10, 11, 12, 13])
->filterLike('job.title', '%Gangster%')
->filterIsNull('lastActivityDate')
->filterIsNotNull('lastLoginDate')
->build();

$this->assertCount(9, $criteria->filters());
$this->assertCount(11, $criteria->filters());
}

public function testShouldSetOrderByAndOrderType(): void
Expand All @@ -60,4 +62,4 @@ public function testShouldSetPageLimitAndPageOffset(): void
$this->assertEquals(50, $criteria->pageLimit());
$this->assertEquals(100, $criteria->pageOffset());
}
}
}

0 comments on commit 3c8058c

Please sign in to comment.