...
 
Commits (2)
......@@ -9,9 +9,13 @@
namespace AboutGoods\Antar\Models;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
use Symfony\Component\Serializer\Serializer;
use AboutGoods\Antar\Tools\FilterEncoder;
class Filter
{
/**
/**;
* @var string
*/
private $uid;
......@@ -186,7 +190,7 @@ class Filter
*/
public function getUserPseudoId()
{
return $this->externalId;
return $this->userPseudoId;
}
/**
......@@ -194,7 +198,7 @@ class Filter
*/
public function setUserPseudoId($userPseudoId): void
{
$this->externalId = $externalId;
$this->userPseudoId = $userPseudoId;
}
/**
......@@ -218,17 +222,13 @@ class Filter
*/
public function toQueryParameters()
{
$queryParameters = [];
$serializer = new Serializer([new ObjectNormalizer()], [new FilterEncoder()]);
$data = $serializer->serialize($this, "antar-filter");
$filters = get_object_vars($this);
if(count($filters) === 0) {
if($data === ""){
return [];
}
foreach ($filters as $name => $value) {
if ($value !== null) {
$queryParameters[] = $name.":".$value;
}
}
return [ "filter" => implode("," , $queryParameters)];
return [ "filter" => $data ];
}
}
......@@ -8,7 +8,7 @@ use Symfony\Component\Serializer\Encoder\DecoderInterface;
use Symfony\Component\Serializer\Encoder\EncoderInterface;
use Symfony\Component\Serializer\Exception\UnexpectedValueException;
class FilterCoder implements EncoderInterface, DecoderInterface
class FilterEncoder implements EncoderInterface, DecoderInterface
{
/**
......@@ -69,7 +69,9 @@ class FilterCoder implements EncoderInterface, DecoderInterface
$queryParameters = [];
$filters = get_object_vars($this);
if(count($filters) === 0) {
if(count(array_filter($filters, function ($item) {
return !is_null($item);
})) === 0) {
return "";
}
foreach ($filters as $name => $value) {
......
......@@ -49,7 +49,7 @@ class QueryParameters
}
$serializer = new Serializer([new ObjectNormalizer()], [new FilterCoder()]);
$serializer = new Serializer([new ObjectNormalizer()], [new FilterEncoder()]);
$data = $serializer->deserialize($filterString, Filter::class, "antar-filter");
$this->filter = $data;
......