-
-
Notifications
You must be signed in to change notification settings - Fork 877
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(doctrine): boolean filter like laravel filters
- Loading branch information
1 parent
1ac0c3d
commit 18c63e9
Showing
13 changed files
with
456 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,12 @@ | |
namespace ApiPlatform\Doctrine\Odm\Filter; | ||
|
||
use ApiPlatform\Doctrine\Common\Filter\BooleanFilterTrait; | ||
use ApiPlatform\Metadata\JsonSchemaFilterInterface; | ||
use ApiPlatform\Metadata\OpenApiParameterFilterInterface; | ||
use ApiPlatform\Metadata\Operation; | ||
use ApiPlatform\Metadata\Parameter; | ||
use ApiPlatform\Metadata\QueryParameter; | ||
use ApiPlatform\OpenApi\Model\Parameter as OpenApiParameter; | ||
use Doctrine\ODM\MongoDB\Aggregation\Builder; | ||
use Doctrine\ODM\MongoDB\Types\Type as MongoDbType; | ||
|
||
|
@@ -104,7 +109,7 @@ | |
* @author Teoh Han Hui <[email protected]> | ||
* @author Alan Poulain <[email protected]> | ||
*/ | ||
final class BooleanFilter extends AbstractFilter | ||
final class BooleanFilter extends AbstractFilter implements OpenApiParameterFilterInterface, JsonSchemaFilterInterface | ||
{ | ||
use BooleanFilterTrait; | ||
|
||
|
@@ -139,4 +144,27 @@ protected function filterProperty(string $property, $value, Builder $aggregation | |
|
||
$aggregationBuilder->match()->field($matchField)->equals($value); | ||
} | ||
|
||
/** | ||
* @return array<string, string> | ||
*/ | ||
public function getSchema(Parameter $parameter): array | ||
{ | ||
return $parameter->getSchema() ?? ['type' => 'boolean']; | ||
} | ||
|
||
public function getOpenApiParameters(Parameter $parameter): OpenApiParameter|array|null | ||
{ | ||
$in = $parameter instanceof QueryParameter ? 'query' : 'header'; | ||
$key = $parameter->getKey(); | ||
|
||
return [ | ||
new OpenApiParameter( | ||
name: $key, | ||
in: $in, | ||
required: false, | ||
schema: ['type' => 'boolean'], | ||
), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,12 @@ | |
|
||
use ApiPlatform\Doctrine\Common\Filter\BooleanFilterTrait; | ||
use ApiPlatform\Doctrine\Orm\Util\QueryNameGeneratorInterface; | ||
use ApiPlatform\Metadata\JsonSchemaFilterInterface; | ||
use ApiPlatform\Metadata\OpenApiParameterFilterInterface; | ||
use ApiPlatform\Metadata\Operation; | ||
use ApiPlatform\Metadata\Parameter; | ||
use ApiPlatform\Metadata\QueryParameter; | ||
use ApiPlatform\OpenApi\Model\Parameter as OpenApiParameter; | ||
use Doctrine\DBAL\Types\Types; | ||
use Doctrine\ORM\Query\Expr\Join; | ||
use Doctrine\ORM\QueryBuilder; | ||
|
@@ -106,7 +111,7 @@ | |
* @author Amrouche Hamza <[email protected]> | ||
* @author Teoh Han Hui <[email protected]> | ||
*/ | ||
final class BooleanFilter extends AbstractFilter | ||
final class BooleanFilter extends AbstractFilter implements OpenApiParameterFilterInterface, JsonSchemaFilterInterface | ||
{ | ||
use BooleanFilterTrait; | ||
|
||
|
@@ -145,4 +150,27 @@ protected function filterProperty(string $property, $value, QueryBuilder $queryB | |
->andWhere(\sprintf('%s.%s = :%s', $alias, $field, $valueParameter)) | ||
->setParameter($valueParameter, $value); | ||
} | ||
|
||
/** | ||
* @return array<string, string> | ||
*/ | ||
public function getSchema(Parameter $parameter): array | ||
{ | ||
return $parameter->getSchema() ?? ['type' => 'boolean']; | ||
} | ||
|
||
public function getOpenApiParameters(Parameter $parameter): OpenApiParameter|array|null | ||
{ | ||
$in = $parameter instanceof QueryParameter ? 'query' : 'header'; | ||
$key = $parameter->getKey(); | ||
|
||
return [ | ||
new OpenApiParameter( | ||
name: $key, | ||
in: $in, | ||
required: false, | ||
schema: ['type' => 'boolean'], | ||
), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.