From 813d6ad0dceec1180d4918e310a46b67797e04d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Muszy=C5=84ski?= Date: Thu, 16 Feb 2017 17:14:25 +0100 Subject: [PATCH 1/4] Return route id in menus API instead of an object --- .../Model/RouteAwareInterface.php | 5 ++++ .../ContentBundle/Model/RouteAwareTrait.php | 24 +++++++++++++++++++ .../config/serializer/Model.MenuItem.yml | 3 +++ 3 files changed, 32 insertions(+) diff --git a/src/SWP/Bundle/ContentBundle/Model/RouteAwareInterface.php b/src/SWP/Bundle/ContentBundle/Model/RouteAwareInterface.php index 6f219077b0..9756f74a69 100644 --- a/src/SWP/Bundle/ContentBundle/Model/RouteAwareInterface.php +++ b/src/SWP/Bundle/ContentBundle/Model/RouteAwareInterface.php @@ -13,4 +13,9 @@ public function getRoute(); * @param RouteInterface|null $route */ public function setRoute(RouteInterface $route = null); + + /** + * @return int|null + */ + public function getRouteId(); } diff --git a/src/SWP/Bundle/ContentBundle/Model/RouteAwareTrait.php b/src/SWP/Bundle/ContentBundle/Model/RouteAwareTrait.php index 0edf41a64d..176552cb85 100644 --- a/src/SWP/Bundle/ContentBundle/Model/RouteAwareTrait.php +++ b/src/SWP/Bundle/ContentBundle/Model/RouteAwareTrait.php @@ -1,5 +1,19 @@ route = $route; } + + /** + * @return int|null + */ + public function getRouteId() + { + if (null !== $this->route) { + return $this->route->getId(); + } + } } diff --git a/src/SWP/Bundle/CoreBundle/Resources/config/serializer/Model.MenuItem.yml b/src/SWP/Bundle/CoreBundle/Resources/config/serializer/Model.MenuItem.yml index 5023e70608..5b066848b9 100644 --- a/src/SWP/Bundle/CoreBundle/Resources/config/serializer/Model.MenuItem.yml +++ b/src/SWP/Bundle/CoreBundle/Resources/config/serializer/Model.MenuItem.yml @@ -3,6 +3,9 @@ SWP\Bundle\CoreBundle\Model\MenuItem: properties: route: expose: true + type: integer + accessor: + getter: getRouteId relations: - rel: self href: From 6fcd94e3565615534f8bff70319c26f62f67e752 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Muszy=C5=84ski?= Date: Mon, 20 Feb 2017 14:56:58 +0100 Subject: [PATCH 2/4] fixed migration script --- app/migrations/Version20170217123721.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/migrations/Version20170217123721.php b/app/migrations/Version20170217123721.php index 34a8cf030b..0ef54c019b 100644 --- a/app/migrations/Version20170217123721.php +++ b/app/migrations/Version20170217123721.php @@ -32,7 +32,7 @@ public function up(Schema $schema) $this->addSql('ALTER TABLE swp_article ALTER keywords DROP NOT NULL'); $this->addSql('DROP INDEX swp_name_idx'); $this->addSql('ALTER TABLE swp_container ADD revision_id INT DEFAULT NULL'); - $this->addSql('ALTER TABLE swp_container ADD uuid VARCHAR(255) NOT NULL'); + $this->addSql('ALTER TABLE swp_container ADD uuid VARCHAR(255) NOT NULL DEFAULT substr(md5(random()::text), 0, 12);'); $this->addSql('ALTER TABLE swp_container DROP width'); $this->addSql('ALTER TABLE swp_container DROP height'); $this->addSql('ALTER TABLE swp_container ALTER created_at SET DEFAULT \'now\''); @@ -50,7 +50,6 @@ public function down(Schema $schema) // this down() migration is auto-generated, please modify it to your needs $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.'); - $this->addSql('CREATE SCHEMA public'); $this->addSql('ALTER TABLE swp_revision_log DROP CONSTRAINT FK_A1F96AFD9AC03385'); $this->addSql('ALTER TABLE swp_revision_log DROP CONSTRAINT FK_A1F96AFD21852C2F'); $this->addSql('ALTER TABLE swp_container DROP CONSTRAINT FK_CF0E49301DFA7C8F'); From 65148c1c61aadf6c56c7a7f72defd8fc2ba8b88d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Muszy=C5=84ski?= Date: Mon, 20 Feb 2017 15:56:54 +0100 Subject: [PATCH 3/4] ByLine is required in storage but it's not required by validation --- .../BridgeBundle/Resources/config/doctrine-orm/Item.orm.yml | 1 + .../BridgeBundle/Resources/config/doctrine-orm/Package.orm.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/src/SWP/Bundle/BridgeBundle/Resources/config/doctrine-orm/Item.orm.yml b/src/SWP/Bundle/BridgeBundle/Resources/config/doctrine-orm/Item.orm.yml index 8a8a0f5bee..1092916fd7 100644 --- a/src/SWP/Bundle/BridgeBundle/Resources/config/doctrine-orm/Item.orm.yml +++ b/src/SWP/Bundle/BridgeBundle/Resources/config/doctrine-orm/Item.orm.yml @@ -18,6 +18,7 @@ SWP\Component\Bridge\Model\Item: type: string byline: type: string + nullable: true language: type: string description: diff --git a/src/SWP/Bundle/BridgeBundle/Resources/config/doctrine-orm/Package.orm.yml b/src/SWP/Bundle/BridgeBundle/Resources/config/doctrine-orm/Package.orm.yml index e23704e791..5a27d8a77b 100644 --- a/src/SWP/Bundle/BridgeBundle/Resources/config/doctrine-orm/Package.orm.yml +++ b/src/SWP/Bundle/BridgeBundle/Resources/config/doctrine-orm/Package.orm.yml @@ -22,6 +22,7 @@ SWP\Component\Bridge\Model\Package: type: string byline: type: string + nullable: true language: type: string description: From 89c9151637cd5fc8e99bc1955d5b4b295aa463c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Muszy=C5=84ski?= Date: Mon, 20 Feb 2017 15:57:09 +0100 Subject: [PATCH 4/4] tests --- .../Tests/Controller/MenuControllerTest.php | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/SWP/Bundle/CoreBundle/Tests/Controller/MenuControllerTest.php b/src/SWP/Bundle/CoreBundle/Tests/Controller/MenuControllerTest.php index 44aa058eff..7f444b7e02 100644 --- a/src/SWP/Bundle/CoreBundle/Tests/Controller/MenuControllerTest.php +++ b/src/SWP/Bundle/CoreBundle/Tests/Controller/MenuControllerTest.php @@ -453,4 +453,41 @@ private function assertCreatingChildren() return $firstChild; } + + public function testAssignRouteToMenuApi() + { + $client = static::createClient(); + $client->request('POST', $this->router->generate('swp_api_core_create_menu'), [ + 'menu' => [ + 'name' => 'navigation', + 'label' => 'Navigation', + ], + ]); + + self::assertEquals(201, $client->getResponse()->getStatusCode()); + $content = $client->getResponse()->getContent(); + + self::assertContains('"name":"navigation"', $content); + self::assertContains('"label":"Navigation"', $content); + self::assertContains('"route":null', $content); + + $client->request('POST', $this->router->generate('swp_api_content_create_routes'), [ + 'route' => [ + 'name' => 'my-menu-route', + 'type' => 'collection', + ], + ]); + + self::assertEquals(201, $client->getResponse()->getStatusCode()); + $content = json_decode($client->getResponse()->getContent(), true); + + $client->request('PATCH', $this->router->generate('swp_api_core_update_menu', ['id' => 1]), [ + 'menu' => [ + 'route' => $content['id'], + ], + ]); + + self::assertEquals(200, $client->getResponse()->getStatusCode()); + self::assertContains('"route":3', $content); + } }