diff --git a/src/Wallabag/ApiBundle/Controller/ConfigRestController.php b/src/Wallabag/ApiBundle/Controller/ConfigRestController.php index 65046ff5f..134efd19d 100644 --- a/src/Wallabag/ApiBundle/Controller/ConfigRestController.php +++ b/src/Wallabag/ApiBundle/Controller/ConfigRestController.php @@ -2,6 +2,7 @@ namespace Wallabag\ApiBundle\Controller; +use JMS\Serializer\SerializationContext; use Nelmio\ApiDocBundle\Annotation\ApiDoc; use Symfony\Component\HttpFoundation\JsonResponse; @@ -18,6 +19,14 @@ class ConfigRestController extends WallabagRestController { $this->validateAuthentication(); - return $this->sendResponse($this->getUser()->getConfig()); + $json = $this->get('jms_serializer')->serialize( + $this->getUser()->getConfig(), + 'json', + SerializationContext::create()->setGroups(['config_api']) + ); + + return (new JsonResponse()) + ->setJson($json) + ->setStatusCode(JsonResponse::HTTP_OK); } } diff --git a/src/Wallabag/CoreBundle/DataFixtures/ConfigFixtures.php b/src/Wallabag/CoreBundle/DataFixtures/ConfigFixtures.php index 6dde08e81..64fe99b45 100644 --- a/src/Wallabag/CoreBundle/DataFixtures/ConfigFixtures.php +++ b/src/Wallabag/CoreBundle/DataFixtures/ConfigFixtures.php @@ -24,6 +24,7 @@ class ConfigFixtures extends Fixture implements DependentFixtureInterface $adminConfig->setPocketConsumerKey('xxxxx'); $adminConfig->setActionMarkAsRead(0); $adminConfig->setListMode(0); + $adminConfig->setListMode(0); $manager->persist($adminConfig); diff --git a/src/Wallabag/CoreBundle/Entity/Config.php b/src/Wallabag/CoreBundle/Entity/Config.php index 1bed45138..1c53de1f1 100644 --- a/src/Wallabag/CoreBundle/Entity/Config.php +++ b/src/Wallabag/CoreBundle/Entity/Config.php @@ -4,6 +4,7 @@ namespace Wallabag\CoreBundle\Entity; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\Mapping as ORM; +use JMS\Serializer\Annotation\Groups; use Symfony\Component\Validator\Constraints as Assert; use Wallabag\UserBundle\Entity\User; @@ -29,6 +30,8 @@ class Config * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") + * + * @Groups({"config_api"}) */ private $id; @@ -37,6 +40,8 @@ class Config * * @Assert\NotBlank() * @ORM\Column(name="theme", type="string", nullable=false) + * + * @Groups({"config_api"}) */ private $theme; @@ -50,6 +55,8 @@ class Config * maxMessage = "validator.item_per_page_too_high" * ) * @ORM\Column(name="items_per_page", type="integer", nullable=false) + * + * @Groups({"config_api"}) */ private $itemsPerPage; @@ -58,6 +65,8 @@ class Config * * @Assert\NotBlank() * @ORM\Column(name="language", type="string", nullable=false) + * + * @Groups({"config_api"}) */ private $language; @@ -65,6 +74,8 @@ class Config * @var string * * @ORM\Column(name="feed_token", type="string", nullable=true) + * + * @Groups({"config_api"}) */ private $feedToken; @@ -77,6 +88,8 @@ class Config * max = 100000, * maxMessage = "validator.feed_limit_too_high" * ) + * + * @Groups({"config_api"}) */ private $feedLimit; @@ -84,6 +97,8 @@ class Config * @var float * * @ORM\Column(name="reading_speed", type="float", nullable=true) + * + * @Groups({"config_api"}) */ private $readingSpeed; @@ -91,6 +106,8 @@ class Config * @var string * * @ORM\Column(name="pocket_consumer_key", type="string", nullable=true) + * + * @Groups({"config_api"}) */ private $pocketConsumerKey; @@ -98,6 +115,8 @@ class Config * @var int * * @ORM\Column(name="action_mark_as_read", type="integer", nullable=true, options={"default" = 0}) + * + * @Groups({"config_api"}) */ private $actionMarkAsRead; @@ -105,6 +124,8 @@ class Config * @var int * * @ORM\Column(name="list_mode", type="integer", nullable=true) + * + * @Groups({"config_api"}) */ private $listMode; diff --git a/tests/Wallabag/ApiBundle/Controller/ConfigRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/ConfigRestControllerTest.php index f4ca14ccf..c7c2fffcb 100644 --- a/tests/Wallabag/ApiBundle/Controller/ConfigRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/ConfigRestControllerTest.php @@ -17,8 +17,6 @@ class ConfigRestControllerTest extends WallabagApiTestCase $this->assertArrayHasKey('theme', $content); $this->assertArrayHasKey('items_per_page', $content); $this->assertArrayHasKey('language', $content); - $this->assertArrayHasKey('feed_token', $content); - $this->assertArrayHasKey('feed_limit', $content); $this->assertArrayHasKey('reading_speed', $content); $this->assertArrayHasKey('pocket_consumer_key', $content); $this->assertArrayHasKey('action_mark_as_read', $content);