]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/CoreBundle/Controller/WallabagRestController.php
GET /api/tags/id_tag method
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Controller / WallabagRestController.php
index d48c7bbb2f18389cb0a5b4deba725542db3f9717..cb68784d55d02080d5262ae3bdac5b61d4d8474c 100644 (file)
@@ -6,11 +6,9 @@ use Nelmio\ApiDocBundle\Annotation\ApiDoc;
 use Symfony\Bundle\FrameworkBundle\Controller\Controller;
 use Symfony\Component\HttpFoundation\Request;
 use Symfony\Component\HttpFoundation\Response;
-use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
 use Wallabag\CoreBundle\Entity\Entry;
 use Wallabag\CoreBundle\Entity\Tag;
 use Wallabag\CoreBundle\Service\Extractor;
-use Hateoas\HateoasBuilder;
 
 class WallabagRestController extends Controller
 {
@@ -44,7 +42,6 @@ class WallabagRestController extends Controller
      *       parameters={
      *          {"name"="archive", "dataType"="boolean", "required"=false, "format"="true or false, all entries by default", "description"="filter by archived status."},
      *          {"name"="star", "dataType"="boolean", "required"=false, "format"="true or false, all entries by default", "description"="filter by starred status."},
-     *          {"name"="delete", "dataType"="boolean", "required"=false, "format"="true or false, default '0'", "description"="filter by deleted status."},
      *          {"name"="sort", "dataType"="string", "required"=false, "format"="'created' or 'updated', default 'created'", "description"="sort entries by date."},
      *          {"name"="order", "dataType"="string", "required"=false, "format"="'asc' or 'desc', default 'desc'", "description"="order of sort."},
      *          {"name"="page", "dataType"="integer", "required"=false, "format"="default '1'", "description"="what page you want."},
@@ -58,7 +55,6 @@ class WallabagRestController extends Controller
     {
         $isArchived = $request->query->get('archive');
         $isStarred  = $request->query->get('star');
-        $isDeleted  = $request->query->get('delete', 0);
         $sort       = $request->query->get('sort', 'created');
         $order      = $request->query->get('order', 'desc');
         $page       = $request->query->get('page', 1);
@@ -68,14 +64,13 @@ class WallabagRestController extends Controller
         $entries = $this
             ->getDoctrine()
             ->getRepository('WallabagCoreBundle:Entry')
-            ->findEntries($this->getUser()->getId(), $isArchived, $isStarred, $isDeleted, $sort, $order);
+            ->findEntries($this->getUser()->getId(), $isArchived, $isStarred, $sort, $order);
 
         if (!($entries)) {
             throw $this->createNotFoundException();
         }
 
-        $hateoas = HateoasBuilder::create()->build();
-        $json = $hateoas->serialize($entries, 'json');
+        $json = $this->get('serializer')->serialize($entries, 'json');
 
         return new Response($json, 200, array('application/json'));
     }
@@ -92,8 +87,7 @@ class WallabagRestController extends Controller
      */
     public function getEntryAction(Entry $entry)
     {
-        $hateoas = HateoasBuilder::create()->build();
-        $json = $hateoas->serialize($entry, 'json');
+        $json = $this->get('serializer')->serialize($entry, 'json');
 
         return new Response($json, 200, array('application/json'));
     }
@@ -124,7 +118,9 @@ class WallabagRestController extends Controller
         $em->persist($entry);
         $em->flush();
 
-        return $entry;
+        $json = $this->get('serializer')->serialize($entry, 'json');
+
+        return new Response($json, 200, array('application/json'));
     }
 
     /**
@@ -139,8 +135,7 @@ class WallabagRestController extends Controller
      *          {"name"="tags", "dataType"="string", "required"=false, "format"="tag1,tag2,tag3", "description"="a comma-separated list of tags."},
      *          {"name"="archive", "dataType"="boolean", "required"=false, "format"="true or false", "description"="archived the entry."},
      *          {"name"="star", "dataType"="boolean", "required"=false, "format"="true or false", "description"="starred the entry."},
-     *          {"name"="delete", "dataType"="boolean", "required"=false, "format"="true or false", "description"="flag as deleted. Default false. In case that you don't want to *really* remove it.."},
-     *       }
+     *      }
      * )
      * @return Entry
      */
@@ -149,7 +144,6 @@ class WallabagRestController extends Controller
         $title      = $request->request->get("title");
         $tags       = $request->request->get("tags", array());
         $isArchived = $request->request->get("archive");
-        $isDeleted  = $request->request->get("delete");
         $isStarred  = $request->request->get("star");
 
         if (!is_null($title)) {
@@ -160,10 +154,6 @@ class WallabagRestController extends Controller
             $entry->setArchived($isArchived);
         }
 
-        if (!is_null($isDeleted)) {
-            $entry->setDeleted($isDeleted);
-        }
-
         if (!is_null($isStarred)) {
             $entry->setStarred($isStarred);
         }
@@ -186,15 +176,13 @@ class WallabagRestController extends Controller
      */
     public function deleteEntriesAction(Entry $entry)
     {
-        if ($entry->isDeleted()) {
-            throw new NotFoundHttpException('This entry is already deleted');
-        }
-
         $em = $this->getDoctrine()->getManager();
-        $entry->setDeleted(1);
+        $em->remove($entry);
         $em->flush();
 
-        return $entry;
+        $json = $this->get('serializer')->serialize($entry, 'json');
+
+        return new Response($json, 200, array('application/json'));
     }
 
     /**
@@ -255,12 +243,24 @@ class WallabagRestController extends Controller
      *
      * @ApiDoc(
      *       requirements={
-     *          {"name"="tag", "dataType"="string", "requirement"="\w+", "description"="The tag"}
+     *          {"name"="label", "dataType"="string", "requirement"="\w+", "description"="Label of the tag"}
      *       }
      * )
      */
-    public function getTagAction(Tag $tag)
+    public function getTagAction($label)
     {
+        $tag = $this
+            ->getDoctrine()
+            ->getRepository('WallabagCoreBundle:Tag')
+            ->findOneByLabel($label);
+
+        if (is_null($tag)) {
+            throw $this->createNotFoundException();
+        }
+
+        $json = $this->get('serializer')->serialize($tag, 'json');
+
+        return new Response($json, 200, array('application/json'));
     }
 
     /**