From 8acd56940a0b42ad8e44efe836b20953cfe32ec0 Mon Sep 17 00:00:00 2001 From: "a.shamavov" Date: Tue, 4 Mar 2025 10:38:06 +0500 Subject: [PATCH] =?UTF-8?q?fix:=20=D0=94=D0=BE=D1=80=D0=B0=D0=B1=D0=BE?= =?UTF-8?q?=D1=82=D0=B0=D0=BD=20=D1=84=D0=B8=D0=BB=D1=8C=D1=82=D1=80=20Ran?= =?UTF-8?q?ge?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Filter/Range.php | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/Filter/Range.php b/src/Filter/Range.php index 77e4e49..af23dd9 100644 --- a/src/Filter/Range.php +++ b/src/Filter/Range.php @@ -5,16 +5,29 @@ declare(strict_types=1); namespace IQDEV\Packages\DoctrineHttpFilter\Filter; use Doctrine\ORM\QueryBuilder; +use IQDEV\Packages\DoctrineHttpFilter\Exception\FilterParameterValueIsNullException; use IQDEV\Packages\DoctrineHttpFilter\HttpFilter; final class Range extends HttpFilter { + /** @throws FilterParameterValueIsNullException */ public function addToQuery(QueryBuilder $queryBuilder): QueryBuilder { - $queryBuilder->where( - $this->getColumn() . '>= ' . $this->getHttpValue()['min'] . ' AND ' . - $this->getColumn() . ' <= ' . $this->getHttpValue()['max'], - ); + if (! isset($this->getHttpValue()['min']) && ! isset($this->getHttpValue()['max'])) { + throw new FilterParameterValueIsNullException($this->field); + } + + if (isset($this->getHttpValue()['min'])) { + $queryBuilder->where( + $this->getColumn() . '>= ' . $this->getHttpValue()['min'] + ); + } + + if (isset($this->getHttpValue()['max'])) { + $queryBuilder->andWhere( + $this->getColumn() . ' <= ' . $this->getHttpValue()['max'] + ); + } return $queryBuilder; } -- GitLab