diff options
Diffstat (limited to 'src')
4 files changed, 86 insertions, 4 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/WallabagRestController.php b/src/Wallabag/CoreBundle/Controller/WallabagRestController.php index 276cfe1c..cb68784d 100644 --- a/src/Wallabag/CoreBundle/Controller/WallabagRestController.php +++ b/src/Wallabag/CoreBundle/Controller/WallabagRestController.php | |||
@@ -6,7 +6,6 @@ use Nelmio\ApiDocBundle\Annotation\ApiDoc; | |||
6 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; | 6 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
7 | use Symfony\Component\HttpFoundation\Request; | 7 | use Symfony\Component\HttpFoundation\Request; |
8 | use Symfony\Component\HttpFoundation\Response; | 8 | use Symfony\Component\HttpFoundation\Response; |
9 | use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; | ||
10 | use Wallabag\CoreBundle\Entity\Entry; | 9 | use Wallabag\CoreBundle\Entity\Entry; |
11 | use Wallabag\CoreBundle\Entity\Tag; | 10 | use Wallabag\CoreBundle\Entity\Tag; |
12 | use Wallabag\CoreBundle\Service\Extractor; | 11 | use Wallabag\CoreBundle\Service\Extractor; |
@@ -244,12 +243,24 @@ class WallabagRestController extends Controller | |||
244 | * | 243 | * |
245 | * @ApiDoc( | 244 | * @ApiDoc( |
246 | * requirements={ | 245 | * requirements={ |
247 | * {"name"="tag", "dataType"="string", "requirement"="\w+", "description"="The tag"} | 246 | * {"name"="label", "dataType"="string", "requirement"="\w+", "description"="Label of the tag"} |
248 | * } | 247 | * } |
249 | * ) | 248 | * ) |
250 | */ | 249 | */ |
251 | public function getTagAction(Tag $tag) | 250 | public function getTagAction($label) |
252 | { | 251 | { |
252 | $tag = $this | ||
253 | ->getDoctrine() | ||
254 | ->getRepository('WallabagCoreBundle:Tag') | ||
255 | ->findOneByLabel($label); | ||
256 | |||
257 | if (is_null($tag)) { | ||
258 | throw $this->createNotFoundException(); | ||
259 | } | ||
260 | |||
261 | $json = $this->get('serializer')->serialize($tag, 'json'); | ||
262 | |||
263 | return new Response($json, 200, array('application/json')); | ||
253 | } | 264 | } |
254 | 265 | ||
255 | /** | 266 | /** |
diff --git a/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadTagData.php b/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadTagData.php new file mode 100644 index 00000000..6b13c2be --- /dev/null +++ b/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadTagData.php | |||
@@ -0,0 +1,42 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\CoreBundle\DataFixtures\ORM; | ||
4 | |||
5 | use Doctrine\Common\DataFixtures\AbstractFixture; | ||
6 | use Doctrine\Common\DataFixtures\OrderedFixtureInterface; | ||
7 | use Doctrine\Common\Persistence\ObjectManager; | ||
8 | use Wallabag\CoreBundle\Entity\Tag; | ||
9 | |||
10 | class LoadTagData extends AbstractFixture implements OrderedFixtureInterface | ||
11 | { | ||
12 | /** | ||
13 | * {@inheritDoc} | ||
14 | */ | ||
15 | public function load(ObjectManager $manager) | ||
16 | { | ||
17 | $tag1 = new Tag(); | ||
18 | $tag1->setLabel('foo'); | ||
19 | |||
20 | $manager->persist($tag1); | ||
21 | |||
22 | $tag2 = new Tag(); | ||
23 | $tag2->setLabel('bar'); | ||
24 | |||
25 | $manager->persist($tag2); | ||
26 | |||
27 | $tag3 = new Tag(); | ||
28 | $tag3->setLabel('baz'); | ||
29 | |||
30 | $manager->persist($tag3); | ||
31 | |||
32 | $manager->flush(); | ||
33 | } | ||
34 | |||
35 | /** | ||
36 | * {@inheritDoc} | ||
37 | */ | ||
38 | public function getOrder() | ||
39 | { | ||
40 | return 30; | ||
41 | } | ||
42 | } | ||
diff --git a/src/Wallabag/CoreBundle/Entity/Tag.php b/src/Wallabag/CoreBundle/Entity/Tag.php index 31017563..963f32b1 100644 --- a/src/Wallabag/CoreBundle/Entity/Tag.php +++ b/src/Wallabag/CoreBundle/Entity/Tag.php | |||
@@ -58,6 +58,6 @@ class Tag | |||
58 | */ | 58 | */ |
59 | public function getLabel() | 59 | public function getLabel() |
60 | { | 60 | { |
61 | return $this->value; | 61 | return $this->label; |
62 | } | 62 | } |
63 | } | 63 | } |
diff --git a/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php index 4164e516..0ffe7fe6 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php | |||
@@ -150,4 +150,33 @@ class WallabagRestControllerTest extends WallabagTestCase | |||
150 | 150 | ||
151 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); | 151 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); |
152 | } | 152 | } |
153 | |||
154 | public function testGetOneTag() | ||
155 | { | ||
156 | $client = $this->createClient(); | ||
157 | $client->request('GET', '/api/salts/admin.json'); | ||
158 | $salt = json_decode($client->getResponse()->getContent()); | ||
159 | |||
160 | $headers = $this->generateHeaders('admin', 'test', $salt[0]); | ||
161 | |||
162 | $tag = $client->getContainer() | ||
163 | ->get('doctrine.orm.entity_manager') | ||
164 | ->getRepository('WallabagCoreBundle:Tag') | ||
165 | ->findOneByLabel('foo'); | ||
166 | |||
167 | if (!$tag) { | ||
168 | $this->markTestSkipped('No content found in db.'); | ||
169 | } | ||
170 | |||
171 | $client->request('GET', '/api/tags/'.$tag->getLabel().'.json', array(), array(), $headers); | ||
172 | |||
173 | $this->assertEquals(json_encode($tag), $client->getResponse()->getContent()); | ||
174 | |||
175 | $this->assertTrue( | ||
176 | $client->getResponse()->headers->contains( | ||
177 | 'Content-Type', | ||
178 | 'application/json' | ||
179 | ) | ||
180 | ); | ||
181 | } | ||
153 | } | 182 | } |